Implement NewSendTxCmd
This commit is contained in:
parent
70d0241373
commit
c4a4047ed2
|
@ -8,6 +8,8 @@ import (
|
|||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/context"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/client/tx"
|
||||
clientx "github.com/cosmos/cosmos-sdk/client/tx"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
|
@ -15,7 +17,65 @@ import (
|
|||
"github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||
)
|
||||
|
||||
// NewTxCmd returns a root CLI command handler for all x/bank transaction commands.
|
||||
func NewTxCmd(m codec.Marshaler, txg tx.Generator, ar tx.AccountRetriever) *cobra.Command {
|
||||
txCmd := &cobra.Command{
|
||||
Use: types.ModuleName,
|
||||
Short: "Bank transaction subcommands",
|
||||
DisableFlagParsing: true,
|
||||
SuggestionsMinimumDistance: 2,
|
||||
RunE: client.ValidateCmd,
|
||||
}
|
||||
|
||||
txCmd.AddCommand(
|
||||
NewSendTxCmd(m, txg, ar),
|
||||
)
|
||||
|
||||
return txCmd
|
||||
}
|
||||
|
||||
// NewSendTxCmd returns a CLI command handler for creating a MsgSend transaction.
|
||||
func NewSendTxCmd(m codec.Marshaler, txg tx.Generator, ar tx.AccountRetriever) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "send [from_key_or_address] [to_address] [amount]",
|
||||
Short: "Create and/or sign and broadcast a MsgSend transaction",
|
||||
Args: cobra.ExactArgs(3),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
inBuf := bufio.NewReader(cmd.InOrStdin())
|
||||
txf := tx.NewFactoryFromCLI(inBuf).
|
||||
WithTxGenerator(txg).
|
||||
WithAccountRetriever(ar)
|
||||
|
||||
cliCtx := context.NewCLIContextWithInputAndFrom(inBuf, args[0]).WithMarshaler(m)
|
||||
|
||||
toAddr, err := sdk.AccAddressFromBech32(args[1])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
coins, err := sdk.ParseCoins(args[2])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
msg := types.NewMsgSend(cliCtx.GetFromAddress(), toAddr, coins)
|
||||
return clientx.GenerateOrBroadcastTx(cliCtx, txf, msg)
|
||||
},
|
||||
}
|
||||
|
||||
return flags.PostCommands(cmd)[0]
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Deprecated
|
||||
//
|
||||
// TODO: Remove once client-side Protobuf migration has been completed.
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
// GetTxCmd returns the transaction commands for this module
|
||||
//
|
||||
// TODO: Remove once client-side Protobuf migration has been completed.
|
||||
// ref: https://github.com/cosmos/cosmos-sdk/issues/5864
|
||||
func GetTxCmd(cdc *codec.Codec) *cobra.Command {
|
||||
txCmd := &cobra.Command{
|
||||
Use: types.ModuleName,
|
||||
|
@ -31,6 +91,9 @@ func GetTxCmd(cdc *codec.Codec) *cobra.Command {
|
|||
}
|
||||
|
||||
// SendTxCmd will create a send tx and sign it with the given key.
|
||||
//
|
||||
// TODO: Remove once client-side Protobuf migration has been completed.
|
||||
// ref: https://github.com/cosmos/cosmos-sdk/issues/5864
|
||||
func SendTxCmd(cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "send [from_key_or_address] [to_address] [amount]",
|
||||
|
|
Loading…
Reference in New Issue