diff --git a/cmd/basecli/commands/cmds.go b/cmd/basecli/commands/cmds.go index faf54c227..d6d598590 100644 --- a/cmd/basecli/commands/cmds.go +++ b/cmd/basecli/commands/cmds.go @@ -2,6 +2,7 @@ package commands import ( "encoding/hex" + "strings" "github.com/pkg/errors" "github.com/spf13/cobra" @@ -78,9 +79,9 @@ func doSendTx(cmd *cobra.Command, args []string) error { func readSendTxFlags(tx *btypes.SendTx) error { // parse to address - to, err := ParseHexFlag(FlagTo) + to, err := parseChainAddress(viper.GetString(FlagTo)) if err != nil { - return errors.Errorf("To address is invalid hex: %v\n", err) + return err } //parse the fee and amounts into coin types @@ -109,6 +110,32 @@ func readSendTxFlags(tx *btypes.SendTx) error { return nil } +func parseChainAddress(toFlag string) ([]byte, error) { + var toHex string + var chainPrefix string + spl := strings.Split(toFlag, "/") + switch len(spl) { + case 1: + toHex = spl[0] + case 2: + chainPrefix = spl[0] + toHex = spl[1] + default: + return nil, errors.Errorf("To address has too many slashes") + } + + // convert destination address to bytes + to, err := hex.DecodeString(cmn.StripHex(toHex)) + if err != nil { + return nil, errors.Errorf("To address is invalid hex: %v\n", err) + } + + if chainPrefix != "" { + to = []byte(chainPrefix + "/" + string(to)) + } + return to, nil +} + /******** AppTx *********/ // BroadcastAppTx wraps, signs, and executes an app tx basecoin transaction diff --git a/cmd/basecli/commands/sendtx.go b/cmd/basecli/commands/sendtx.go index ccf00c6ed..178e4e37d 100644 --- a/cmd/basecli/commands/sendtx.go +++ b/cmd/basecli/commands/sendtx.go @@ -97,7 +97,8 @@ func (s *SendTx) ValidateBasic() error { } } for _, out := range s.Tx.Outputs { - if len(out.Address) != 20 { + // we now allow chain/addr, so it can be more than 20 bytes + if len(out.Address) < 20 { return errors.Errorf("Invalid output address length: %d", len(out.Address)) } if !out.Coins.IsValid() { diff --git a/tests/cli/ibc.sh b/tests/cli/ibc.sh index 49c607834..dbe1ff4f9 100755 --- a/tests/cli/ibc.sh +++ b/tests/cli/ibc.sh @@ -5,6 +5,8 @@ # these are two globals to control all scripts (can use eg. counter instead) SERVER_EXE=basecoin CLIENT_EXE=basecli +# just uncomment this line for full stack traces in error output +# CLIENT_EXE="basecli --trace" oneTimeSetUp() { # these are passed in as args