add mpoolpending from to filter

This commit is contained in:
Frank 2020-12-10 17:21:32 +08:00
parent e1be89b442
commit 0f08da3272

View File

@ -49,6 +49,14 @@ var mpoolPending = &cli.Command{
Name: "cids",
Usage: "only print cids of messages in output",
},
&cli.StringFlag{
Name: "to",
Usage: "return messages to a given address",
},
&cli.StringFlag{
Name: "from",
Usage: "return messages from a given address",
},
},
Action: func(cctx *cli.Context) error {
api, closer, err := GetFullNodeAPI(cctx)
@ -59,6 +67,23 @@ var mpoolPending = &cli.Command{
ctx := ReqContext(cctx)
var toa, froma address.Address
if tos := cctx.String("to"); tos != "" {
a, err := address.NewFromString(tos)
if err != nil {
return fmt.Errorf("given 'to' address %q was invalid: %w", tos, err)
}
toa = a
}
if froms := cctx.String("from"); froms != "" {
a, err := address.NewFromString(froms)
if err != nil {
return fmt.Errorf("given 'from' address %q was invalid: %w", froms, err)
}
froma = a
}
var filter map[address.Address]struct{}
if cctx.Bool("local") {
filter = map[address.Address]struct{}{}
@ -85,6 +110,13 @@ var mpoolPending = &cli.Command{
}
}
if toa != address.Undef && msg.Message.To != toa {
continue
}
if froma != address.Undef && msg.Message.From != froma {
continue
}
if cctx.Bool("cids") {
fmt.Println(msg.Cid())
} else {