Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move commands from the show subcommand to the chain subcommand #4604

Merged
merged 1 commit into from
Dec 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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{},
}