From 889dd3cb3fa6e44c2e590fd1908df90db9360010 Mon Sep 17 00:00:00 2001 From: whyrusleeping Date: Thu, 1 Oct 2020 08:51:01 -0700 Subject: [PATCH] improve the UX for replacing messages --- cli/mpool.go | 65 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 47 insertions(+), 18 deletions(-) diff --git a/cli/mpool.go b/cli/mpool.go index 65f4ef942c..a8c73b656e 100644 --- a/cli/mpool.go +++ b/cli/mpool.go @@ -7,6 +7,7 @@ import ( "sort" "strconv" + cid "github.com/ipfs/go-cid" "github.com/urfave/cli/v2" "golang.org/x/xerrors" @@ -43,6 +44,10 @@ var mpoolPending = &cli.Command{ Name: "local", Usage: "print pending messages for addresses in local wallet only", }, + &cli.BoolFlag{ + Name: "cids", + Usage: "only print cids of messages in output", + }, }, Action: func(cctx *cli.Context) error { api, closer, err := GetFullNodeAPI(cctx) @@ -79,11 +84,15 @@ var mpoolPending = &cli.Command{ } } - out, err := json.MarshalIndent(msg, "", " ") - if err != nil { - return err + if cctx.Bool("cids") { + fmt.Println(msg.Cid()) + } else { + out, err := json.MarshalIndent(msg, "", " ") + if err != nil { + return err + } + fmt.Println(string(out)) } - fmt.Println(string(out)) } return nil @@ -308,21 +317,8 @@ var mpoolReplaceCmd = &cli.Command{ Usage: "Spend up to X FIL for this message (applicable for auto mode)", }, }, - ArgsUsage: "[from] [nonce]", + ArgsUsage: " | ", Action: func(cctx *cli.Context) error { - if cctx.Args().Len() < 2 { - return cli.ShowCommandHelp(cctx, cctx.Command.Name) - } - - from, err := address.NewFromString(cctx.Args().Get(0)) - if err != nil { - return err - } - - nonce, err := strconv.ParseUint(cctx.Args().Get(1), 10, 64) - if err != nil { - return err - } api, closer, err := GetFullNodeAPI(cctx) if err != nil { @@ -332,6 +328,39 @@ var mpoolReplaceCmd = &cli.Command{ ctx := ReqContext(cctx) + var from address.Address + var nonce uint64 + switch cctx.Args().Len() { + case 1: + mcid, err := cid.Decode(cctx.Args().First()) + if err != nil { + return err + } + + msg, err := api.ChainGetMessage(ctx, mcid) + if err != nil { + return fmt.Errorf("could not find referenced message: %w", err) + } + + from = msg.From + nonce = msg.Nonce + case 2: + f, err := address.NewFromString(cctx.Args().Get(0)) + if err != nil { + return err + } + + n, err := strconv.ParseUint(cctx.Args().Get(1), 10, 64) + if err != nil { + return err + } + + from = f + nonce = n + default: + return cli.ShowCommandHelp(cctx, cctx.Command.Name) + } + ts, err := api.ChainHead(ctx) if err != nil { return xerrors.Errorf("getting chain head: %w", err)