Skip to content

Commit

Permalink
remove x/ dep from client - thanks alessio for the pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
tac0turtle committed Oct 25, 2019
1 parent 2feb737 commit f15ec6e
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 50 deletions.
50 changes: 0 additions & 50 deletions client/debug/main.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package debug

import (
"bytes"
"encoding/base64"
"encoding/hex"
"encoding/json"
"fmt"
"strings"

Expand All @@ -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"
)
Expand All @@ -28,60 +25,13 @@ func Cmd(cdc *codec.Codec) *cobra.Command {
RunE: client.ValidateCmd,
}

cmd.AddCommand(TxCmd(cdc))
cmd.AddCommand(PubkeyCmd(cdc))
cmd.AddCommand(AddrCmd())
cmd.AddCommand(RawBytesCmd())

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",
Expand Down
53 changes: 53 additions & 0 deletions x/auth/client/cli/decode.go
Original file line number Diff line number Diff line change
@@ -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"
)

Expand Down Expand Up @@ -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
},
}
}

0 comments on commit f15ec6e

Please sign in to comment.