Merge pull request #5169 from filcloud/5141-mpoolpending

add mpoolpending from to filter
This commit is contained in:
Łukasz Magiera 2020-12-10 17:31:48 +01:00 committed by GitHub
commit 58729b7fd6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -49,6 +49,14 @@ var mpoolPending = &cli.Command{
Name: "cids", Name: "cids",
Usage: "only print cids of messages in output", 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 { Action: func(cctx *cli.Context) error {
api, closer, err := GetFullNodeAPI(cctx) api, closer, err := GetFullNodeAPI(cctx)
@ -59,6 +67,23 @@ var mpoolPending = &cli.Command{
ctx := ReqContext(cctx) 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{} var filter map[address.Address]struct{}
if cctx.Bool("local") { if cctx.Bool("local") {
filter = map[address.Address]struct{}{} 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") { if cctx.Bool("cids") {
fmt.Println(msg.Cid()) fmt.Println(msg.Cid())
} else { } else {