Skip to content

Commit

Permalink
autocli for Init
Browse files Browse the repository at this point in the history
  • Loading branch information
DongLieu committed Dec 2, 2024
1 parent f89848f commit 8640966
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 186 deletions.
16 changes: 14 additions & 2 deletions x/accounts/autocli.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,20 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions {
EnhanceCustomCommand: true,
},
Tx: &autocliv1.ServiceCommandDescriptor{
Service: accountsv1.Msg_ServiceDesc.ServiceName,
RpcCommandOptions: []*autocliv1.RpcCommandOptions{},
Service: accountsv1.Msg_ServiceDesc.ServiceName,
RpcCommandOptions: []*autocliv1.RpcCommandOptions{
{
RpcMethod: "Init",
Use: "init <account-type> <json-message>",
Short: "Initialize a new account",
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
{ProtoField: "sender"},
{ProtoField: "account_type"},
{ProtoField: "json_message"},
{ProtoField: "funds", Varargs: true},
},
},
},
EnhanceCustomCommand: true,
},
}
Expand Down
41 changes: 1 addition & 40 deletions x/accounts/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,46 +24,7 @@ func TxCmd(name string) *cobra.Command {
RunE: client.ValidateCmd,
DisableFlagParsing: true,
}
cmd.AddCommand(GetTxInitCmd(), GetExecuteCmd())
return cmd
}

func GetTxInitCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "init <account-type> <json-message>",
Short: "Initialize a new account",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
sender, err := clientCtx.AddressCodec.BytesToString(clientCtx.GetFromAddress())
if err != nil {
return err
}

msg := v1.MsgInit{
Sender: sender,
AccountType: args[0],
JsonMessage: args[1],
}

isGenesis, err := cmd.Flags().GetBool("genesis")
if err != nil {
return err
}

// in case the genesis flag is provided then the init message is printed.
if isGenesis {
return clientCtx.WithOutputFormat(flags.OutputFormatJSON).PrintProto(&msg)
}

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg)
},
}
cmd.Flags().Bool("genesis", false, "if true will print the json init message for genesis")
flags.AddTxFlagsToCmd(cmd)
cmd.AddCommand(GetExecuteCmd())
return cmd
}

Expand Down
144 changes: 0 additions & 144 deletions x/accounts/cli/cli_test.go

This file was deleted.

0 comments on commit 8640966

Please sign in to comment.