From 0f08da3272103ac6e256b97a0e5246010ca6ba26 Mon Sep 17 00:00:00 2001 From: Frank Date: Thu, 10 Dec 2020 17:21:32 +0800 Subject: [PATCH] add mpoolpending from to filter --- cli/mpool.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/cli/mpool.go b/cli/mpool.go index d30b85f4fdc..a84865547e0 100644 --- a/cli/mpool.go +++ b/cli/mpool.go @@ -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 {