From f754f18f6a352eeecb7294028972f8e6d260ff26 Mon Sep 17 00:00:00 2001 From: Jack Zampolin Date: Thu, 25 Mar 2021 16:25:52 -0700 Subject: [PATCH] Merge PR #471: Add send command for individual chain --- cmd/tx.go | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/cmd/tx.go b/cmd/tx.go index d284655a6..a862bf64b 100644 --- a/cmd/tx.go +++ b/cmd/tx.go @@ -10,6 +10,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" sdk "github.com/cosmos/cosmos-sdk/types" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" "github.com/cosmos/relayer/relayer" "github.com/spf13/cobra" @@ -44,11 +45,58 @@ Most of these commands take a [path] argument. Make sure: closeChannelCmd(), flags.LineBreak, rawTransactionCmd(), + flags.LineBreak, + sendCmd(), ) return cmd } +func sendCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "send [chain-id] [from-key] [to-address] [amount]", + Short: "send funds to a different address on the same chain", + Args: cobra.ExactArgs(4), + Example: strings.TrimSpace(fmt.Sprintf(`$ %s tx send testkey cosmos10yft4nc8tacpngwlpyq3u4t88y7qzc9xv0q4y8 10000uatom`, appName)), + RunE: func(cmd *cobra.Command, args []string) error { + c, err := config.Chains.Get(args[0]) + if err != nil { + return err + } + + // ensure that keys exist + key, err := c.Keybase.Key(args[1]) + if err != nil { + return err + } + + to, err := sdk.AccAddressFromBech32(args[2]) + if err != nil { + return err + } + + amt, err := sdk.ParseCoinsNormalized(args[3]) + if err != nil { + return err + } + + msg := banktypes.NewMsgSend(key.GetAddress(), to, amt) + if err := msg.ValidateBasic(); err != nil { + return err + } + + res, _, err := c.SendMsg(msg) + if err != nil { + return err + } + + return c.Print(res, false, true) + }, + } + + return cmd +} + func createClientsCmd() *cobra.Command { cmd := &cobra.Command{ Use: "clients [path-name]",