From c3b19f1bb4452592b4aeafba18a4b55ccd4e22ba Mon Sep 17 00:00:00 2001 From: Mike <41407352+hunjixin@users.noreply.github.com> Date: Sat, 8 May 2021 11:15:45 +0800 Subject: [PATCH] add cmd for message select (#4432) * add cmd for message select * fix lint --- app/submodule/chain/actor_api.go | 2 +- cmd/mpool.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/app/submodule/chain/actor_api.go b/app/submodule/chain/actor_api.go index 3360b5fb75..496484d985 100644 --- a/app/submodule/chain/actor_api.go +++ b/app/submodule/chain/actor_api.go @@ -29,7 +29,7 @@ func (actorAPI *ActorAPI) StateGetActor(ctx context.Context, actor address.Addre return nil, xerrors.Errorf("loading tipset %s: %v", tsk, err) } - view, err := actorAPI.chain.ChainReader.StateView(ts) + view, err := actorAPI.chain.ChainReader.ParentStateView(ts) if err != nil { return nil, xerrors.Errorf("loading tipset %s: %v", tsk, err) } diff --git a/cmd/mpool.go b/cmd/mpool.go index 4a10e75fa5..d3b72e8eeb 100644 --- a/cmd/mpool.go +++ b/cmd/mpool.go @@ -36,6 +36,7 @@ var mpoolCmd = &cmds.Command{ "gas-perf": mpoolGasPerfCmd, "publish": mpoolPublish, "delete": mpoolDeleteAddress, + "select": mpoolSelect, }, } @@ -69,6 +70,35 @@ var mpoolDeleteAddress = &cmds.Command{ }, } +var mpoolSelect = &cmds.Command{ + Helptext: cmds.HelpText{ + Tagline: "select", + ShortDescription: "select message from mpool", + }, + Options: []cmds.Option{ + cmds.FloatOption("quality", "optionally specify the wallet for publish message").WithDefault(0.5), + }, + Run: func(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment) error { + ctx := context.TODO() + + quality, _ := req.Options["quality"].(float64) + head, err := env.(*node.Env).ChainAPI.ChainHead(ctx) + if err != nil { + return err + } + msgs, err := env.(*node.Env).MessagePoolAPI.MpoolSelect(ctx, head.Key(), quality) + if err != nil { + return err + } + selectMsg, err := json.MarshalIndent(msgs, " ", "\t") + if err != nil { + return err + } + + return printOneString(re, string(selectMsg)) + }, +} + var mpoolPublish = &cmds.Command{ Helptext: cmds.HelpText{ Tagline: "publish",