From 9f2a15ee51bff9429199cc44aa22d91343db67d2 Mon Sep 17 00:00:00 2001 From: tom <69969590+simlecode@users.noreply.github.com> Date: Tue, 7 Dec 2021 14:10:14 +0800 Subject: [PATCH] Move commands from the show subcommand to the chain subcommand (#4604) --- cmd/chain.go | 90 ++++++++++++++++++++++++++++++++++++++++++++++++---- cmd/show.go | 83 ++---------------------------------------------- 2 files changed, 85 insertions(+), 88 deletions(-) diff --git a/cmd/chain.go b/cmd/chain.go index 6cd9e37626..fbf9e7e91c 100644 --- a/cmd/chain.go +++ b/cmd/chain.go @@ -6,7 +6,6 @@ import ( "context" "encoding/json" "fmt" - "github.com/filecoin-project/venus/app/client/apiface" "os" "strings" "time" @@ -18,6 +17,7 @@ import ( cmds "github.com/ipfs/go-ipfs-cmds" "golang.org/x/xerrors" + "github.com/filecoin-project/venus/app/client/apiface" "github.com/filecoin-project/venus/app/node" "github.com/filecoin-project/venus/app/submodule/apitypes" "github.com/filecoin-project/venus/pkg/constants" @@ -29,12 +29,15 @@ var chainCmd = &cmds.Command{ Tagline: "Inspect the filecoin blockchain", }, Subcommands: map[string]*cmds.Command{ - "head": chainHeadCmd, - "ls": chainLsCmd, - "set-head": chainSetHeadCmd, - "getblock": chainGetBlockCmd, - "disputer": chainDisputeSetCmd, - "export": chainExportCmd, + "head": chainHeadCmd, + "ls": chainLsCmd, + "set-head": chainSetHeadCmd, + "getblock": chainGetBlockCmd, + "get-message": chainGetMessageCmd, + "get-messages": chainGetMessagesCmd, + "get-receipts": chainGetReceiptsCmd, + "disputer": chainDisputeSetCmd, + "export": chainExportCmd, }, } @@ -233,6 +236,79 @@ var chainGetBlockCmd = &cmds.Command{ }, } +var chainGetMessageCmd = &cmds.Command{ + Helptext: cmds.HelpText{ + Tagline: "Show a filecoin message by its CID", + }, + Arguments: []cmds.Argument{ + cmds.StringArg("cid", true, false, "CID of message to show"), + }, + Run: func(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment) error { + cid, err := cid.Decode(req.Arguments[0]) + if err != nil { + return err + } + + msg, err := env.(*node.Env).ChainAPI.ChainGetMessage(req.Context, cid) + if err != nil { + return err + } + + return re.Emit(msg) + }, + Type: types.UnsignedMessage{}, +} + +var chainGetMessagesCmd = &cmds.Command{ + Helptext: cmds.HelpText{ + Tagline: "Show a filecoin message collection by block CID", + ShortDescription: "Prints info for all messages in a collection, at the given block CID.", + }, + Arguments: []cmds.Argument{ + cmds.StringArg("cid", true, false, "CID of block to show"), + }, + Run: func(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment) error { + cid, err := cid.Decode(req.Arguments[0]) + if err != nil { + return err + } + + bmsg, err := env.(*node.Env).ChainAPI.ChainGetBlockMessages(req.Context, cid) + if err != nil { + return err + } + + return re.Emit(bmsg) + }, + Type: &apitypes.BlockMessages{}, +} + +var chainGetReceiptsCmd = &cmds.Command{ + Helptext: cmds.HelpText{ + Tagline: "Show a filecoin receipt collection by its CID", + ShortDescription: `Prints info for all receipts in a collection, +at the given CID. MessageReceipt collection CIDs are found in the "ParentMessageReceipts" +field of the filecoin block header.`, + }, + Arguments: []cmds.Argument{ + cmds.StringArg("cid", true, false, "CID of receipt collection to show"), + }, + Run: func(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment) error { + cid, err := cid.Decode(req.Arguments[0]) + if err != nil { + return err + } + + receipts, err := env.(*node.Env).ChainAPI.ChainGetReceipts(req.Context, cid) + if err != nil { + return err + } + + return re.Emit(receipts) + }, + Type: []types.MessageReceipt{}, +} + func apiMsgCids(in []apitypes.Message) []cid.Cid { out := make([]cid.Cid, len(in)) for k, v := range in { diff --git a/cmd/show.go b/cmd/show.go index 48665862f7..f9673777f8 100644 --- a/cmd/show.go +++ b/cmd/show.go @@ -2,7 +2,6 @@ package cmd import ( "github.com/filecoin-project/venus/app/node" - "github.com/filecoin-project/venus/app/submodule/apitypes" "github.com/filecoin-project/venus/pkg/types" "github.com/ipfs/go-cid" @@ -14,11 +13,8 @@ var showCmd = &cmds.Command{ Tagline: "Get human-readable representations of filecoin objects", }, Subcommands: map[string]*cmds.Command{ - "block": showBlockCmd, - "header": showHeaderCmd, - "message": showMessageCmd, - "messages": showMessagesCmd, - "receipts": showReceiptsCmd, + "block": showBlockCmd, + "header": showHeaderCmd, }, } @@ -76,78 +72,3 @@ all other block properties will be included as well.`, }, Type: types.BlockHeader{}, } - -var showMessageCmd = &cmds.Command{ - Helptext: cmds.HelpText{ - Tagline: "Show a filecoin message by its CID", - }, - Arguments: []cmds.Argument{ - cmds.StringArg("cid", true, false, "CID of block to show"), - }, - Run: func(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment) error { - cid, err := cid.Decode(req.Arguments[0]) - if err != nil { - return err - } - - msg, err := env.(*node.Env).ChainAPI.ChainGetMessage(req.Context, cid) - if err != nil { - return err - } - - return re.Emit(msg) - }, - Type: types.UnsignedMessage{}, -} - -var showMessagesCmd = &cmds.Command{ - Helptext: cmds.HelpText{ - Tagline: "Show a filecoin message collection by txmeta CID", - ShortDescription: `Prints info for all messages in a collection, -at the given CID. This CID is found in the "Messages" field of -the filecoin block header.`, - }, - Arguments: []cmds.Argument{ - cmds.StringArg("cid", true, false, "CID of message collection to show"), - }, - Run: func(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment) error { - cid, err := cid.Decode(req.Arguments[0]) - if err != nil { - return err - } - - bmsg, err := env.(*node.Env).ChainAPI.ChainGetBlockMessages(req.Context, cid) - if err != nil { - return err - } - - return re.Emit(bmsg) - }, - Type: &apitypes.BlockMessages{}, -} - -var showReceiptsCmd = &cmds.Command{ - Helptext: cmds.HelpText{ - Tagline: "Show a filecoin receipt collection by its CID", - ShortDescription: `Prints info for all receipts in a collection, -at the given CID. MessageReceipt collection CIDs are found in the "ParentMessageReceipts" -field of the filecoin block header.`, - }, - Arguments: []cmds.Argument{ - cmds.StringArg("cid", true, false, "CID of receipt collection to show"), - }, - Run: func(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment) error { - cid, err := cid.Decode(req.Arguments[0]) - if err != nil { - return err - } - - receipts, err := env.(*node.Env).ChainAPI.ChainGetReceipts(req.Context, cid) - if err != nil { - return err - } - - return re.Emit(receipts) - }, - Type: []types.MessageReceipt{}, -}