refactor(crisis & vesting): remove global bech32 (#15852)
Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>
This commit is contained in:
co-authored by
Aleksandr Bezobchuk
parent
33657b3bf9
commit
e9e582aede
@@ -7,6 +7,7 @@ import (
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"cosmossdk.io/core/address"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
@@ -22,7 +23,7 @@ const (
|
||||
)
|
||||
|
||||
// GetTxCmd returns vesting module's transaction commands.
|
||||
func GetTxCmd() *cobra.Command {
|
||||
func GetTxCmd(ac address.Codec) *cobra.Command {
|
||||
txCmd := &cobra.Command{
|
||||
Use: types.ModuleName,
|
||||
Short: "Vesting transaction subcommands",
|
||||
@@ -32,9 +33,9 @@ func GetTxCmd() *cobra.Command {
|
||||
}
|
||||
|
||||
txCmd.AddCommand(
|
||||
NewMsgCreateVestingAccountCmd(),
|
||||
NewMsgCreatePermanentLockedAccountCmd(),
|
||||
NewMsgCreatePeriodicVestingAccountCmd(),
|
||||
NewMsgCreateVestingAccountCmd(ac),
|
||||
NewMsgCreatePermanentLockedAccountCmd(ac),
|
||||
NewMsgCreatePeriodicVestingAccountCmd(ac),
|
||||
)
|
||||
|
||||
return txCmd
|
||||
@@ -42,7 +43,7 @@ func GetTxCmd() *cobra.Command {
|
||||
|
||||
// NewMsgCreateVestingAccountCmd returns a CLI command handler for creating a
|
||||
// MsgCreateVestingAccount transaction.
|
||||
func NewMsgCreateVestingAccountCmd() *cobra.Command {
|
||||
func NewMsgCreateVestingAccountCmd(ac address.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "create-vesting-account [to_address] [amount] [end_time]",
|
||||
Short: "Create a new vesting account funded with an allocation of tokens.",
|
||||
@@ -57,7 +58,7 @@ timestamp.`,
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
toAddr, err := sdk.AccAddressFromBech32(args[0])
|
||||
toAddr, err := ac.StringToBytes(args[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -91,7 +92,7 @@ timestamp.`,
|
||||
|
||||
// NewMsgCreatePermanentLockedAccountCmd returns a CLI command handler for creating a
|
||||
// MsgCreatePermanentLockedAccount transaction.
|
||||
func NewMsgCreatePermanentLockedAccountCmd() *cobra.Command {
|
||||
func NewMsgCreatePermanentLockedAccountCmd(ac address.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "create-permanent-locked-account [to_address] [amount]",
|
||||
Short: "Create a new permanently locked account funded with an allocation of tokens.",
|
||||
@@ -104,7 +105,7 @@ tokens.`,
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
toAddr, err := sdk.AccAddressFromBech32(args[0])
|
||||
toAddr, err := ac.StringToBytes(args[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -140,7 +141,7 @@ type InputPeriod struct {
|
||||
|
||||
// NewMsgCreatePeriodicVestingAccountCmd returns a CLI command handler for creating a
|
||||
// MsgCreatePeriodicVestingAccountCmd transaction.
|
||||
func NewMsgCreatePeriodicVestingAccountCmd() *cobra.Command {
|
||||
func NewMsgCreatePeriodicVestingAccountCmd(ac address.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "create-periodic-vesting-account [to_address] [periods_json_file]",
|
||||
Short: "Create a new vesting account funded with an allocation of tokens.",
|
||||
@@ -168,7 +169,7 @@ func NewMsgCreatePeriodicVestingAccountCmd() *cobra.Command {
|
||||
return err
|
||||
}
|
||||
|
||||
toAddr, err := sdk.AccAddressFromBech32(args[0])
|
||||
toAddr, err := ac.StringToBytes(args[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/codec/address"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
svrcmd "github.com/cosmos/cosmos-sdk/server/cmd"
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
@@ -49,7 +50,7 @@ func (s *CLITestSuite) SetupSuite() {
|
||||
|
||||
func (s *CLITestSuite) TestNewMsgCreateVestingAccountCmd() {
|
||||
accounts := testutil.CreateKeyringAccounts(s.T(), s.kr, 1)
|
||||
cmd := cli.NewMsgCreateVestingAccountCmd()
|
||||
cmd := cli.NewMsgCreateVestingAccountCmd(address.NewBech32Codec("cosmos"))
|
||||
cmd.SetOutput(io.Discard)
|
||||
|
||||
extraArgs := []string{
|
||||
@@ -138,7 +139,7 @@ func (s *CLITestSuite) TestNewMsgCreateVestingAccountCmd() {
|
||||
|
||||
func (s *CLITestSuite) TestNewMsgCreatePermanentLockedAccountCmd() {
|
||||
accounts := testutil.CreateKeyringAccounts(s.T(), s.kr, 1)
|
||||
cmd := cli.NewMsgCreatePermanentLockedAccountCmd()
|
||||
cmd := cli.NewMsgCreatePermanentLockedAccountCmd(address.NewBech32Codec("cosmos"))
|
||||
cmd.SetOutput(io.Discard)
|
||||
|
||||
extraArgs := []string{
|
||||
@@ -217,7 +218,7 @@ func (s *CLITestSuite) TestNewMsgCreatePermanentLockedAccountCmd() {
|
||||
|
||||
func (s *CLITestSuite) TestNewMsgCreatePeriodicVestingAccountCmd() {
|
||||
accounts := testutil.CreateKeyringAccounts(s.T(), s.kr, 1)
|
||||
cmd := cli.NewMsgCreatePeriodicVestingAccountCmd()
|
||||
cmd := cli.NewMsgCreatePeriodicVestingAccountCmd(address.NewBech32Codec("cosmos"))
|
||||
cmd.SetOutput(io.Discard)
|
||||
|
||||
extraArgs := []string{
|
||||
|
||||
@@ -17,6 +17,7 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/types/module"
|
||||
|
||||
modulev1 "cosmossdk.io/api/cosmos/vesting/module/v1"
|
||||
"cosmossdk.io/core/address"
|
||||
"cosmossdk.io/core/appmodule"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/keeper"
|
||||
@@ -32,7 +33,9 @@ var (
|
||||
// AppModuleBasic defines the basic application module used by the sub-vesting
|
||||
// module. The module itself contain no special logic or state other than message
|
||||
// handling.
|
||||
type AppModuleBasic struct{}
|
||||
type AppModuleBasic struct {
|
||||
ac address.Codec
|
||||
}
|
||||
|
||||
// Name returns the module's name.
|
||||
func (AppModuleBasic) Name() string {
|
||||
@@ -62,11 +65,11 @@ func (AppModuleBasic) ValidateGenesis(_ codec.JSONCodec, _ client.TxEncodingConf
|
||||
|
||||
// RegisterGRPCGatewayRoutes registers the module's gRPC Gateway routes. Currently, this
|
||||
// is a no-op.
|
||||
func (a AppModuleBasic) RegisterGRPCGatewayRoutes(_ client.Context, _ *gwruntime.ServeMux) {}
|
||||
func (AppModuleBasic) RegisterGRPCGatewayRoutes(_ client.Context, _ *gwruntime.ServeMux) {}
|
||||
|
||||
// GetTxCmd returns the root tx command for the auth module.
|
||||
func (AppModuleBasic) GetTxCmd() *cobra.Command {
|
||||
return cli.GetTxCmd()
|
||||
func (ab AppModuleBasic) GetTxCmd() *cobra.Command {
|
||||
return cli.GetTxCmd(ab.ac)
|
||||
}
|
||||
|
||||
// GetQueryCmd returns the module's root query command. Currently, this is a no-op.
|
||||
@@ -85,7 +88,7 @@ type AppModule struct {
|
||||
|
||||
func NewAppModule(ak keeper.AccountKeeper, bk types.BankKeeper) AppModule {
|
||||
return AppModule{
|
||||
AppModuleBasic: AppModuleBasic{},
|
||||
AppModuleBasic: AppModuleBasic{ac: ak},
|
||||
accountKeeper: ak,
|
||||
bankKeeper: bk,
|
||||
}
|
||||
|
||||
@@ -29,12 +29,12 @@ func NewMsgServerImpl(k keeper.AccountKeeper, bk types.BankKeeper) types.MsgServ
|
||||
var _ types.MsgServer = msgServer{}
|
||||
|
||||
func (s msgServer) CreateVestingAccount(goCtx context.Context, msg *types.MsgCreateVestingAccount) (*types.MsgCreateVestingAccountResponse, error) {
|
||||
from, err := sdk.AccAddressFromBech32(msg.FromAddress)
|
||||
from, err := s.AccountKeeper.StringToBytes(msg.FromAddress)
|
||||
if err != nil {
|
||||
return nil, sdkerrors.ErrInvalidAddress.Wrapf("invalid 'from' address: %s", err)
|
||||
}
|
||||
|
||||
to, err := sdk.AccAddressFromBech32(msg.ToAddress)
|
||||
to, err := s.AccountKeeper.StringToBytes(msg.ToAddress)
|
||||
if err != nil {
|
||||
return nil, sdkerrors.ErrInvalidAddress.Wrapf("invalid 'to' address: %s", err)
|
||||
}
|
||||
@@ -95,12 +95,12 @@ func (s msgServer) CreateVestingAccount(goCtx context.Context, msg *types.MsgCre
|
||||
}
|
||||
|
||||
func (s msgServer) CreatePermanentLockedAccount(goCtx context.Context, msg *types.MsgCreatePermanentLockedAccount) (*types.MsgCreatePermanentLockedAccountResponse, error) {
|
||||
from, err := sdk.AccAddressFromBech32(msg.FromAddress)
|
||||
from, err := s.AccountKeeper.StringToBytes(msg.FromAddress)
|
||||
if err != nil {
|
||||
return nil, sdkerrors.ErrInvalidAddress.Wrapf("invalid 'from' address: %s", err)
|
||||
}
|
||||
|
||||
to, err := sdk.AccAddressFromBech32(msg.ToAddress)
|
||||
to, err := s.AccountKeeper.StringToBytes(msg.ToAddress)
|
||||
if err != nil {
|
||||
return nil, sdkerrors.ErrInvalidAddress.Wrapf("invalid 'to' address: %s", err)
|
||||
}
|
||||
@@ -150,12 +150,12 @@ func (s msgServer) CreatePermanentLockedAccount(goCtx context.Context, msg *type
|
||||
}
|
||||
|
||||
func (s msgServer) CreatePeriodicVestingAccount(goCtx context.Context, msg *types.MsgCreatePeriodicVestingAccount) (*types.MsgCreatePeriodicVestingAccountResponse, error) {
|
||||
from, err := sdk.AccAddressFromBech32(msg.FromAddress)
|
||||
from, err := s.AccountKeeper.StringToBytes(msg.FromAddress)
|
||||
if err != nil {
|
||||
return nil, sdkerrors.ErrInvalidAddress.Wrapf("invalid 'from' address: %s", err)
|
||||
}
|
||||
|
||||
to, err := sdk.AccAddressFromBech32(msg.ToAddress)
|
||||
to, err := s.AccountKeeper.StringToBytes(msg.ToAddress)
|
||||
if err != nil {
|
||||
return nil, sdkerrors.ErrInvalidAddress.Wrapf("invalid 'to' address: %s", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user