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

cli: ux cleanup for tx commands #467

Merged
merged 11 commits into from
Mar 24, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,24 +151,26 @@ $ rly paths list
$ rly tx link demo -d -o 3s

# Check the token balances on both chains
$ rly q balance ibc-0
$ rly q bal ibc-1
$ rly query balance ibc-0
$ rly query bal ibc-1

# Then send some tokens between the chains
$ rly tx transfer ibc-0 ibc-1 1000000samoleans $(rly chains address ibc-1)
$ rly tx relay demo -d
$ rly tx acks demo -d

# See that the transfer has completed
$ rly q bal ibc-0
$ rly q bal ibc-1
$ rly query bal ibc-0
$ rly query bal ibc-1

# Send the tokens back to the account on ibc-0
$ rly tx xfer ibc-1 ibc-0 1000000ibc/27A6394C3F9FF9C9DCF5DFFADF9BB5FE9A37C7E92B006199894CF1824DF9AC7C $(rly ch addr ibc-0)
$ rly tx rly demo -d
$ rly tx transfer ibc-1 ibc-0 1000000ibc/27A6394C3F9FF9C9DCF5DFFADF9BB5FE9A37C7E92B006199894CF1824DF9AC7C $(rly chains addr ibc-0)
$ rly tx relay demo -d
$ rly tx acks demo -d

# See that the return trip has completed
$ rly q bal ibc-0
$ rly q bal ibc-1
$ rly query bal ibc-0
$ rly query bal ibc-1

# NOTE: you will see the stake balances decreasing on each chain. This is to pay for fees
# You can change the amount of fees you are paying on each chain in the configuration.
Expand Down
37 changes: 19 additions & 18 deletions cmd/xfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,19 @@ func (ss stringStringer) String() string {
return ss.str
}

// NOTE: These commands are registered over in cmd/raw.go

func xfersend() *cobra.Command {
cmd := &cobra.Command{
Use: "transfer [src-chain-id] [dst-chain-id] [amount] [dst-addr]",
Short: "Initiate a transfer from one chain to another",
Aliases: []string{"xfer", "txf", "send"},
Long: "Sends the first step to transfer tokens in an IBC transfer." +
" The created packet must be relayed to another chain",
Use: "transfer [src-chain-id] [dst-chain-id] [amount] [dst-addr]",
Short: "initiate a transfer from one network to another",
Long: `Initiate a token transfer via IBC between two networks. The created packet
must be relayed to the destination chain.`,
Args: cobra.ExactArgs(4),
Example: strings.TrimSpace(fmt.Sprintf(`
$ %s transact transfer ibc-0 ibc-1 100000stake cosmos1skjwj5whet0lpe65qaq4rpq03hjxlwd9nf39lk --path demo-path
$ %s tx xfer ibc-0 ibc-1 100000stake cosmos1skjwj5whet0lpe65qaq4rpq03hjxlwd9nf39lk --path demo -y 2 -c 10
$ %s tx xfer ibc-0 ibc-1 100000stake raw:non-bech32-address --path demo
$ %s tx txf ibc-0 ibc-1 100000stake cosmos1skjwj5whet0lpe65qaq4rpq03hjxlwd9nf39lk --path demo
$ %s tx transfer ibc-0 ibc-1 100000stake cosmos1skjwj5whet0lpe65qaq4rpq03hjxlwd9nf39lk --path demo-path
$ %s tx transfer ibc-0 ibc-1 100000stake cosmos1skjwj5whet0lpe65qaq4rpq03hjxlwd9nf39lk --path demo -y 2 -c 10
$ %s tx transfer ibc-0 ibc-1 100000stake raw:non-bech32-address --path demo
$ %s tx raw send ibc-0 ibc-1 100000stake cosmos1skjwj5whet0lpe65qaq4rpq03hjxlwd9nf39lk --path demo -c 5
`, appName, appName, appName, appName, appName)),
`, appName, appName, appName, appName)),
RunE: func(cmd *cobra.Command, args []string) error {
src, dst := args[0], args[1]
c, err := config.Chains.Gets(src, dst)
Expand Down Expand Up @@ -86,12 +82,14 @@ $ %s tx raw send ibc-0 ibc-1 100000stake cosmos1skjwj5whet0lpe65qaq4rpq03hjxlwd9
rawDstAddr := strings.TrimPrefix(args[3], "raw:")
var dstAddr fmt.Stringer
if rawDstAddr == args[3] {
// Not "raw:", treat the dstAddr as bech32.
// not "raw:", so we treat the dstAddr as bech32
done := c[dst].UseSDKContext()

dstAddr, err = sdk.AccAddressFromBech32(args[3])
if err != nil {
return err
}

done()
} else {
// Don't parse the rest of the dstAddr... it's raw.
Expand All @@ -101,31 +99,34 @@ $ %s tx raw send ibc-0 ibc-1 100000stake cosmos1skjwj5whet0lpe65qaq4rpq03hjxlwd9
return c[src].SendTransferMsg(c[dst], amount, dstAddr.String(), toHeightOffset, toTimeOffset)
},
}

return timeoutFlags(pathFlag(cmd))
}

func setPathsFromArgs(src, dst *relayer.Chain, name string) (*relayer.Path, error) {
// Find any configured paths between the chains
// find any configured paths between the chains
paths, err := config.Paths.PathsFromChains(src.ChainID, dst.ChainID)
if err != nil {
return nil, err
}

// Given the number of args and the number of paths,
// work on the appropriate path
// Given the number of args and the number of paths, work on the appropriate
// path.
var path *relayer.Path
switch {
case name != "" && len(paths) > 1:
if path, err = paths.Get(name); err != nil {
return path, err
}

case name != "" && len(paths) == 1:
if path, err = paths.Get(name); err != nil {
return path, err
}

case name == "" && len(paths) > 1:
return nil, fmt.Errorf("more than one path between %s and %s exists, pass in path name",
src.ChainID, dst.ChainID)
return nil, fmt.Errorf("more than one path between %s and %s exists, pass in path name", src.ChainID, dst.ChainID)

case name == "" && len(paths) == 1:
for _, v := range paths {
path = v
Expand Down