Merge PR #5244: Add debug commands
This commit is contained in:
committed by
Alexander Bezobchuk
parent
d81d46192a
commit
92d2dbe3ff
@@ -1,13 +1,20 @@
|
||||
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/version"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
)
|
||||
|
||||
@@ -38,3 +45,54 @@ func GetDecodeCommand(codec *amino.Codec) *cobra.Command {
|
||||
|
||||
return client.PostCommands(cmd)[0]
|
||||
}
|
||||
|
||||
// GetDecodeTxCmd - returns the command to decode a tx from hex or base64
|
||||
func GetDecodeTxCmd(cdc *codec.Codec) *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "decode-tx [tx]",
|
||||
Short: "Decode a tx from hex or base64",
|
||||
Long: fmt.Sprintf(`Decode a tx from hex, base64.
|
||||
|
||||
Example:
|
||||
$ %s tx decode-tx TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz
|
||||
`, version.ClientName),
|
||||
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{})
|
||||
if err = json.Indent(buf, bz, "", " "); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Println(buf.String())
|
||||
return nil
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,16 +2,11 @@ package types
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
var (
|
||||
_ Router = (*router)(nil)
|
||||
|
||||
isAlphaNumeric = regexp.MustCompile(`^[a-zA-Z0-9]+$`).MatchString
|
||||
)
|
||||
var _ Router = (*router)(nil)
|
||||
|
||||
// Router implements a governance Handler router.
|
||||
//
|
||||
|
||||
@@ -272,7 +272,7 @@ func SimulateMsgUndelegate(ak types.AccountKeeper, k keeper.Keeper) simulation.O
|
||||
}
|
||||
// if simaccount.PrivKey == nil, delegation address does not exist in accs. Return error
|
||||
if simAccount.PrivKey == nil {
|
||||
return simulation.NoOpMsg(types.ModuleName), nil, fmt.Errorf("Delegation addr: %s does not exist in simulation accounts", delAddr)
|
||||
return simulation.NoOpMsg(types.ModuleName), nil, fmt.Errorf("delegation addr: %s does not exist in simulation accounts", delAddr)
|
||||
}
|
||||
|
||||
account := ak.GetAccount(ctx, delAddr)
|
||||
@@ -371,7 +371,7 @@ func SimulateMsgBeginRedelegate(ak types.AccountKeeper, k keeper.Keeper) simulat
|
||||
}
|
||||
// if simaccount.PrivKey == nil, delegation address does not exist in accs. Return error
|
||||
if simAccount.PrivKey == nil {
|
||||
return simulation.NoOpMsg(types.ModuleName), nil, fmt.Errorf("Delegation addr: %s does not exist in simulation accounts", delAddr)
|
||||
return simulation.NoOpMsg(types.ModuleName), nil, fmt.Errorf("delegation addr: %s does not exist in simulation accounts", delAddr)
|
||||
}
|
||||
|
||||
// get tx fees
|
||||
|
||||
Reference in New Issue
Block a user