* add utils * update sign cmd * update multisign cmd * update sign batch cmd * update genutil cmd * add wrap tx builder * update gentx cli * update validate sigs cmd * fix lint * add flag reader to cli * update marshaler for batchscan * add register query server * update to master * remove depricated methods * fix keyring issue * update wraptx * Fix batch scan * fix register interfaces issue * update printOutput * Update Validate Sigs test * WIP on signature JSON * Cleanup * Cleanup * Test fixes * Test fixes * Fixes * WIP on tests * Fix gov tests * fix lint * fix MultiSign tests * fix tests * refactor tests * Cleanup * Address review comments * Update encode * Test fix * Rename SignData func * Fix lint * Fix lint * Revert ReadTxCommandFlags Co-authored-by: Aaron Craelius <aaron@regen.network> Co-authored-by: Aaron Craelius <aaronc@users.noreply.github.com>
55 lines
1.2 KiB
Go
55 lines
1.2 KiB
Go
package cli
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"encoding/hex"
|
|
"fmt"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/cosmos/cosmos-sdk/client"
|
|
"github.com/cosmos/cosmos-sdk/client/flags"
|
|
)
|
|
|
|
const flagHex = "hex"
|
|
|
|
// GetDecodeCommand returns the decode command to take serialized bytes and turn
|
|
// it into a JSON-encoded transaction.
|
|
func GetDecodeCommand() *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: "decode [amino-byte-string]",
|
|
Short: "Decode an binary encoded transaction string.",
|
|
Args: cobra.ExactArgs(1),
|
|
RunE: func(cmd *cobra.Command, args []string) (err error) {
|
|
clientCtx := client.GetClientContextFromCmd(cmd)
|
|
var txBytes []byte
|
|
|
|
if useHex, _ := cmd.Flags().GetBool(flagHex); useHex {
|
|
txBytes, err = hex.DecodeString(args[0])
|
|
} else {
|
|
txBytes, err = base64.StdEncoding.DecodeString(args[0])
|
|
}
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
tx, err := clientCtx.TxConfig.TxDecoder()(txBytes)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
json, err := clientCtx.TxConfig.TxJSONEncoder()(tx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return clientCtx.PrintString(fmt.Sprintf("%s\n", json))
|
|
},
|
|
}
|
|
|
|
cmd.Flags().BoolP(flagHex, "x", false, "Treat input as hexadecimal instead of base64")
|
|
flags.AddTxFlagsToCmd(cmd)
|
|
|
|
return cmd
|
|
}
|