basecli sendtx handles chain/addr format
This commit is contained in:
parent
cba5523ca5
commit
33d4f930da
|
@ -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
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue