diff --git a/client/keys/add.go b/client/keys/add.go index 60f4dfe20060..9ef7f0531046 100644 --- a/client/keys/add.go +++ b/client/keys/add.go @@ -39,8 +39,42 @@ const ( DefaultKeyPass = "12345678" ) -// AddKeyCommand defines a keys command to add a generated or recovered private key to keybase. -func AddKeyCommand() *cobra.Command { +func addKeyScriptingCommand() *cobra.Command { + cmd := &cobra.Command{ + Use: "test [name] [mnemonic] [password]", + Short: "Add a recovered mnemonic to the keystore encrypt it, and save to disk, for testing", + Long: `Derive a new private key from an existing mnemonic file and encrypt to disk. + +NOTE: This is insecure and only meant to be used during testing!!!! HERE BE DRAGONS! +`, + Args: cobra.ExactArgs(3), + RunE: func(cmd *cobra.Command, args []string) error { + kb, err := NewKeyBaseFromHomeFlag() + if err != nil { + return err + } + + _, err = kb.Get(args[0]) + if err == nil { + return errors.New("key already exists, exiting") + } + + if !bip39.IsMnemonicValid(args[1]) { + return errors.New("invalid mnemonic") + } + + info, err := kb.CreateAccount(args[0], args[1], "", args[2], keys.CreateHDPath(0, 0).String(), keys.Secp256k1) + if err != nil { + return err + } + + return printCreate(cmd, info, false, "") + }, + } + return cmd +} + +func addKeyCommand() *cobra.Command { cmd := &cobra.Command{ Use: "add ", Short: "Add an encrypted private key (either newly generated or recovered), encrypt it, and save to disk", diff --git a/client/keys/root.go b/client/keys/root.go index b7f70059c015..7786070e9109 100644 --- a/client/keys/root.go +++ b/client/keys/root.go @@ -21,7 +21,7 @@ func Commands() *cobra.Command { } cmd.AddCommand( MnemonicKeyCommand(), - AddKeyCommand(), + addKeyCommand(), ExportKeyCommand(), ImportKeyCommand(), ListKeysCmd(), @@ -31,6 +31,7 @@ func Commands() *cobra.Command { UpdateKeyCommand(), ParseKeyStringCommand(), MigrateCommand(), + addKeyScriptingCommand(), ) cmd.PersistentFlags().String(flags.FlagKeyringBackend, flags.DefaultKeyringBackend, "Select keyring's backend (os|file|test)") viper.BindPFlag(flags.FlagKeyringBackend, cmd.Flags().Lookup(flags.FlagKeyringBackend)) diff --git a/types/coin.go b/types/coin.go index 98eaa6b806df..a23e3962e37e 100644 --- a/types/coin.go +++ b/types/coin.go @@ -594,8 +594,8 @@ func (coins Coins) Sort() Coins { // Parsing var ( - // Denominations can be 3 ~ 16 characters long. - reDnmString = `[a-z][a-z0-9]{2,15}` + // Denominations can be 3 ~ 32 characters long. + reDnmString = `[a-z][a-z0-9/]{2,31}` reAmt = `[[:digit:]]+` reDecAmt = `[[:digit:]]*\.[[:digit:]]+` reSpc = `[[:space:]]*` diff --git a/x/ibc/04-channel/client/cli/tx.go b/x/ibc/04-channel/client/cli/tx.go index 833ed29af01c..265ec880d73a 100644 --- a/x/ibc/04-channel/client/cli/tx.go +++ b/x/ibc/04-channel/client/cli/tx.go @@ -14,6 +14,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/client/keys" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/version" @@ -356,17 +357,17 @@ $ %s tx ibc channel handshake [client-id] [port-id] [chan-id] [conn-id] [cp-clie WithCodec(cdc). WithBroadcastMode(flags.BroadcastBlock) - // // get passphrase for key from1 - // passphrase1, err := keys.GetPassphrase(from1) - // if err != nil { - // return err - // } + // get passphrase for key from1 + passphrase1, err := keys.GetPassphrase(from1) + if err != nil { + return err + } - // // get passphrase for key from2 - // passphrase2, err := keys.GetPassphrase(from2) - // if err != nil { - // return err - // } + // get passphrase for key from2 + passphrase2, err := keys.GetPassphrase(from2) + if err != nil { + return err + } // TODO: check state and if not Idle continue existing process viper.Set(flags.FlagChainID, cid1) @@ -375,8 +376,8 @@ $ %s tx ibc channel handshake [client-id] [port-id] [chan-id] [conn-id] [cp-clie return err } - err := utils.CompleteAndBroadcastTxCLI(txBldr1, ctx1, []sdk.Msg{msgOpenInit}) - if err != nil { + res, err := utils.CompleteAndBroadcastTx(txBldr1, ctx1, []sdk.Msg{msgOpenInit}, passphrase1) + if err != nil || !res.IsOK() { return err } @@ -395,8 +396,8 @@ $ %s tx ibc channel handshake [client-id] [port-id] [chan-id] [conn-id] [cp-clie return err } - err = utils.CompleteAndBroadcastTxCLI(txBldr2, ctx2, []sdk.Msg{msgUpdateClient}) - if err != nil { + res, err = utils.CompleteAndBroadcastTx(txBldr2, ctx2, []sdk.Msg{msgUpdateClient}, passphrase2) + if err != nil || !res.IsOK() { return err } @@ -411,8 +412,8 @@ $ %s tx ibc channel handshake [client-id] [port-id] [chan-id] [conn-id] [cp-clie return err } - err = utils.CompleteAndBroadcastTxCLI(txBldr2, ctx2, []sdk.Msg{msgOpenTry}) - if err != nil { + res, err = utils.CompleteAndBroadcastTx(txBldr2, ctx2, []sdk.Msg{msgOpenTry}, passphrase2) + if err != nil || !res.IsOK() { return err } @@ -431,8 +432,8 @@ $ %s tx ibc channel handshake [client-id] [port-id] [chan-id] [conn-id] [cp-clie return err } - err = utils.CompleteAndBroadcastTxCLI(txBldr1, ctx1, []sdk.Msg{msgUpdateClient}) - if err != nil { + res, err = utils.CompleteAndBroadcastTx(txBldr1, ctx1, []sdk.Msg{msgUpdateClient}, passphrase1) + if err != nil || !res.IsOK() { return err } @@ -448,8 +449,8 @@ $ %s tx ibc channel handshake [client-id] [port-id] [chan-id] [conn-id] [cp-clie return err } - err = utils.CompleteAndBroadcastTxCLI(txBldr1, ctx1, []sdk.Msg{msgOpenAck}) - if err != nil { + res, err = utils.CompleteAndBroadcastTx(txBldr1, ctx1, []sdk.Msg{msgOpenAck}, passphrase1) + if err != nil || !res.IsOK() { return err } @@ -468,8 +469,8 @@ $ %s tx ibc channel handshake [client-id] [port-id] [chan-id] [conn-id] [cp-clie return err } - err = utils.CompleteAndBroadcastTxCLI(txBldr2, ctx2, []sdk.Msg{msgUpdateClient}) - if err != nil { + res, err = utils.CompleteAndBroadcastTx(txBldr2, ctx2, []sdk.Msg{msgUpdateClient}, passphrase2) + if err != nil || !res.IsOK() { return err } @@ -484,8 +485,8 @@ $ %s tx ibc channel handshake [client-id] [port-id] [chan-id] [conn-id] [cp-clie return err } - err = utils.CompleteAndBroadcastTxCLI(txBldr2, ctx2, []sdk.Msg{msgOpenConfirm}) - if err != nil { + res, err = utils.CompleteAndBroadcastTx(txBldr2, ctx2, []sdk.Msg{msgOpenConfirm}, passphrase2) + if err != nil || !res.IsOK() { return err } diff --git a/x/ibc/20-transfer/client/cli/query.go b/x/ibc/20-transfer/client/cli/query.go index 1795e1919edb..4be0103385ee 100644 --- a/x/ibc/20-transfer/client/cli/query.go +++ b/x/ibc/20-transfer/client/cli/query.go @@ -15,15 +15,15 @@ import ( abci "github.com/tendermint/tendermint/abci/types" ) -// GetTxCmd returns the transaction commands for IBC fungible token transfer -func GetQueryCmd(cdc *codec.Codec, storeKey string) *cobra.Command { +// GetQueryCmd returns the query commands for IBC fungible token transfer +func GetQueryCmd(cdc *codec.Codec, queryRoute string) *cobra.Command { queryCmd := &cobra.Command{ Use: "transfer", Short: "IBC fungible token transfer query subcommands", } queryCmd.AddCommand( - GetCmdQueryNextSequence(cdc, storeKey), + GetCmdQueryNextSequence(cdc, queryRoute), ) return queryCmd diff --git a/x/ibc/20-transfer/client/cli/tx.go b/x/ibc/20-transfer/client/cli/tx.go index 28870567b55c..13917f47a62d 100644 --- a/x/ibc/20-transfer/client/cli/tx.go +++ b/x/ibc/20-transfer/client/cli/tx.go @@ -12,8 +12,8 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/auth/client/utils" - clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types" clientutils "github.com/cosmos/cosmos-sdk/x/ibc/02-client/client/utils" + clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types" channelutils "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/client/utils" "github.com/cosmos/cosmos-sdk/x/ibc/20-transfer/types" commitment "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment" @@ -26,7 +26,7 @@ var ( FlagNode2 = "node2" FlagFrom1 = "from1" FlagFrom2 = "from2" - FlagChainId2 = "chain-id2" + FlagChainID2 = "chain-id2" FlagSequence = "packet-sequence" FlagTimeout = "timeout" ) @@ -96,7 +96,7 @@ func GetMsgRecvPacketCmd(cdc *codec.Codec) *cobra.Command { node2 := viper.GetString(FlagNode2) cid1 := viper.GetString(flags.FlagChainID) - cid2 := viper.GetString(FlagChainId2) + cid2 := viper.GetString(FlagChainID2) cliCtx2 := context.NewCLIContextIBC(cliCtx.GetFromAddress().String(), cid2, node2). WithCodec(cdc). WithBroadcastMode(flags.BroadcastBlock) @@ -143,7 +143,7 @@ func GetMsgRecvPacketCmd(cdc *codec.Codec) *cobra.Command { cmd = client.PostCommands(cmd)[0] cmd.Flags().Bool(FlagSource, false, "Pass flag for sending token from the source chain") cmd.Flags().String(FlagNode2, "tcp://localhost:26657", "RPC port for the second chain") - cmd.Flags().String(FlagChainId2, "", "chain-id for the second chain") + cmd.Flags().String(FlagChainID2, "", "chain-id for the second chain") cmd.Flags().String(FlagSequence, "", "sequence for the packet") cmd.Flags().String(FlagTimeout, "", "timeout for the packet") return cmd diff --git a/x/ibc/20-transfer/module.go b/x/ibc/20-transfer/module.go index 269be2377f6e..a1e12ec35d8f 100644 --- a/x/ibc/20-transfer/module.go +++ b/x/ibc/20-transfer/module.go @@ -16,3 +16,8 @@ func Name() string { func GetTxCmd(cdc *codec.Codec) *cobra.Command { return cli.GetTxCmd(cdc) } + +// GetQueryCmd returns the root tx command for the IBC transfer. +func GetQueryCmd(cdc *codec.Codec, queryRoute string) *cobra.Command { + return cli.GetQueryCmd(cdc, queryRoute) +} diff --git a/x/ibc/client/cli/cli.go b/x/ibc/client/cli/cli.go index cc6bd3bd7822..4818d68008d6 100644 --- a/x/ibc/client/cli/cli.go +++ b/x/ibc/client/cli/cli.go @@ -45,6 +45,8 @@ func GetQueryCmd(queryRoute string, cdc *codec.Codec) *cobra.Command { ibcQueryCmd.AddCommand(client.GetCommands( ibcclient.GetQueryCmd(cdc, queryRoute), connection.GetQueryCmd(cdc, queryRoute), + channel.GetQueryCmd(cdc, queryRoute), + transfer.GetQueryCmd(cdc, queryRoute), )...) return ibcQueryCmd }