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

Add send command for individual chain #471

Merged
merged 1 commit into from
Mar 25, 2021
Merged
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
48 changes: 48 additions & 0 deletions cmd/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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]",
Expand Down