* Migrate encode, decode, and broadcast cmd's to use TxGenerator marshal methods * Fix tests, add EncodingConfig * Add simapp/encoding.go and wire up with simcli * add godocs * fix tests * Debugging CLI Tests * Fix integration test * 6391 - lint issues and code coverage (#6414) * fixed lint issue of "txEncodeRespStr" * added tests for encode.go * WIP: added tests for decode.go * added txEncoder at bytes * updated decode test * updated txBytes to use TxEncoder in decoder test * added a require after TxEncoder * removed file save * debug decode command * fixed decode tests * added decode cli * updated encode and decode in a single file * separated decode test from encode test * review changes * removed register interface * review change * Fix tests * WIP add test for tx sign * removed commented code * Fix flags * WIP add test for sign * Address review suggestions * fixed command issue * Add tests for TxEncoder * Revert sign changes * Fix TxEncoder tests * Fix GetSign Cmd * Add tx test * Remove duplicate validation * Add tests for TxDecoder * Fix tests * Fix tests * Output to clientCtx.Output * Fix cli_tests Co-authored-by: atheeshp <59333759+atheeshp@users.noreply.github.com> Co-authored-by: atheesh <atheesh@vitwit.com> Co-authored-by: anilCSE <anil@vitwit.com> Co-authored-by: sahith-narahari <sahithnarahari@gmail.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
54 lines
1.5 KiB
Go
54 lines
1.5 KiB
Go
package cli
|
|
|
|
import (
|
|
"encoding/base64"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/cosmos/cosmos-sdk/client"
|
|
"github.com/cosmos/cosmos-sdk/client/flags"
|
|
authclient "github.com/cosmos/cosmos-sdk/x/auth/client"
|
|
)
|
|
|
|
// txEncodeRespStr implements a simple Stringer wrapper for a encoded tx.
|
|
type txEncodeRespStr string
|
|
|
|
func (txr txEncodeRespStr) String() string {
|
|
return string(txr)
|
|
}
|
|
|
|
// GetEncodeCommand returns the encode command to take a JSONified transaction and turn it into
|
|
// Amino-serialized bytes
|
|
func GetEncodeCommand(clientCtx client.Context) *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: "encode [file]",
|
|
Short: "Encode transactions generated offline",
|
|
Long: `Encode transactions created with the --generate-only flag and signed with the sign command.
|
|
Read a transaction from <file>, serialize it to the Amino wire protocol, and output it as base64.
|
|
If you supply a dash (-) argument in place of an input filename, the command reads from standard input.`,
|
|
Args: cobra.ExactArgs(1),
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
cliCtx := clientCtx.Init()
|
|
|
|
tx, err := authclient.ReadTxFromFile(cliCtx, args[0])
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// re-encode it
|
|
txBytes, err := cliCtx.TxGenerator.TxEncoder()(tx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// base64 encode the encoded tx bytes
|
|
txBytesBase64 := base64.StdEncoding.EncodeToString(txBytes)
|
|
|
|
response := txEncodeRespStr(txBytesBase64)
|
|
return clientCtx.PrintOutput(response)
|
|
},
|
|
}
|
|
|
|
return flags.PostCommands(cmd)[0]
|
|
}
|