diff --git a/client/debug/main.go b/client/debug/main.go index adfb40eacd87..7ba6ce839af3 100644 --- a/client/debug/main.go +++ b/client/debug/main.go @@ -1,10 +1,8 @@ package debug import ( - "bytes" "encoding/base64" "encoding/hex" - "encoding/json" "fmt" "strings" @@ -16,7 +14,6 @@ import ( "github.com/spf13/cobra" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/auth" "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/ed25519" ) @@ -28,7 +25,6 @@ func Cmd(cdc *codec.Codec) *cobra.Command { RunE: client.ValidateCmd, } - cmd.AddCommand(TxCmd(cdc)) cmd.AddCommand(PubkeyCmd(cdc)) cmd.AddCommand(AddrCmd()) cmd.AddCommand(RawBytesCmd()) @@ -36,52 +32,6 @@ func Cmd(cdc *codec.Codec) *cobra.Command { return cmd } -func TxCmd(cdc *codec.Codec) *cobra.Command { - return &cobra.Command{ - Use: "tx", - Short: "Decode a tx from hex or base64", - Args: cobra.ExactArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - - txString := args[0] - - // try hex, then base64 - txBytes, err := hex.DecodeString(txString) - if err != nil { - var err2 error - txBytes, err2 = base64.StdEncoding.DecodeString(txString) - if err2 != nil { - return fmt.Errorf(`expected hex or base64. Got errors: - hex: %v, - base64: %v - `, err, err2) - } - } - - var tx = auth.StdTx{} - - err = cdc.UnmarshalBinaryLengthPrefixed(txBytes, &tx) - if err != nil { - return err - } - - bz, err := cdc.MarshalJSON(tx) - if err != nil { - return err - } - - buf := bytes.NewBuffer([]byte{}) - err = json.Indent(buf, bz, "", " ") - if err != nil { - return err - } - - fmt.Println(buf.String()) - return nil - }, - } -} - func PubkeyCmd(cdc *codec.Codec) *cobra.Command { return &cobra.Command{ Use: "pubkey", diff --git a/x/auth/client/cli/decode.go b/x/auth/client/cli/decode.go index 3d8fa1f3ceca..90bbb635471a 100644 --- a/x/auth/client/cli/decode.go +++ b/x/auth/client/cli/decode.go @@ -1,13 +1,19 @@ package cli import ( + "bytes" "encoding/base64" + "encoding/hex" + "encoding/json" + "fmt" "github.com/spf13/cobra" "github.com/tendermint/go-amino" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/context" + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/x/auth/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" ) @@ -38,3 +44,50 @@ func GetDecodeCommand(codec *amino.Codec) *cobra.Command { return client.PostCommands(cmd)[0] } + +// DecodeTxCmd - returns the command to decode a tx from hex or base64 +func DecodeTxCmd(cdc *codec.Codec) *cobra.Command { + return &cobra.Command{ + Use: "tx", + Short: "Decode a tx from hex or base64", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + + txString := args[0] + + // try hex, then base64 + txBytes, err := hex.DecodeString(txString) + if err != nil { + var err2 error + txBytes, err2 = base64.StdEncoding.DecodeString(txString) + if err2 != nil { + return fmt.Errorf(`expected hex or base64. Got errors: + hex: %v, + base64: %v + `, err, err2) + } + } + + var tx = types.StdTx{} + + err = cdc.UnmarshalBinaryLengthPrefixed(txBytes, &tx) + if err != nil { + return err + } + + bz, err := cdc.MarshalJSON(tx) + if err != nil { + return err + } + + buf := bytes.NewBuffer([]byte{}) + err = json.Indent(buf, bz, "", " ") + if err != nil { + return err + } + + fmt.Println(buf.String()) + return nil + }, + } +}