Skip to content

Commit

Permalink
Merge pull request #4134 from filecoin-project/feat/better-replace-ux
Browse files Browse the repository at this point in the history
improve the UX for replacing messages
  • Loading branch information
magik6k committed Oct 1, 2020
2 parents 60d442e + 889dd3c commit bceb880
Showing 1 changed file with 47 additions and 18 deletions.
65 changes: 47 additions & 18 deletions cli/mpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"sort"
"strconv"

cid "github.com/ipfs/go-cid"
"github.com/urfave/cli/v2"
"golang.org/x/xerrors"

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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: "<from nonce> | <message-cid>",
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 {
Expand All @@ -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)
Expand Down

0 comments on commit bceb880

Please sign in to comment.