Skip to content

Commit

Permalink
Move commands from the show subcommand to the chain subcommand (#4604)
Browse files Browse the repository at this point in the history
  • Loading branch information
simlecode authored Dec 7, 2021
1 parent ee1908b commit 9f2a15e
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 88 deletions.
90 changes: 83 additions & 7 deletions cmd/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/filecoin-project/venus/app/client/apiface"
"os"
"strings"
"time"
Expand All @@ -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"
Expand All @@ -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,
},
}

Expand Down Expand Up @@ -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 {
Expand Down
83 changes: 2 additions & 81 deletions cmd/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,
},
}

Expand Down Expand Up @@ -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{},
}

0 comments on commit 9f2a15e

Please sign in to comment.