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

Add debug commands #5244

Merged
merged 10 commits into from
Nov 11, 2019
52 changes: 30 additions & 22 deletions client/debug/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@ import (
"encoding/base64"
"encoding/hex"
"fmt"
"strings"

"github.com/cosmos/cosmos-sdk/codec"

"strconv"
tac0turtle marked this conversation as resolved.
Show resolved Hide resolved
"strings"

"github.com/cosmos/cosmos-sdk/client"
"github.com/spf13/cobra"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/ed25519"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
)

func Cmd(cdc *codec.Codec) *cobra.Command {
Expand All @@ -34,9 +33,12 @@ func Cmd(cdc *codec.Codec) *cobra.Command {

tac0turtle marked this conversation as resolved.
Show resolved Hide resolved
func PubkeyCmd(cdc *codec.Codec) *cobra.Command {
alexanderbez marked this conversation as resolved.
Show resolved Hide resolved
return &cobra.Command{
Use: "pubkey",
Use: "pubkey [pubkey]",
Short: "Decode a pubkey from hex, base64, or bech32",
Args: cobra.ExactArgs(1),
Long: `Decode a public key:

$ <appcli> debug pubkey <pubkey> `,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {

pubkeyString := args[0]
Expand Down Expand Up @@ -98,22 +100,25 @@ func PubkeyCmd(cdc *codec.Codec) *cobra.Command {
if err != nil {
return err
}
fmt.Println("Address:", pubKey.Address())
fmt.Printf("Hex: %X\n", pubkeyBytes)
fmt.Println("JSON (base64):", string(pubKeyJSONBytes))
fmt.Println("Bech32 Acc:", accPub)
fmt.Println("Bech32 Validator Operator:", valPub)
fmt.Println("Bech32 Validator Consensus:", consenusPub)
cmd.Println("Address:", pubKey.Address())
cmd.Printf("Hex: %X\n", pubkeyBytes)
cmd.Println("JSON (base64):", string(pubKeyJSONBytes))
cmd.Println("Bech32 Acc:", accPub)
cmd.Println("Bech32 Validator Operator:", valPub)
cmd.Println("Bech32 Validator Consensus:", consenusPub)
return nil
},
}
}

func AddrCmd() *cobra.Command {
return &cobra.Command{
Use: "addr",
Use: "addr [address]",
Short: "Convert an address between hex and bech32",
Args: cobra.ExactArgs(1),
Long: `Convert addresses:

tac0turtle marked this conversation as resolved.
Show resolved Hide resolved
$ <appcli> debug addr <address>`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {

addrString := args[0]
Expand Down Expand Up @@ -143,20 +148,23 @@ func AddrCmd() *cobra.Command {
accAddr := sdk.AccAddress(addr)
valAddr := sdk.ValAddress(addr)

fmt.Println("Address:", addr)
fmt.Printf("Address (hex): %X\n", addr)
fmt.Printf("Bech32 Acc: %s\n", accAddr)
fmt.Printf("Bech32 Val: %s\n", valAddr)
cmd.Println("Address:", addr)
cmd.Printf("Address (hex): %X\n", addr)
cmd.Printf("Bech32 Acc: %s\n", accAddr)
cmd.Printf("Bech32 Val: %s\n", valAddr)
return nil
},
}
}

func RawBytesCmd() *cobra.Command {
return &cobra.Command{
Use: "raw-bytes",
Use: "raw-bytes [raw-bytes]",
Short: "Convert raw bytes output (eg. [10 21 13 255]) to hex",
Args: cobra.ExactArgs(1),
Long: `Convert bytes output:

$ <appcli> debug raw-bytes <bytes>`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
stringBytes := args[0]
stringBytes = strings.Trim(stringBytes, "[")
Expand Down
14 changes: 8 additions & 6 deletions x/auth/client/cli/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,15 @@ 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 {
// GetDecodeTxCmd - returns the command to decode a tx from hex or base64
func GetDecodeTxCmd(cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "tx",
Use: "decode-tx [tx]",
Short: "Decode a tx from hex or base64",
Args: cobra.ExactArgs(1),
Long: `Decode Tx from hez or base64:

$ <appcli> decode-tx <tx>`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {

txString := args[0]
Expand Down Expand Up @@ -81,8 +84,7 @@ func DecodeTxCmd(cdc *codec.Codec) *cobra.Command {
}

buf := bytes.NewBuffer([]byte{})
err = json.Indent(buf, bz, "", " ")
if err != nil {
if err = json.Indent(buf, bz, "", " "); err != nil {
return err
}

Expand Down