* remove unused functions * create helper func to send tx * refactor to use test help to send tx by client * Commit before getting backend. * Temporal commit * temp commit * remove the creation of txbuilder from cli * fix imports * update changelog * Remove unused function. * Add flag home into tx sign command. * migrade TestCLIValidateSignatures to use new test suite * migrate test one * Add changes to make sign batch. * make test pass * refactor common logic * First part of cli sign. * Add test for sign batch. * refactor a little and improve the test * migrate broadcast command * fix linter * Remove printf for debug in bank module. * Fix unused err var. * fix linter * fix test * fix tests client * Fix linter. * Temp commit signature. * encode tx * migrate tests * Fix imports. * Remove changelog * fix tests * Fix tests. * Update x/bank/client/testutil/cli_helpers.go * Remove alias. * Remove wait for N block func. * export callCmd function into its own file. * fix imports * bring back to inner functions * apply mock io * the helpers use mockio * fix bug * Add Helpers. * return to put the function in testutil package * return BufferWriter in ExecTestCLICmd Co-authored-by: Alessio Treglia <alessio@tendermint.com> Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>
56 lines
1.5 KiB
Go
56 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() *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 {
|
|
clientCtx := client.GetClientContextFromCmd(cmd)
|
|
|
|
tx, err := authclient.ReadTxFromFile(clientCtx, args[0])
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// re-encode it
|
|
txBytes, err := clientCtx.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)
|
|
},
|
|
}
|
|
|
|
flags.AddTxFlagsToCmd(cmd)
|
|
|
|
return cmd
|
|
}
|