Skip to content

Commit

Permalink
Fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
tnachen committed Sep 12, 2019
1 parent 63600e5 commit 57a8696
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 2 deletions.
1 change: 0 additions & 1 deletion .pending/features/gaiacli/3872-Add-gaiacli-tx-

This file was deleted.

1 change: 0 additions & 1 deletion .pending/features/gaiarest/3872-Add-POST-txs-de

This file was deleted.

1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ and tx hash will be returned for specific Tendermint errors:
* `CodeTxInMempoolCache`
* `CodeMempoolIsFull`
* `CodeTxTooLarge`
* (cli) [\#3872](https://github.com/cosmos/cosmos-sdk/issues/3872) Implement a RESTful endpoint and cli command to decode txs via `POST /txs/decode`

### Improvements

Expand Down
1 change: 1 addition & 0 deletions x/auth/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func GetTxCmd(cdc *codec.Codec) *cobra.Command {
txCmd.AddCommand(
GetMultiSignCommand(cdc),
GetSignCommand(cdc),
GetDecodeCommand(cdc),
)
return txCmd
}
52 changes: 52 additions & 0 deletions x/auth/client/cli/tx_decode.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package cli

import (
"encoding/base64"

"github.com/spf13/cobra"
"github.com/tendermint/go-amino"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/context"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
)

// txDecodeRespStr implements a simple Stringer wrapper for a decoded tx.
type txDecodeRespTx authtypes.StdTx

func (tx txDecodeRespTx) String() string {
return tx.String()
}

// GetDecodeCommand returns the decode command to take Amino-serialized bytes and turn it into
// a JSONified transaction
func GetDecodeCommand(codec *amino.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "decode [amino-byte-string]",
Short: "Decode an amino-encoded transaction string",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) (err error) {
cliCtx := context.NewCLIContext().WithCodec(codec)

txBytesBase64 := args[0]

txBytes, err := base64.StdEncoding.DecodeString(txBytesBase64)
if err != nil {
return err
}

var stdTx authtypes.StdTx
err = cliCtx.Codec.UnmarshalBinaryLengthPrefixed(txBytes, &stdTx)
if err != nil {
return err
}

response := txDecodeRespTx(stdTx)
_ = cliCtx.PrintOutput(response)

return nil
},
}

return client.PostCommands(cmd)[0]
}

0 comments on commit 57a8696

Please sign in to comment.