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

revised docs for cli.go #22665

Closed
wants to merge 2 commits into from
Closed
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
35 changes: 32 additions & 3 deletions x/accounts/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,30 +93,42 @@ func GetTxInitCmd() *cobra.Command {
return cmd
}

// GetExecuteCmd returns a command for executing a state transition on an account.
func GetExecuteCmd() *cobra.Command {

// Create a new Cobra command with the "execute" use case and a short description.
cmd := &cobra.Command{
Use: "execute <account-address> <execute-msg-type-url> <json-message>",
Short: "Execute state transition to account",
Args: cobra.ExactArgs(3),
Use: "execute <account-address> <execute-msg-type-url> <json-message>", // Command syntax
Short: "Execute state transition to account", // Short description
Args: cobra.ExactArgs(3), // Expect exactly three arguments: account-address, execute-msg-type-url, json-message
RunE: func(cmd *cobra.Command, args []string) error {

// Get the transaction context from the command
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

// Retrieve the sender's address and convert it to a string format
sender, err := clientCtx.AddressCodec.BytesToString(clientCtx.GetFromAddress())
if err != nil {
return err
}

// Retrieve the schema for the specified account address (first argument)
schema, err := getSchemaForAccount(clientCtx, args[0])
if err != nil {
return err
}

// Convert the provided JSON message (third argument) to a protobuf message
// using the schema and the execute message type URL (second argument)
msgBytes, err := handlerMsgBytes(schema.ExecuteHandlers, args[1], args[2])
if err != nil {
return err
}

// Construct the MsgExecute protobuf message
msg := v1.MsgExecute{
Sender: sender,
Target: args[0],
Expand All @@ -130,26 +142,40 @@ func GetExecuteCmd() *cobra.Command {
return cmd
}

// GetQueryAccountCmd returns a command for querying the state of an account.
func GetQueryAccountCmd() *cobra.Command {

// Create a new Cobra command with the "query" use case and a short description.
cmd := &cobra.Command{
Use: "query <account-address> <query-request-type-url> <json-message>",
Short: "Query account state",
Args: cobra.ExactArgs(3),
RunE: func(cmd *cobra.Command, args []string) error {

// Get the query context from the command
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

// Retrieve the schema for the specified account address (first argument)
schema, err := getSchemaForAccount(clientCtx, args[0])
if err != nil {
return err
}

// Convert the provided JSON message (third argument) to a protobuf message
// using the schema and the query request type URL (second argument)
msgBytes, err := handlerMsgBytes(schema.QueryHandlers, args[1], args[2])
if err != nil {
return err
}

// Create a new QueryClient for interacting with the backend
queryClient := v1.NewQueryClient(clientCtx)


// Execute the account query with the constructed request
res, err := queryClient.AccountQuery(cmd.Context(), &v1.AccountQueryRequest{
Target: args[0],
Request: msgBytes,
Expand All @@ -160,10 +186,13 @@ func GetQueryAccountCmd() *cobra.Command {
return clientCtx.PrintProto(res)
},
}

// Add standard query flags to the command
flags.AddQueryFlagsToCmd(cmd)
return cmd
}


func getSchemaForAccount(clientCtx client.Context, addr string) (*v1.SchemaResponse, error) {
queryClient := v1.NewQueryClient(clientCtx)
accType, err := queryClient.AccountType(clientCtx.CmdContext, &v1.AccountTypeRequest{
Expand Down
4 changes: 4 additions & 0 deletions x/bank/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ func NewMsgServerImpl(keeper Keeper) types.MsgServer {
return &msgServer{Keeper: keeper}
}

// Send handles the Send message, transferring coins from one account to another
func (k msgServer) Send(ctx context.Context, msg *types.MsgSend) (*types.MsgSendResponse, error) {
var (
from, to []byte
err error
)

// Ensure the Keeper implements BaseKeeper and perform address conversion
if base, ok := k.Keeper.(BaseKeeper); ok {
from, err = base.addrCdc.StringToBytes(msg.FromAddress)
if err != nil {
Expand Down Expand Up @@ -65,6 +67,7 @@ func (k msgServer) Send(ctx context.Context, msg *types.MsgSend) (*types.MsgSend
return &types.MsgSendResponse{}, nil
}

// MultiSend handles a multi-send operation where multiple outputs are specified
func (k msgServer) MultiSend(ctx context.Context, msg *types.MsgMultiSend) (*types.MsgMultiSendResponse, error) {
if len(msg.Inputs) == 0 {
return nil, types.ErrNoInputs
Expand Down Expand Up @@ -162,6 +165,7 @@ func (k msgServer) SetSendEnabled(ctx context.Context, msg *types.MsgSetSendEnab
return &types.MsgSetSendEnabledResponse{}, nil
}

// Burn handles the burning of coins from an account
func (k msgServer) Burn(ctx context.Context, msg *types.MsgBurn) (*types.MsgBurnResponse, error) {
var (
from []byte
Expand Down
Loading