From bf8809ef9840b4f5369887a38d8345e2380a567f Mon Sep 17 00:00:00 2001 From: SaReN Date: Thu, 21 May 2020 00:51:00 +0530 Subject: [PATCH] Update x/auth to use Any (#6165) * Migrate keeper codec to use marshaler * Migrate AccountI to types * Did go imports * Fix tests for x/auth * Cleanup std/codec * Sort imports * Fix legacy codec * Add godoc for RegisterInterfaces * Add RegisterInterfaces to std * Fix typo * Fixed merge changes * Eliminate vesting import in auth * Fix lint issues * Fix tests * Addressed comments * Rename interfaces in RegisterInterfaces * Removed codec.proto from std * Minor code cleanup Co-authored-by: Aaron Craelius --- client/keys/parse.go | 3 +- simapp/app.go | 2 +- simapp/cmd/simd/genaccounts.go | 4 +- simapp/genesis_account.go | 3 +- simapp/test_helpers.go | 3 +- std/codec.go | 51 +- std/codec.pb.go | 772 ------------------- std/codec.proto | 22 - x/auth/alias.go | 4 +- x/auth/ante/expected_keepers.go | 5 +- x/auth/ante/fee.go | 3 +- x/auth/ante/sigverify.go | 7 +- x/auth/client/tx.go | 2 +- x/auth/exported/exported.go | 62 -- x/auth/exported/exported_test.go | 24 - x/auth/genesis.go | 8 +- x/auth/keeper/account.go | 19 +- x/auth/keeper/keeper.go | 63 +- x/auth/keeper/querier_test.go | 3 +- x/auth/legacy/v0_38/types.go | 2 +- x/auth/legacy/v0_39/migrate_test.go | 2 +- x/auth/module.go | 37 +- x/auth/simulation/decoder.go | 16 +- x/auth/simulation/decoder_test.go | 5 +- x/auth/simulation/genesis.go | 5 +- x/auth/types/account.go | 86 ++- x/auth/types/account_retriever.go | 12 +- x/auth/types/account_test.go | 23 +- x/auth/types/codec.go | 35 +- x/auth/types/genesis.go | 18 +- x/auth/types/genesis_test.go | 9 +- x/auth/types/stdtx.go | 3 +- x/auth/types/types.pb.go | 85 +- x/auth/types/types.proto | 3 + x/auth/vesting/alias.go | 1 + x/auth/vesting/exported/exported.go | 5 +- x/auth/vesting/types/codec.go | 27 + x/auth/vesting/types/genesis_test.go | 3 +- x/auth/vesting/types/vesting_account.go | 9 +- x/auth/vesting/types/vesting_account_test.go | 21 +- x/bank/app_test.go | 14 +- x/bank/bench_test.go | 6 +- x/bank/types/expected_keepers.go | 22 +- x/distribution/keeper/alias_functions.go | 4 +- x/distribution/keeper/delegation.go | 2 +- x/distribution/types/expected_keepers.go | 8 +- x/genutil/types/expected_keepers.go | 10 +- x/gov/keeper/keeper.go | 4 +- x/gov/types/expected_keepers.go | 8 +- x/ibc-transfer/keeper/keeper.go | 4 +- x/ibc-transfer/types/expected_keepers.go | 4 +- x/mint/types/expected_keepers.go | 6 +- x/slashing/app_test.go | 4 +- x/slashing/types/expected_keepers.go | 6 +- x/staking/app_test.go | 3 +- x/staking/keeper/pool.go | 6 +- x/staking/types/expected_keepers.go | 10 +- 57 files changed, 404 insertions(+), 1184 deletions(-) delete mode 100644 std/codec.pb.go delete mode 100644 std/codec.proto delete mode 100644 x/auth/exported/exported.go delete mode 100644 x/auth/exported/exported_test.go diff --git a/client/keys/parse.go b/client/keys/parse.go index 26b109e671..2205179137 100644 --- a/client/keys/parse.go +++ b/client/keys/parse.go @@ -12,9 +12,10 @@ import ( "github.com/spf13/viper" yaml "gopkg.in/yaml.v2" - "github.com/cosmos/cosmos-sdk/types/bech32" "github.com/tendermint/tendermint/libs/cli" + "github.com/cosmos/cosmos-sdk/types/bech32" + "github.com/cosmos/cosmos-sdk/client/flags" sdk "github.com/cosmos/cosmos-sdk/types" ) diff --git a/simapp/app.go b/simapp/app.go index e36d92b87a..e13a361b8a 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -367,7 +367,7 @@ func NewSimApp( func MakeCodecs() (*std.Codec, *codec.Codec) { cdc := std.MakeCodec(ModuleBasics) interfaceRegistry := types.NewInterfaceRegistry() - sdk.RegisterInterfaces(interfaceRegistry) + std.RegisterInterfaces(interfaceRegistry) ModuleBasics.RegisterInterfaceModules(interfaceRegistry) appCodec := std.NewAppCodec(cdc, interfaceRegistry) return appCodec, cdc diff --git a/simapp/cmd/simd/genaccounts.go b/simapp/cmd/simd/genaccounts.go index 0a6015104d..0268b54054 100644 --- a/simapp/cmd/simd/genaccounts.go +++ b/simapp/cmd/simd/genaccounts.go @@ -19,7 +19,7 @@ import ( "github.com/cosmos/cosmos-sdk/server" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" - authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" + "github.com/cosmos/cosmos-sdk/x/auth/types" authvesting "github.com/cosmos/cosmos-sdk/x/auth/vesting" "github.com/cosmos/cosmos-sdk/x/bank" "github.com/cosmos/cosmos-sdk/x/genutil" @@ -85,7 +85,7 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa } // create concrete account type based on input parameters - var genAccount authexported.GenesisAccount + var genAccount types.GenesisAccount balances := bank.Balance{Address: addr, Coins: coins.Sort()} baseAccount := auth.NewBaseAccount(addr, nil, 0, 0) diff --git a/simapp/genesis_account.go b/simapp/genesis_account.go index 1725b6982f..860370057a 100644 --- a/simapp/genesis_account.go +++ b/simapp/genesis_account.go @@ -5,11 +5,10 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" - authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" ) -var _ authexported.GenesisAccount = (*SimGenesisAccount)(nil) +var _ authtypes.GenesisAccount = (*SimGenesisAccount)(nil) // SimGenesisAccount defines a type that implements the GenesisAccount interface // to be used for simulation accounts in the genesis state. diff --git a/simapp/test_helpers.go b/simapp/test_helpers.go index f5e5b523ae..7b17fe7430 100644 --- a/simapp/test_helpers.go +++ b/simapp/test_helpers.go @@ -20,7 +20,6 @@ import ( "github.com/cosmos/cosmos-sdk/simapp/helpers" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" - authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" "github.com/cosmos/cosmos-sdk/x/bank" ) @@ -70,7 +69,7 @@ func Setup(isCheckTx bool) *SimApp { // SetupWithGenesisAccounts initializes a new SimApp with the provided genesis // accounts and possible balances. -func SetupWithGenesisAccounts(genAccs []authexported.GenesisAccount, balances ...bank.Balance) *SimApp { +func SetupWithGenesisAccounts(genAccs []auth.GenesisAccount, balances ...bank.Balance) *SimApp { db := dbm.NewMemDB() app := NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0) diff --git a/std/codec.go b/std/codec.go index d0d2047dff..eeb8f038c9 100644 --- a/std/codec.go +++ b/std/codec.go @@ -5,15 +5,9 @@ import ( "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" - "github.com/cosmos/cosmos-sdk/x/auth" - authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" "github.com/cosmos/cosmos-sdk/x/auth/vesting" ) -var ( - _ auth.Codec = (*Codec)(nil) -) - // Codec defines the application-level codec. This codec contains all the // required module-specific codecs that are to be provided upon initialization. type Codec struct { @@ -30,45 +24,6 @@ func NewAppCodec(amino *codec.Codec, anyUnpacker types.AnyUnpacker) *Codec { return &Codec{Marshaler: codec.NewHybridCodec(amino, anyUnpacker), amino: amino, anyUnpacker: anyUnpacker} } -// MarshalAccount marshals an Account interface. If the given type implements -// the Marshaler interface, it is treated as a Proto-defined message and -// serialized that way. Otherwise, it falls back on the internal Amino codec. -func (c *Codec) MarshalAccount(accI authexported.Account) ([]byte, error) { - acc := &Account{} - if err := acc.SetAccount(accI); err != nil { - return nil, err - } - - return c.Marshaler.MarshalBinaryBare(acc) -} - -// UnmarshalAccount returns an Account interface from raw encoded account bytes -// of a Proto-based Account type. An error is returned upon decoding failure. -func (c *Codec) UnmarshalAccount(bz []byte) (authexported.Account, error) { - acc := &Account{} - if err := c.Marshaler.UnmarshalBinaryBare(bz, acc); err != nil { - return nil, err - } - - return acc.GetAccount(), nil -} - -// MarshalAccountJSON JSON encodes an account object implementing the Account -// interface. -func (c *Codec) MarshalAccountJSON(acc authexported.Account) ([]byte, error) { - return c.Marshaler.MarshalJSON(acc) -} - -// UnmarshalAccountJSON returns an Account from JSON encoded bytes. -func (c *Codec) UnmarshalAccountJSON(bz []byte) (authexported.Account, error) { - acc := &Account{} - if err := c.Marshaler.UnmarshalJSON(bz, acc); err != nil { - return nil, err - } - - return acc.GetAccount(), nil -} - // ---------------------------------------------------------------------------- // necessary types and interfaces registered. This codec is provided to all the // modules the application depends on. @@ -85,3 +40,9 @@ func MakeCodec(bm module.BasicManager) *codec.Codec { return cdc } + +// RegisterInterfaces registers Interfaces from sdk/types and vesting +func RegisterInterfaces(interfaceRegistry types.InterfaceRegistry) { + sdk.RegisterInterfaces(interfaceRegistry) + vesting.RegisterInterfaces(interfaceRegistry) +} diff --git a/std/codec.pb.go b/std/codec.pb.go deleted file mode 100644 index 9c43d734d3..0000000000 --- a/std/codec.pb.go +++ /dev/null @@ -1,772 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: std/codec.proto - -package std - -import ( - fmt "fmt" - github_com_cosmos_cosmos_sdk_x_auth_exported "github.com/cosmos/cosmos-sdk/x/auth/exported" - types "github.com/cosmos/cosmos-sdk/x/auth/types" - types1 "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" - proto "github.com/gogo/protobuf/proto" - _ "github.com/regen-network/cosmos-proto" - io "io" - math "math" - math_bits "math/bits" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package - -// Account defines the application-level Account type. -type Account struct { - // sum defines a list of all acceptable concrete Account implementations. - // - // Types that are valid to be assigned to Sum: - // *Account_BaseAccount - // *Account_ContinuousVestingAccount - // *Account_DelayedVestingAccount - // *Account_PeriodicVestingAccount - // *Account_ModuleAccount - Sum isAccount_Sum `protobuf_oneof:"sum"` -} - -func (m *Account) Reset() { *m = Account{} } -func (m *Account) String() string { return proto.CompactTextString(m) } -func (*Account) ProtoMessage() {} -func (*Account) Descriptor() ([]byte, []int) { - return fileDescriptor_ff851c3a98ef46f7, []int{0} -} -func (m *Account) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *Account) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_Account.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *Account) XXX_Merge(src proto.Message) { - xxx_messageInfo_Account.Merge(m, src) -} -func (m *Account) XXX_Size() int { - return m.Size() -} -func (m *Account) XXX_DiscardUnknown() { - xxx_messageInfo_Account.DiscardUnknown(m) -} - -var xxx_messageInfo_Account proto.InternalMessageInfo - -type isAccount_Sum interface { - isAccount_Sum() - MarshalTo([]byte) (int, error) - Size() int -} - -type Account_BaseAccount struct { - BaseAccount *types.BaseAccount `protobuf:"bytes,1,opt,name=base_account,json=baseAccount,proto3,oneof" json:"base_account,omitempty"` -} -type Account_ContinuousVestingAccount struct { - ContinuousVestingAccount *types1.ContinuousVestingAccount `protobuf:"bytes,2,opt,name=continuous_vesting_account,json=continuousVestingAccount,proto3,oneof" json:"continuous_vesting_account,omitempty"` -} -type Account_DelayedVestingAccount struct { - DelayedVestingAccount *types1.DelayedVestingAccount `protobuf:"bytes,3,opt,name=delayed_vesting_account,json=delayedVestingAccount,proto3,oneof" json:"delayed_vesting_account,omitempty"` -} -type Account_PeriodicVestingAccount struct { - PeriodicVestingAccount *types1.PeriodicVestingAccount `protobuf:"bytes,4,opt,name=periodic_vesting_account,json=periodicVestingAccount,proto3,oneof" json:"periodic_vesting_account,omitempty"` -} -type Account_ModuleAccount struct { - ModuleAccount *types.ModuleAccount `protobuf:"bytes,5,opt,name=module_account,json=moduleAccount,proto3,oneof" json:"module_account,omitempty"` -} - -func (*Account_BaseAccount) isAccount_Sum() {} -func (*Account_ContinuousVestingAccount) isAccount_Sum() {} -func (*Account_DelayedVestingAccount) isAccount_Sum() {} -func (*Account_PeriodicVestingAccount) isAccount_Sum() {} -func (*Account_ModuleAccount) isAccount_Sum() {} - -func (m *Account) GetSum() isAccount_Sum { - if m != nil { - return m.Sum - } - return nil -} - -func (m *Account) GetBaseAccount() *types.BaseAccount { - if x, ok := m.GetSum().(*Account_BaseAccount); ok { - return x.BaseAccount - } - return nil -} - -func (m *Account) GetContinuousVestingAccount() *types1.ContinuousVestingAccount { - if x, ok := m.GetSum().(*Account_ContinuousVestingAccount); ok { - return x.ContinuousVestingAccount - } - return nil -} - -func (m *Account) GetDelayedVestingAccount() *types1.DelayedVestingAccount { - if x, ok := m.GetSum().(*Account_DelayedVestingAccount); ok { - return x.DelayedVestingAccount - } - return nil -} - -func (m *Account) GetPeriodicVestingAccount() *types1.PeriodicVestingAccount { - if x, ok := m.GetSum().(*Account_PeriodicVestingAccount); ok { - return x.PeriodicVestingAccount - } - return nil -} - -func (m *Account) GetModuleAccount() *types.ModuleAccount { - if x, ok := m.GetSum().(*Account_ModuleAccount); ok { - return x.ModuleAccount - } - return nil -} - -// XXX_OneofWrappers is for the internal use of the proto package. -func (*Account) XXX_OneofWrappers() []interface{} { - return []interface{}{ - (*Account_BaseAccount)(nil), - (*Account_ContinuousVestingAccount)(nil), - (*Account_DelayedVestingAccount)(nil), - (*Account_PeriodicVestingAccount)(nil), - (*Account_ModuleAccount)(nil), - } -} - -func init() { - proto.RegisterType((*Account)(nil), "cosmos_sdk.std.v1.Account") -} - -func init() { proto.RegisterFile("std/codec.proto", fileDescriptor_ff851c3a98ef46f7) } - -var fileDescriptor_ff851c3a98ef46f7 = []byte{ - // 379 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x92, 0xcd, 0x4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-} - -func (this *Account) GetAccount() github_com_cosmos_cosmos_sdk_x_auth_exported.Account { - if x := this.GetBaseAccount(); x != nil { - return x - } - if x := this.GetContinuousVestingAccount(); x != nil { - return x - } - if x := this.GetDelayedVestingAccount(); x != nil { - return x - } - if x := this.GetPeriodicVestingAccount(); x != nil { - return x - } - if x := this.GetModuleAccount(); x != nil { - return x - } - return nil -} - -func (this *Account) SetAccount(value github_com_cosmos_cosmos_sdk_x_auth_exported.Account) error { - if value == nil { - this.Sum = nil - return nil - } - switch vt := value.(type) { - case *types.BaseAccount: - this.Sum = &Account_BaseAccount{vt} - return nil - case *types1.ContinuousVestingAccount: - this.Sum = &Account_ContinuousVestingAccount{vt} - return nil - case *types1.DelayedVestingAccount: - this.Sum = &Account_DelayedVestingAccount{vt} - return nil - case *types1.PeriodicVestingAccount: - this.Sum = &Account_PeriodicVestingAccount{vt} - return nil - case *types.ModuleAccount: - this.Sum = &Account_ModuleAccount{vt} - return nil - } - return fmt.Errorf("can't encode value of type %T as message Account", value) -} - -func (m *Account) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Account) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Account) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.Sum != nil { - { - size := m.Sum.Size() - i -= size - if _, err := m.Sum.MarshalTo(dAtA[i:]); err != nil { - return 0, err - } - } - } - return len(dAtA) - i, nil -} - -func (m *Account_BaseAccount) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Account_BaseAccount) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - if m.BaseAccount != nil { - { - size, err := m.BaseAccount.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintCodec(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} -func (m *Account_ContinuousVestingAccount) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Account_ContinuousVestingAccount) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - if m.ContinuousVestingAccount != nil { - { - size, err := m.ContinuousVestingAccount.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintCodec(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - } - return len(dAtA) - i, nil -} -func (m *Account_DelayedVestingAccount) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Account_DelayedVestingAccount) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - if m.DelayedVestingAccount != nil { - { - size, err := m.DelayedVestingAccount.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintCodec(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x1a - } - return len(dAtA) - i, nil -} -func (m *Account_PeriodicVestingAccount) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Account_PeriodicVestingAccount) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - if m.PeriodicVestingAccount != nil { - { - size, err := m.PeriodicVestingAccount.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintCodec(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x22 - } - return len(dAtA) - i, nil -} -func (m *Account_ModuleAccount) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Account_ModuleAccount) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - if m.ModuleAccount != nil { - { - size, err := m.ModuleAccount.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintCodec(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x2a - } - return len(dAtA) - i, nil -} -func encodeVarintCodec(dAtA []byte, offset int, v uint64) int { - offset -= sovCodec(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *Account) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Sum != nil { - n += m.Sum.Size() - } - return n -} - -func (m *Account_BaseAccount) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.BaseAccount != nil { - l = m.BaseAccount.Size() - n += 1 + l + sovCodec(uint64(l)) - } - return n -} -func (m *Account_ContinuousVestingAccount) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.ContinuousVestingAccount != nil { - l = m.ContinuousVestingAccount.Size() - n += 1 + l + sovCodec(uint64(l)) - } - return n -} -func (m *Account_DelayedVestingAccount) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.DelayedVestingAccount != nil { - l = m.DelayedVestingAccount.Size() - n += 1 + l + sovCodec(uint64(l)) - } - return n -} -func (m *Account_PeriodicVestingAccount) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.PeriodicVestingAccount != nil { - l = m.PeriodicVestingAccount.Size() - n += 1 + l + sovCodec(uint64(l)) - } - return n -} -func (m *Account_ModuleAccount) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.ModuleAccount != nil { - l = m.ModuleAccount.Size() - n += 1 + l + sovCodec(uint64(l)) - } - return n -} - -func sovCodec(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozCodec(x uint64) (n int) { - return sovCodec(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *Account) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCodec - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Account: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Account: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field BaseAccount", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCodec - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthCodec - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthCodec - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - v := &types.BaseAccount{} - if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - m.Sum = &Account_BaseAccount{v} - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ContinuousVestingAccount", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCodec - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthCodec - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthCodec - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - v := &types1.ContinuousVestingAccount{} - if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - m.Sum = &Account_ContinuousVestingAccount{v} - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field DelayedVestingAccount", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCodec - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthCodec - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthCodec - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - v := &types1.DelayedVestingAccount{} - if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - m.Sum = &Account_DelayedVestingAccount{v} - iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PeriodicVestingAccount", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCodec - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthCodec - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthCodec - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - v := &types1.PeriodicVestingAccount{} - if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - m.Sum = &Account_PeriodicVestingAccount{v} - iNdEx = postIndex - case 5: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ModuleAccount", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCodec - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthCodec - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthCodec - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - v := &types.ModuleAccount{} - if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - m.Sum = &Account_ModuleAccount{v} - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipCodec(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthCodec - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthCodec - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipCodec(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowCodec - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowCodec - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowCodec - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLengthCodec - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroupCodec - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLengthCodec - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLengthCodec = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowCodec = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupCodec = fmt.Errorf("proto: unexpected end of group") -) diff --git a/std/codec.proto b/std/codec.proto deleted file mode 100644 index 2a232237eb..0000000000 --- a/std/codec.proto +++ /dev/null @@ -1,22 +0,0 @@ -syntax = "proto3"; -package cosmos_sdk.std.v1; - -import "third_party/proto/cosmos-proto/cosmos.proto"; -import "x/auth/types/types.proto"; -import "x/auth/vesting/types/types.proto"; - -option go_package = "github.com/cosmos/cosmos-sdk/std"; - -// Account defines the application-level Account type. -message Account { - option (cosmos_proto.interface_type) = "*github.com/cosmos/cosmos-sdk/x/auth/exported.Account"; - - // sum defines a list of all acceptable concrete Account implementations. - oneof sum { - cosmos_sdk.x.auth.v1.BaseAccount base_account = 1; - cosmos_sdk.x.auth.vesting.v1.ContinuousVestingAccount continuous_vesting_account = 2; - cosmos_sdk.x.auth.vesting.v1.DelayedVestingAccount delayed_vesting_account = 3; - cosmos_sdk.x.auth.vesting.v1.PeriodicVestingAccount periodic_vesting_account = 4; - cosmos_sdk.x.auth.v1.ModuleAccount module_account = 5; - } -} diff --git a/x/auth/alias.go b/x/auth/alias.go index 01392a61d2..5c57f75e77 100644 --- a/x/auth/alias.go +++ b/x/auth/alias.go @@ -78,6 +78,7 @@ var ( ) type ( + AccountI = types.AccountI SignatureVerificationGasConsumer = ante.SignatureVerificationGasConsumer AccountKeeper = keeper.AccountKeeper BaseAccount = types.BaseAccount @@ -93,6 +94,7 @@ type ( StdSignature = types.StdSignature //nolint:staticcheck TxBuilder = types.TxBuilder GenesisAccountIterator = types.GenesisAccountIterator - Codec = types.Codec ModuleAccount = types.ModuleAccount + GenesisAccounts = types.GenesisAccounts + GenesisAccount = types.GenesisAccount ) diff --git a/x/auth/ante/expected_keepers.go b/x/auth/ante/expected_keepers.go index ed93b907b9..d8be4312e5 100644 --- a/x/auth/ante/expected_keepers.go +++ b/x/auth/ante/expected_keepers.go @@ -2,7 +2,6 @@ package ante import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/auth/exported" "github.com/cosmos/cosmos-sdk/x/auth/types" ) @@ -10,7 +9,7 @@ import ( // Interface provides support to use non-sdk AccountKeeper for AnteHandler's decorators. type AccountKeeper interface { GetParams(ctx sdk.Context) (params types.Params) - GetAccount(ctx sdk.Context, addr sdk.AccAddress) exported.Account - SetAccount(ctx sdk.Context, acc exported.Account) + GetAccount(ctx sdk.Context, addr sdk.AccAddress) types.AccountI + SetAccount(ctx sdk.Context, acc types.AccountI) GetModuleAddress(moduleName string) sdk.AccAddress } diff --git a/x/auth/ante/fee.go b/x/auth/ante/fee.go index 5b1044c586..900caf18d5 100644 --- a/x/auth/ante/fee.go +++ b/x/auth/ante/fee.go @@ -5,7 +5,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/x/auth/exported" "github.com/cosmos/cosmos-sdk/x/auth/types" ) @@ -111,7 +110,7 @@ func (dfd DeductFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bo } // DeductFees deducts fees from the given account. -func DeductFees(bankKeeper types.BankKeeper, ctx sdk.Context, acc exported.Account, fees sdk.Coins) error { +func DeductFees(bankKeeper types.BankKeeper, ctx sdk.Context, acc types.AccountI, fees sdk.Coins) error { if !fees.IsValid() { return sdkerrors.Wrapf(sdkerrors.ErrInsufficientFee, "invalid fee amount: %s", fees) } diff --git a/x/auth/ante/sigverify.go b/x/auth/ante/sigverify.go index 93ae0f3b4a..0b17b05bc4 100644 --- a/x/auth/ante/sigverify.go +++ b/x/auth/ante/sigverify.go @@ -12,7 +12,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/x/auth/exported" "github.com/cosmos/cosmos-sdk/x/auth/types" ) @@ -41,7 +40,7 @@ type SigVerifiableTx interface { GetSignatures() [][]byte GetSigners() []sdk.AccAddress GetPubKeys() []crypto.PubKey // If signer already has pubkey in context, this list will have nil in its place - GetSignBytes(ctx sdk.Context, acc exported.Account) []byte + GetSignBytes(ctx sdk.Context, acc types.AccountI) []byte } // SetPubKeyDecorator sets PubKeys in context for any signer which does not already have pubkey set @@ -184,7 +183,7 @@ func (svd SigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simul // stdSigs contains the sequence number, account number, and signatures. // When simulating, this would just be a 0-length slice. signerAddrs := sigTx.GetSigners() - signerAccs := make([]exported.Account, len(signerAddrs)) + signerAccs := make([]types.AccountI, len(signerAddrs)) // check that signer length and signature length are the same if len(sigs) != len(signerAddrs) { @@ -339,7 +338,7 @@ func ConsumeMultisignatureVerificationGas( // GetSignerAcc returns an account for a given address that is expected to sign // a transaction. -func GetSignerAcc(ctx sdk.Context, ak AccountKeeper, addr sdk.AccAddress) (exported.Account, error) { +func GetSignerAcc(ctx sdk.Context, ak AccountKeeper, addr sdk.AccAddress) (types.AccountI, error) { if acc := ak.GetAccount(ctx, addr); acc != nil { return acc, nil } diff --git a/x/auth/client/tx.go b/x/auth/client/tx.go index c06acf7367..90678f32d0 100644 --- a/x/auth/client/tx.go +++ b/x/auth/client/tx.go @@ -29,7 +29,7 @@ import ( // // TODO:/XXX: Using a package-level global isn't ideal and we should consider // refactoring the module manager to allow passing in the correct module codec. -var Codec authtypes.Codec +var Codec codec.Marshaler // GasEstimateResponse defines a response definition for tx gas estimation. type GasEstimateResponse struct { diff --git a/x/auth/exported/exported.go b/x/auth/exported/exported.go deleted file mode 100644 index 1974ff9ae4..0000000000 --- a/x/auth/exported/exported.go +++ /dev/null @@ -1,62 +0,0 @@ -package exported - -import ( - "github.com/tendermint/tendermint/crypto" - - sdk "github.com/cosmos/cosmos-sdk/types" -) - -// Account is an interface used to store coins at a given address within state. -// It presumes a notion of sequence numbers for replay protection, -// a notion of account numbers for replay protection for previously pruned accounts, -// and a pubkey for authentication purposes. -// -// Many complex conditions can be used in the concrete struct which implements Account. -type Account interface { - GetAddress() sdk.AccAddress - SetAddress(sdk.AccAddress) error // errors if already set. - - GetPubKey() crypto.PubKey // can return nil. - SetPubKey(crypto.PubKey) error - - GetAccountNumber() uint64 - SetAccountNumber(uint64) error - - GetSequence() uint64 - SetSequence(uint64) error - - // Ensure that account implements stringer - String() string -} - -// ModuleAccountI defines an account interface for modules that hold tokens in -// an escrow. -type ModuleAccountI interface { - Account - - GetName() string - GetPermissions() []string - HasPermission(string) bool -} - -// GenesisAccounts defines a slice of GenesisAccount objects -type GenesisAccounts []GenesisAccount - -// Contains returns true if the given address exists in a slice of GenesisAccount -// objects. -func (ga GenesisAccounts) Contains(addr sdk.Address) bool { - for _, acc := range ga { - if acc.GetAddress().Equals(addr) { - return true - } - } - - return false -} - -// GenesisAccount defines a genesis account that embeds an Account with validation capabilities. -type GenesisAccount interface { - Account - - Validate() error -} diff --git a/x/auth/exported/exported_test.go b/x/auth/exported/exported_test.go deleted file mode 100644 index 23de4f777e..0000000000 --- a/x/auth/exported/exported_test.go +++ /dev/null @@ -1,24 +0,0 @@ -package exported_test - -import ( - "testing" - - "github.com/stretchr/testify/require" - "github.com/tendermint/tendermint/crypto/secp256k1" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/auth/exported" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" -) - -func TestGenesisAccountsContains(t *testing.T) { - pubkey := secp256k1.GenPrivKey().PubKey() - addr := sdk.AccAddress(pubkey.Address()) - acc := authtypes.NewBaseAccount(addr, secp256k1.GenPrivKey().PubKey(), 0, 0) - - genAccounts := exported.GenesisAccounts{} - require.False(t, genAccounts.Contains(acc.GetAddress())) - - genAccounts = append(genAccounts, acc) - require.True(t, genAccounts.Contains(acc.GetAddress())) -} diff --git a/x/auth/genesis.go b/x/auth/genesis.go index 606e4f410d..93f7688a15 100644 --- a/x/auth/genesis.go +++ b/x/auth/genesis.go @@ -2,7 +2,7 @@ package auth import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/auth/exported" + "github.com/cosmos/cosmos-sdk/x/auth/types" ) // InitGenesis - Init store state from genesis data @@ -25,9 +25,9 @@ func InitGenesis(ctx sdk.Context, ak AccountKeeper, data GenesisState) { func ExportGenesis(ctx sdk.Context, ak AccountKeeper) GenesisState { params := ak.GetParams(ctx) - var genAccounts exported.GenesisAccounts - ak.IterateAccounts(ctx, func(account exported.Account) bool { - genAccount := account.(exported.GenesisAccount) + var genAccounts types.GenesisAccounts + ak.IterateAccounts(ctx, func(account types.AccountI) bool { + genAccount := account.(types.GenesisAccount) genAccounts = append(genAccounts, genAccount) return false }) diff --git a/x/auth/keeper/account.go b/x/auth/keeper/account.go index f2e9292b47..e39c98ac52 100644 --- a/x/auth/keeper/account.go +++ b/x/auth/keeper/account.go @@ -2,12 +2,11 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/auth/exported" "github.com/cosmos/cosmos-sdk/x/auth/types" ) // NewAccountWithAddress implements sdk.AccountKeeper. -func (ak AccountKeeper) NewAccountWithAddress(ctx sdk.Context, addr sdk.AccAddress) exported.Account { +func (ak AccountKeeper) NewAccountWithAddress(ctx sdk.Context, addr sdk.AccAddress) types.AccountI { acc := ak.proto() err := acc.SetAddress(addr) if err != nil { @@ -18,7 +17,7 @@ func (ak AccountKeeper) NewAccountWithAddress(ctx sdk.Context, addr sdk.AccAddre } // NewAccount sets the next account number to a given account interface -func (ak AccountKeeper) NewAccount(ctx sdk.Context, acc exported.Account) exported.Account { +func (ak AccountKeeper) NewAccount(ctx sdk.Context, acc types.AccountI) types.AccountI { if err := acc.SetAccountNumber(ak.GetNextAccountNumber(ctx)); err != nil { panic(err) } @@ -27,7 +26,7 @@ func (ak AccountKeeper) NewAccount(ctx sdk.Context, acc exported.Account) export } // GetAccount implements sdk.AccountKeeper. -func (ak AccountKeeper) GetAccount(ctx sdk.Context, addr sdk.AccAddress) exported.Account { +func (ak AccountKeeper) GetAccount(ctx sdk.Context, addr sdk.AccAddress) types.AccountI { store := ctx.KVStore(ak.key) bz := store.Get(types.AddressStoreKey(addr)) if bz == nil { @@ -38,8 +37,8 @@ func (ak AccountKeeper) GetAccount(ctx sdk.Context, addr sdk.AccAddress) exporte } // GetAllAccounts returns all accounts in the accountKeeper. -func (ak AccountKeeper) GetAllAccounts(ctx sdk.Context) (accounts []exported.Account) { - ak.IterateAccounts(ctx, func(acc exported.Account) (stop bool) { +func (ak AccountKeeper) GetAllAccounts(ctx sdk.Context) (accounts []types.AccountI) { + ak.IterateAccounts(ctx, func(acc types.AccountI) (stop bool) { accounts = append(accounts, acc) return false }) @@ -48,11 +47,11 @@ func (ak AccountKeeper) GetAllAccounts(ctx sdk.Context) (accounts []exported.Acc } // SetAccount implements sdk.AccountKeeper. -func (ak AccountKeeper) SetAccount(ctx sdk.Context, acc exported.Account) { +func (ak AccountKeeper) SetAccount(ctx sdk.Context, acc types.AccountI) { addr := acc.GetAddress() store := ctx.KVStore(ak.key) - bz, err := ak.cdc.MarshalAccount(acc) + bz, err := ak.MarshalAccount(acc) if err != nil { panic(err) } @@ -62,14 +61,14 @@ func (ak AccountKeeper) SetAccount(ctx sdk.Context, acc exported.Account) { // RemoveAccount removes an account for the account mapper store. // NOTE: this will cause supply invariant violation if called -func (ak AccountKeeper) RemoveAccount(ctx sdk.Context, acc exported.Account) { +func (ak AccountKeeper) RemoveAccount(ctx sdk.Context, acc types.AccountI) { addr := acc.GetAddress() store := ctx.KVStore(ak.key) store.Delete(types.AddressStoreKey(addr)) } // IterateAccounts iterates over all the stored accounts and performs a callback function -func (ak AccountKeeper) IterateAccounts(ctx sdk.Context, cb func(account exported.Account) (stop bool)) { +func (ak AccountKeeper) IterateAccounts(ctx sdk.Context, cb func(account types.AccountI) (stop bool)) { store := ctx.KVStore(ak.key) iterator := sdk.KVStorePrefixIterator(store, types.AddressStoreKeyPrefix) diff --git a/x/auth/keeper/keeper.go b/x/auth/keeper/keeper.go index 2db0dec2e4..13018004cc 100644 --- a/x/auth/keeper/keeper.go +++ b/x/auth/keeper/keeper.go @@ -7,9 +7,10 @@ import ( "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/libs/log" + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/x/auth/exported" "github.com/cosmos/cosmos-sdk/x/auth/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" ) @@ -18,18 +19,18 @@ import ( // encoding/decoding library. type AccountKeeper struct { key sdk.StoreKey - cdc types.Codec + cdc codec.Marshaler paramSubspace paramtypes.Subspace permAddrs map[string]types.PermissionsForAddress - // The prototypical Account constructor. - proto func() exported.Account + // The prototypical AccountI constructor. + proto func() types.AccountI } // NewAccountKeeper returns a new sdk.AccountKeeper that uses go-amino to // (binary) encode and decode concrete sdk.Accounts. func NewAccountKeeper( - cdc types.Codec, key sdk.StoreKey, paramstore paramtypes.Subspace, proto func() exported.Account, + cdc codec.Marshaler, key sdk.StoreKey, paramstore paramtypes.Subspace, proto func() types.AccountI, maccPerms map[string][]string, ) AccountKeeper { @@ -106,7 +107,7 @@ func (ak AccountKeeper) GetNextAccountNumber(ctx sdk.Context) uint64 { // ValidatePermissions validates that the module account has been granted // permissions within its set of allowed permissions. -func (ak AccountKeeper) ValidatePermissions(macc exported.ModuleAccountI) error { +func (ak AccountKeeper) ValidatePermissions(macc types.ModuleAccountI) error { permAddr := ak.permAddrs[macc.GetName()] for _, perm := range macc.GetPermissions() { if !permAddr.HasPermission(perm) { @@ -139,7 +140,7 @@ func (ak AccountKeeper) GetModuleAddressAndPermissions(moduleName string) (addr // GetModuleAccountAndPermissions gets the module account from the auth account store and its // registered permissions -func (ak AccountKeeper) GetModuleAccountAndPermissions(ctx sdk.Context, moduleName string) (exported.ModuleAccountI, []string) { +func (ak AccountKeeper) GetModuleAccountAndPermissions(ctx sdk.Context, moduleName string) (types.ModuleAccountI, []string) { addr, perms := ak.GetModuleAddressAndPermissions(moduleName) if addr == nil { return nil, []string{} @@ -147,7 +148,7 @@ func (ak AccountKeeper) GetModuleAccountAndPermissions(ctx sdk.Context, moduleNa acc := ak.GetAccount(ctx, addr) if acc != nil { - macc, ok := acc.(exported.ModuleAccountI) + macc, ok := acc.(types.ModuleAccountI) if !ok { panic("account is not a module account") } @@ -156,7 +157,7 @@ func (ak AccountKeeper) GetModuleAccountAndPermissions(ctx sdk.Context, moduleNa // create a new module account macc := types.NewEmptyModuleAccount(moduleName, perms...) - maccI := (ak.NewAccount(ctx, macc)).(exported.ModuleAccountI) // set the account number + maccI := (ak.NewAccount(ctx, macc)).(types.ModuleAccountI) // set the account number ak.SetModuleAccount(ctx, maccI) return maccI, perms @@ -164,21 +165,57 @@ func (ak AccountKeeper) GetModuleAccountAndPermissions(ctx sdk.Context, moduleNa // GetModuleAccount gets the module account from the auth account store, if the account does not // exist in the AccountKeeper, then it is created. -func (ak AccountKeeper) GetModuleAccount(ctx sdk.Context, moduleName string) exported.ModuleAccountI { +func (ak AccountKeeper) GetModuleAccount(ctx sdk.Context, moduleName string) types.ModuleAccountI { acc, _ := ak.GetModuleAccountAndPermissions(ctx, moduleName) return acc } // SetModuleAccount sets the module account to the auth account store -func (ak AccountKeeper) SetModuleAccount(ctx sdk.Context, macc exported.ModuleAccountI) { //nolint:interfacer +func (ak AccountKeeper) SetModuleAccount(ctx sdk.Context, macc types.ModuleAccountI) { //nolint:interfacer ak.SetAccount(ctx, macc) } -func (ak AccountKeeper) decodeAccount(bz []byte) exported.Account { - acc, err := ak.cdc.UnmarshalAccount(bz) +func (ak AccountKeeper) decodeAccount(bz []byte) types.AccountI { + acc, err := ak.UnmarshalAccount(bz) if err != nil { panic(err) } return acc } + +// MarshalEvidence marshals an Evidence interface. If the given type implements +// the Marshaler interface, it is treated as a Proto-defined message and +// serialized that way. Otherwise, it falls back on the internal Amino codec. +func (ak AccountKeeper) MarshalAccount(accountI types.AccountI) ([]byte, error) { + return codec.MarshalAny(ak.cdc, accountI) +} + +// UnmarshalEvidence returns an Evidence interface from raw encoded evidence +// bytes of a Proto-based Evidence type. An error is returned upon decoding +// failure. +func (ak AccountKeeper) UnmarshalAccount(bz []byte) (types.AccountI, error) { + var acc types.AccountI + if err := codec.UnmarshalAny(ak.cdc, &acc, bz); err != nil { + return nil, err + } + + return acc, nil +} + +// UnmarshalAccountJSON returns an AccountI from JSON encoded bytes +func (ak AccountKeeper) UnmarshalAccountJSON(bz []byte) (types.AccountI, error) { + var any codectypes.Any + if err := ak.cdc.UnmarshalJSON(bz, &any); err != nil { + return nil, err + } + + var acc types.AccountI + if err := ak.cdc.UnpackAny(&any, &acc); err != nil { + return nil, err + } + + return acc, nil +} + +func (ak AccountKeeper) GetCodec() codec.Marshaler { return ak.cdc } diff --git a/x/auth/keeper/querier_test.go b/x/auth/keeper/querier_test.go index 0306965c8a..749c512ecf 100644 --- a/x/auth/keeper/querier_test.go +++ b/x/auth/keeper/querier_test.go @@ -8,7 +8,6 @@ import ( abci "github.com/tendermint/tendermint/abci/types" - "github.com/cosmos/cosmos-sdk/x/auth/exported" keep "github.com/cosmos/cosmos-sdk/x/auth/keeper" "github.com/cosmos/cosmos-sdk/x/auth/types" ) @@ -57,7 +56,7 @@ func TestQueryAccount(t *testing.T) { require.NoError(t, err) require.NotNil(t, res) - var account exported.Account + var account types.AccountI err2 := cdc.UnmarshalJSON(res, &account) require.Nil(t, err2) } diff --git a/x/auth/legacy/v0_38/types.go b/x/auth/legacy/v0_38/types.go index 1502fb27db..ac62694e76 100644 --- a/x/auth/legacy/v0_38/types.go +++ b/x/auth/legacy/v0_38/types.go @@ -524,7 +524,7 @@ func ValidateGenAccounts(genAccounts GenesisAccounts) error { func RegisterCodec(cdc *codec.Codec) { cdc.RegisterInterface((*GenesisAccount)(nil), nil) cdc.RegisterInterface((*Account)(nil), nil) - cdc.RegisterConcrete(&BaseAccount{}, "cosmos-sdk/Account", nil) + cdc.RegisterConcrete(&BaseAccount{}, "cosmos-sdk/BaseAccount", nil) cdc.RegisterConcrete(&BaseVestingAccount{}, "cosmos-sdk/BaseVestingAccount", nil) cdc.RegisterConcrete(&ContinuousVestingAccount{}, "cosmos-sdk/ContinuousVestingAccount", nil) cdc.RegisterConcrete(&DelayedVestingAccount{}, "cosmos-sdk/DelayedVestingAccount", nil) diff --git a/x/auth/legacy/v0_39/migrate_test.go b/x/auth/legacy/v0_39/migrate_test.go index 5f9cee0d25..027db2e896 100644 --- a/x/auth/legacy/v0_39/migrate_test.go +++ b/x/auth/legacy/v0_39/migrate_test.go @@ -51,7 +51,7 @@ func TestMigrate(t *testing.T) { }, "accounts": [ { - "type": "cosmos-sdk/Account", + "type": "cosmos-sdk/BaseAccount", "value": { "address": "cosmos1xxkueklal9vejv9unqu80w9vptyepfa95pd53u", "public_key": "", diff --git a/x/auth/module.go b/x/auth/module.go index 2f425d6459..11875b6356 100644 --- a/x/auth/module.go +++ b/x/auth/module.go @@ -11,55 +11,55 @@ import ( "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/cosmos/cosmos-sdk/x/auth/client/cli" "github.com/cosmos/cosmos-sdk/x/auth/client/rest" "github.com/cosmos/cosmos-sdk/x/auth/simulation" - "github.com/cosmos/cosmos-sdk/x/auth/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" ) var ( _ module.AppModule = AppModule{} _ module.AppModuleBasic = AppModuleBasic{} _ module.AppModuleSimulation = AppModule{} + _ module.InterfaceModule = AppModuleBasic{} ) // AppModuleBasic defines the basic application module used by the auth module. -type AppModuleBasic struct { - cdc Codec -} +type AppModuleBasic struct{} // Name returns the auth module's name. func (AppModuleBasic) Name() string { - return types.ModuleName + return authtypes.ModuleName } // RegisterCodec registers the auth module's types for the given codec. func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) { - types.RegisterCodec(cdc) + authtypes.RegisterCodec(cdc) } // DefaultGenesis returns default genesis state as raw bytes for the auth // module. func (AppModuleBasic) DefaultGenesis(cdc codec.JSONMarshaler) json.RawMessage { - return cdc.MustMarshalJSON(types.DefaultGenesisState()) + return cdc.MustMarshalJSON(authtypes.DefaultGenesisState()) } // ValidateGenesis performs genesis state validation for the auth module. func (AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, bz json.RawMessage) error { - var data types.GenesisState + var data authtypes.GenesisState if err := cdc.UnmarshalJSON(bz, &data); err != nil { - return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) + return fmt.Errorf("failed to unmarshal %s genesis state: %w", authtypes.ModuleName, err) } - return types.ValidateGenesis(data) + return authtypes.ValidateGenesis(data) } // RegisterRESTRoutes registers the REST routes for the auth module. func (AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Router) { - rest.RegisterRoutes(ctx, rtr, types.StoreKey) + rest.RegisterRoutes(ctx, rtr, authtypes.StoreKey) } // GetTxCmd returns the root tx command for the auth module. @@ -72,6 +72,11 @@ func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command { return cli.GetQueryCmd(cdc) } +// RegisterInterfaceTypes registers interfaces and implementations of the auth module. +func (AppModuleBasic) RegisterInterfaceTypes(registry types.InterfaceRegistry) { + authtypes.RegisterInterfaces(registry) +} + //____________________________________________________________________________ // AppModule implements an application module for the auth module. @@ -82,16 +87,16 @@ type AppModule struct { } // NewAppModule creates a new AppModule object -func NewAppModule(cdc Codec, accountKeeper AccountKeeper) AppModule { +func NewAppModule(cdc codec.Marshaler, accountKeeper AccountKeeper) AppModule { return AppModule{ - AppModuleBasic: AppModuleBasic{cdc: cdc}, + AppModuleBasic: AppModuleBasic{}, accountKeeper: accountKeeper, } } // Name returns the auth module's name. func (AppModule) Name() string { - return types.ModuleName + return authtypes.ModuleName } // RegisterInvariants performs a no-op. @@ -105,7 +110,7 @@ func (AppModule) NewHandler() sdk.Handler { return nil } // QuerierRoute returns the auth module's querier route name. func (AppModule) QuerierRoute() string { - return types.QuerierRoute + return authtypes.QuerierRoute } // NewQuerierHandler returns the auth module sdk.Querier. @@ -159,7 +164,7 @@ func (AppModule) RandomizedParams(r *rand.Rand) []simtypes.ParamChange { // RegisterStoreDecoder registers a decoder for auth module's types func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) { - sdr[StoreKey] = simulation.NewDecodeStore(am.cdc) + sdr[StoreKey] = simulation.NewDecodeStore(am.accountKeeper) } // WeightedOperations doesn't return any auth module operation. diff --git a/x/auth/simulation/decoder.go b/x/auth/simulation/decoder.go index e14670a36d..3df011342d 100644 --- a/x/auth/simulation/decoder.go +++ b/x/auth/simulation/decoder.go @@ -7,21 +7,27 @@ import ( gogotypes "github.com/gogo/protobuf/types" tmkv "github.com/tendermint/tendermint/libs/kv" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/x/auth/types" ) +type AuthUnmarshaler interface { + UnmarshalAccount([]byte) (types.AccountI, error) + GetCodec() codec.Marshaler +} + // NewDecodeStore returns a decoder function closure that unmarshals the KVPair's // Value to the corresponding auth type. -func NewDecodeStore(cdc types.Codec) func(kvA, kvB tmkv.Pair) string { +func NewDecodeStore(ak AuthUnmarshaler) func(kvA, kvB tmkv.Pair) string { return func(kvA, kvB tmkv.Pair) string { switch { case bytes.Equal(kvA.Key[:1], types.AddressStoreKeyPrefix): - accA, err := cdc.UnmarshalAccount(kvA.Value) + accA, err := ak.UnmarshalAccount(kvA.Value) if err != nil { panic(err) } - accB, err := cdc.UnmarshalAccount(kvB.Value) + accB, err := ak.UnmarshalAccount(kvB.Value) if err != nil { panic(err) } @@ -30,8 +36,8 @@ func NewDecodeStore(cdc types.Codec) func(kvA, kvB tmkv.Pair) string { case bytes.Equal(kvA.Key, types.GlobalAccountNumberKey): var globalAccNumberA, globalAccNumberB gogotypes.UInt64Value - cdc.MustUnmarshalBinaryBare(kvA.Value, &globalAccNumberA) - cdc.MustUnmarshalBinaryBare(kvB.Value, &globalAccNumberB) + ak.GetCodec().MustUnmarshalBinaryBare(kvA.Value, &globalAccNumberA) + ak.GetCodec().MustUnmarshalBinaryBare(kvB.Value, &globalAccNumberB) return fmt.Sprintf("GlobalAccNumberA: %d\nGlobalAccNumberB: %d", globalAccNumberA, globalAccNumberB) diff --git a/x/auth/simulation/decoder_test.go b/x/auth/simulation/decoder_test.go index 829d0d9c2c..6603d0083c 100644 --- a/x/auth/simulation/decoder_test.go +++ b/x/auth/simulation/decoder_test.go @@ -21,11 +21,12 @@ var ( ) func TestDecodeStore(t *testing.T) { + app := simapp.Setup(false) cdc, _ := simapp.MakeCodecs() acc := types.NewBaseAccountWithAddress(delAddr1) - dec := simulation.NewDecodeStore(cdc) + dec := simulation.NewDecodeStore(app.AccountKeeper) - accBz, err := cdc.MarshalAccount(acc) + accBz, err := app.AccountKeeper.MarshalAccount(acc) require.NoError(t, err) globalAccNumber := gogotypes.UInt64Value{Value: 10} diff --git a/x/auth/simulation/genesis.go b/x/auth/simulation/genesis.go index 5309baf349..b35f43f310 100644 --- a/x/auth/simulation/genesis.go +++ b/x/auth/simulation/genesis.go @@ -10,7 +10,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/types/simulation" - "github.com/cosmos/cosmos-sdk/x/auth/exported" "github.com/cosmos/cosmos-sdk/x/auth/types" vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" ) @@ -95,10 +94,10 @@ func RandomizedGenState(simState *module.SimulationState) { } // RandomGenesisAccounts returns randomly generated genesis accounts -func RandomGenesisAccounts(simState *module.SimulationState) (genesisAccs exported.GenesisAccounts) { +func RandomGenesisAccounts(simState *module.SimulationState) (genesisAccs types.GenesisAccounts) { for i, acc := range simState.Accounts { bacc := types.NewBaseAccountWithAddress(acc.Address) - var gacc exported.GenesisAccount = bacc + var gacc types.GenesisAccount = bacc // Only consider making a vesting account once the initial bonded validator // set is exhausted due to needing to track DelegatedVesting. diff --git a/x/auth/types/account.go b/x/auth/types/account.go index a01d622fb2..1e85ac8f20 100644 --- a/x/auth/types/account.go +++ b/x/auth/types/account.go @@ -11,14 +11,13 @@ import ( yaml "gopkg.in/yaml.v2" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/auth/exported" ) var ( - _ exported.Account = (*BaseAccount)(nil) - _ exported.GenesisAccount = (*BaseAccount)(nil) - _ exported.GenesisAccount = (*ModuleAccount)(nil) - _ exported.ModuleAccountI = (*ModuleAccount)(nil) + _ AccountI = (*BaseAccount)(nil) + _ GenesisAccount = (*BaseAccount)(nil) + _ GenesisAccount = (*ModuleAccount)(nil) + _ ModuleAccountI = (*ModuleAccount)(nil) ) // NewBaseAccount creates a new BaseAccount object @@ -35,7 +34,7 @@ func NewBaseAccount(address sdk.AccAddress, pubKey crypto.PubKey, accountNumber, } // ProtoBaseAccount - a prototype function for BaseAccount -func ProtoBaseAccount() exported.Account { +func ProtoBaseAccount() AccountI { return &BaseAccount{} } @@ -46,12 +45,12 @@ func NewBaseAccountWithAddress(addr sdk.AccAddress) *BaseAccount { } } -// GetAddress - Implements sdk.Account. +// GetAddress - Implements sdk.AccountI. func (acc BaseAccount) GetAddress() sdk.AccAddress { return acc.Address } -// SetAddress - Implements sdk.Account. +// SetAddress - Implements sdk.AccountI. func (acc *BaseAccount) SetAddress(addr sdk.AccAddress) error { if len(acc.Address) != 0 { return errors.New("cannot override BaseAccount address") @@ -61,7 +60,7 @@ func (acc *BaseAccount) SetAddress(addr sdk.AccAddress) error { return nil } -// GetPubKey - Implements sdk.Account. +// GetPubKey - Implements sdk.AccountI. func (acc BaseAccount) GetPubKey() (pk crypto.PubKey) { if len(acc.PubKey) == 0 { return nil @@ -71,7 +70,7 @@ func (acc BaseAccount) GetPubKey() (pk crypto.PubKey) { return pk } -// SetPubKey - Implements sdk.Account. +// SetPubKey - Implements sdk.AccountI. func (acc *BaseAccount) SetPubKey(pubKey crypto.PubKey) error { if pubKey == nil { acc.PubKey = nil @@ -82,23 +81,23 @@ func (acc *BaseAccount) SetPubKey(pubKey crypto.PubKey) error { return nil } -// GetAccountNumber - Implements Account +// GetAccountNumber - Implements AccountI func (acc BaseAccount) GetAccountNumber() uint64 { return acc.AccountNumber } -// SetAccountNumber - Implements Account +// SetAccountNumber - Implements AccountI func (acc *BaseAccount) SetAccountNumber(accNumber uint64) error { acc.AccountNumber = accNumber return nil } -// GetSequence - Implements sdk.Account. +// GetSequence - Implements sdk.AccountI. func (acc BaseAccount) GetSequence() uint64 { return acc.Sequence } -// SetSequence - Implements sdk.Account. +// SetSequence - Implements sdk.AccountI. func (acc *BaseAccount) SetSequence(seq uint64) error { acc.Sequence = seq return nil @@ -205,12 +204,12 @@ func (ma ModuleAccount) GetPermissions() []string { return ma.Permissions } -// SetPubKey - Implements Account +// SetPubKey - Implements AccountI func (ma ModuleAccount) SetPubKey(pubKey crypto.PubKey) error { return fmt.Errorf("not supported for module accounts") } -// SetSequence - Implements Account +// SetSequence - Implements AccountI func (ma ModuleAccount) SetSequence(seq uint64) error { return fmt.Errorf("not supported for module accounts") } @@ -285,3 +284,58 @@ func (ma *ModuleAccount) UnmarshalJSON(bz []byte) error { return nil } + +// AccountI is an interface used to store coins at a given address within state. +// It presumes a notion of sequence numbers for replay protection, +// a notion of account numbers for replay protection for previously pruned accounts, +// and a pubkey for authentication purposes. +// +// Many complex conditions can be used in the concrete struct which implements AccountI. +type AccountI interface { + GetAddress() sdk.AccAddress + SetAddress(sdk.AccAddress) error // errors if already set. + + GetPubKey() crypto.PubKey // can return nil. + SetPubKey(crypto.PubKey) error + + GetAccountNumber() uint64 + SetAccountNumber(uint64) error + + GetSequence() uint64 + SetSequence(uint64) error + + // Ensure that account implements stringer + String() string +} + +// ModuleAccountI defines an account interface for modules that hold tokens in +// an escrow. +type ModuleAccountI interface { + AccountI + + GetName() string + GetPermissions() []string + HasPermission(string) bool +} + +// GenesisAccounts defines a slice of GenesisAccount objects +type GenesisAccounts []GenesisAccount + +// Contains returns true if the given address exists in a slice of GenesisAccount +// objects. +func (ga GenesisAccounts) Contains(addr sdk.Address) bool { + for _, acc := range ga { + if acc.GetAddress().Equals(addr) { + return true + } + } + + return false +} + +// GenesisAccount defines a genesis account that embeds an AccountI with validation capabilities. +type GenesisAccount interface { + AccountI + + Validate() error +} diff --git a/x/auth/types/account_retriever.go b/x/auth/types/account_retriever.go index bc24b4a9c4..88f15ebc24 100644 --- a/x/auth/types/account_retriever.go +++ b/x/auth/types/account_retriever.go @@ -3,8 +3,8 @@ package types import ( "fmt" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/auth/exported" ) // NodeQuerier is an interface that is satisfied by types that provide the QueryWithData method @@ -18,18 +18,18 @@ type NodeQuerier interface { // AccountRetriever defines the properties of a type that can be used to // retrieve accounts. type AccountRetriever struct { - codec Codec + codec codec.Marshaler querier NodeQuerier } // NewAccountRetriever initialises a new AccountRetriever instance. -func NewAccountRetriever(codec Codec, querier NodeQuerier) AccountRetriever { +func NewAccountRetriever(codec codec.Marshaler, querier NodeQuerier) AccountRetriever { return AccountRetriever{codec: codec, querier: querier} } // GetAccount queries for an account given an address and a block height. An // error is returned if the query or decoding fails. -func (ar AccountRetriever) GetAccount(addr sdk.AccAddress) (exported.Account, error) { +func (ar AccountRetriever) GetAccount(addr sdk.AccAddress) (AccountI, error) { account, _, err := ar.GetAccountWithHeight(addr) return account, err } @@ -37,7 +37,7 @@ func (ar AccountRetriever) GetAccount(addr sdk.AccAddress) (exported.Account, er // GetAccountWithHeight queries for an account given an address. Returns the // height of the query with the account. An error is returned if the query // or decoding fails. -func (ar AccountRetriever) GetAccountWithHeight(addr sdk.AccAddress) (exported.Account, int64, error) { +func (ar AccountRetriever) GetAccountWithHeight(addr sdk.AccAddress) (AccountI, int64, error) { bs, err := ar.codec.MarshalJSON(NewQueryAccountParams(addr)) if err != nil { return nil, 0, err @@ -48,7 +48,7 @@ func (ar AccountRetriever) GetAccountWithHeight(addr sdk.AccAddress) (exported.A return nil, height, err } - var account exported.Account + var account AccountI if err := ar.codec.UnmarshalJSON(bz, &account); err != nil { return nil, height, err } diff --git a/x/auth/types/account_test.go b/x/auth/types/account_test.go index 9e156c49da..69a3d2e918 100644 --- a/x/auth/types/account_test.go +++ b/x/auth/types/account_test.go @@ -11,7 +11,6 @@ import ( yaml "gopkg.in/yaml.v2" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/auth/exported" "github.com/cosmos/cosmos-sdk/x/auth/types" ) @@ -69,15 +68,15 @@ func TestBaseAccountMarshal(t *testing.T) { err = acc.SetSequence(seq) require.Nil(t, err) - bz, err := appCodec.MarshalAccount(acc) + bz, err := app.AccountKeeper.MarshalAccount(acc) require.Nil(t, err) - acc2, err := appCodec.UnmarshalAccount(bz) + acc2, err := app.AccountKeeper.UnmarshalAccount(bz) require.Nil(t, err) require.Equal(t, acc, acc2) // error on bad bytes - _, err = appCodec.UnmarshalAccount(bz[:len(bz)/2]) + _, err = app.AccountKeeper.UnmarshalAccount(bz[:len(bz)/2]) require.NotNil(t, err) } @@ -88,7 +87,7 @@ func TestGenesisAccountValidate(t *testing.T) { tests := []struct { name string - acc exported.GenesisAccount + acc types.GenesisAccount expErr bool }{ { @@ -150,7 +149,7 @@ func TestValidate(t *testing.T) { baseAcc := types.NewBaseAccount(addr, nil, 0, 0) tests := []struct { name string - acc exported.GenesisAccount + acc types.GenesisAccount expErr error }{ { @@ -195,3 +194,15 @@ func TestModuleAccountJSON(t *testing.T) { require.NoError(t, json.Unmarshal(bz, &a)) require.Equal(t, acc.String(), a.String()) } + +func TestGenesisAccountsContains(t *testing.T) { + pubkey := secp256k1.GenPrivKey().PubKey() + addr := sdk.AccAddress(pubkey.Address()) + acc := types.NewBaseAccount(addr, secp256k1.GenPrivKey().PubKey(), 0, 0) + + genAccounts := types.GenesisAccounts{} + require.False(t, genAccounts.Contains(acc.GetAddress())) + + genAccounts = append(genAccounts, acc) + require.True(t, genAccounts.Contains(acc.GetAddress())) +} diff --git a/x/auth/types/codec.go b/x/auth/types/codec.go index c4609d8a40..071ef32495 100644 --- a/x/auth/types/codec.go +++ b/x/auth/types/codec.go @@ -2,32 +2,31 @@ package types import ( "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/x/auth/exported" + "github.com/cosmos/cosmos-sdk/codec/types" ) -// Codec defines the interface needed to serialize x/auth state. It must be -// aware of all concrete account types. -type Codec interface { - codec.Marshaler - - MarshalAccount(acc exported.Account) ([]byte, error) - UnmarshalAccount(bz []byte) (exported.Account, error) - - MarshalAccountJSON(acc exported.Account) ([]byte, error) - UnmarshalAccountJSON(bz []byte) (exported.Account, error) -} - // RegisterCodec registers the account interfaces and concrete types on the // provided Amino codec. func RegisterCodec(cdc *codec.Codec) { - cdc.RegisterInterface((*exported.ModuleAccountI)(nil), nil) - cdc.RegisterInterface((*exported.GenesisAccount)(nil), nil) - cdc.RegisterInterface((*exported.Account)(nil), nil) - cdc.RegisterConcrete(&BaseAccount{}, "cosmos-sdk/Account", nil) + cdc.RegisterInterface((*ModuleAccountI)(nil), nil) + cdc.RegisterInterface((*GenesisAccount)(nil), nil) + cdc.RegisterInterface((*AccountI)(nil), nil) + cdc.RegisterConcrete(&BaseAccount{}, "cosmos-sdk/BaseAccount", nil) cdc.RegisterConcrete(&ModuleAccount{}, "cosmos-sdk/ModuleAccount", nil) cdc.RegisterConcrete(StdTx{}, "cosmos-sdk/StdTx", nil) } +// RegisterInterface associates protoName with AccountI interface +// and creates a registry of it's concrete implementations +func RegisterInterfaces(registry types.InterfaceRegistry) { + registry.RegisterInterface( + "cosmos_sdk.auth.v1.AccountI", + (*AccountI)(nil), + &BaseAccount{}, + &ModuleAccount{}, + ) +} + // RegisterKeyTypeCodec registers an external concrete type defined in // another module for the internal ModuleCdc. func RegisterKeyTypeCodec(o interface{}, name string) { @@ -36,6 +35,8 @@ func RegisterKeyTypeCodec(o interface{}, name string) { var ( amino = codec.New() + + ModuleCdc = codec.NewHybridCodec(amino, types.NewInterfaceRegistry()) ) func init() { diff --git a/x/auth/types/genesis.go b/x/auth/types/genesis.go index 394d83ad8e..6e6631e1e8 100644 --- a/x/auth/types/genesis.go +++ b/x/auth/types/genesis.go @@ -5,17 +5,17 @@ import ( "fmt" "sort" - "github.com/cosmos/cosmos-sdk/x/auth/exported" + "github.com/cosmos/cosmos-sdk/codec" ) // GenesisState - all auth state that must be provided at genesis type GenesisState struct { - Params Params `json:"params" yaml:"params"` - Accounts exported.GenesisAccounts `json:"accounts" yaml:"accounts"` + Params Params `json:"params" yaml:"params"` + Accounts GenesisAccounts `json:"accounts" yaml:"accounts"` } // NewGenesisState - Create a new genesis state -func NewGenesisState(params Params, accounts exported.GenesisAccounts) GenesisState { +func NewGenesisState(params Params, accounts GenesisAccounts) GenesisState { return GenesisState{ Params: params, Accounts: accounts, @@ -24,12 +24,12 @@ func NewGenesisState(params Params, accounts exported.GenesisAccounts) GenesisSt // DefaultGenesisState - Return a default genesis state func DefaultGenesisState() GenesisState { - return NewGenesisState(DefaultParams(), exported.GenesisAccounts{}) + return NewGenesisState(DefaultParams(), GenesisAccounts{}) } // GetGenesisStateFromAppState returns x/auth GenesisState given raw application // genesis state. -func GetGenesisStateFromAppState(cdc Codec, appState map[string]json.RawMessage) GenesisState { +func GetGenesisStateFromAppState(cdc codec.Marshaler, appState map[string]json.RawMessage) GenesisState { var genesisState GenesisState if appState[ModuleName] != nil { @@ -50,7 +50,7 @@ func ValidateGenesis(data GenesisState) error { } // SanitizeGenesisAccounts sorts accounts and coin sets. -func SanitizeGenesisAccounts(genAccs exported.GenesisAccounts) exported.GenesisAccounts { +func SanitizeGenesisAccounts(genAccs GenesisAccounts) GenesisAccounts { sort.Slice(genAccs, func(i, j int) bool { return genAccs[i].GetAccountNumber() < genAccs[j].GetAccountNumber() }) @@ -59,7 +59,7 @@ func SanitizeGenesisAccounts(genAccs exported.GenesisAccounts) exported.GenesisA } // ValidateGenAccounts validates an array of GenesisAccounts and checks for duplicates -func ValidateGenAccounts(accounts exported.GenesisAccounts) error { +func ValidateGenAccounts(accounts GenesisAccounts) error { addrMap := make(map[string]bool, len(accounts)) for _, acc := range accounts { @@ -86,7 +86,7 @@ type GenesisAccountIterator struct{} // appGenesis and invokes a callback on each genesis account. If any call // returns true, iteration stops. func (GenesisAccountIterator) IterateGenesisAccounts( - cdc Codec, appGenesis map[string]json.RawMessage, cb func(exported.Account) (stop bool), + cdc codec.Marshaler, appGenesis map[string]json.RawMessage, cb func(AccountI) (stop bool), ) { for _, genAcc := range GetGenesisStateFromAppState(cdc, appGenesis).Accounts { if cb(genAcc) { diff --git a/x/auth/types/genesis_test.go b/x/auth/types/genesis_test.go index f0733a2af2..d424678574 100644 --- a/x/auth/types/genesis_test.go +++ b/x/auth/types/genesis_test.go @@ -8,7 +8,6 @@ import ( "github.com/tendermint/tendermint/crypto/ed25519" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/auth/exported" "github.com/cosmos/cosmos-sdk/x/auth/types" ) @@ -21,7 +20,7 @@ func TestSanitize(t *testing.T) { addr2 := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address()) authAcc2 := types.NewBaseAccountWithAddress(addr2) - genAccs := exported.GenesisAccounts{authAcc1, authAcc2} + genAccs := types.GenesisAccounts{authAcc1, authAcc2} require.True(t, genAccs[0].GetAccountNumber() > genAccs[1].GetAccountNumber()) require.Equal(t, genAccs[1].GetAddress(), addr2) @@ -42,7 +41,7 @@ var ( func TestValidateGenesisDuplicateAccounts(t *testing.T) { acc1 := types.NewBaseAccountWithAddress(sdk.AccAddress(addr1)) - genAccs := make(exported.GenesisAccounts, 2) + genAccs := make(types.GenesisAccounts, 2) genAccs[0] = acc1 genAccs[1] = acc1 @@ -53,7 +52,7 @@ func TestGenesisAccountIterator(t *testing.T) { acc1 := types.NewBaseAccountWithAddress(sdk.AccAddress(addr1)) acc2 := types.NewBaseAccountWithAddress(sdk.AccAddress(addr2)) - genAccounts := exported.GenesisAccounts{acc1, acc2} + genAccounts := types.GenesisAccounts{acc1, acc2} authGenState := types.DefaultGenesisState() authGenState.Accounts = genAccounts @@ -66,7 +65,7 @@ func TestGenesisAccountIterator(t *testing.T) { var addresses []sdk.AccAddress types.GenesisAccountIterator{}.IterateGenesisAccounts( - appCodec, appGenesis, func(acc exported.Account) (stop bool) { + appCodec, appGenesis, func(acc types.AccountI) (stop bool) { addresses = append(addresses, acc.GetAddress()) return false }, diff --git a/x/auth/types/stdtx.go b/x/auth/types/stdtx.go index 3f5eb1e410..e18d69579f 100644 --- a/x/auth/types/stdtx.go +++ b/x/auth/types/stdtx.go @@ -12,7 +12,6 @@ import ( codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/x/auth/exported" ) // MaxGasWanted defines the max gas allowed. @@ -246,7 +245,7 @@ func (tx StdTx) GetPubKeys() []crypto.PubKey { } // GetSignBytes returns the signBytes of the tx for a given signer -func (tx StdTx) GetSignBytes(ctx sdk.Context, acc exported.Account) []byte { +func (tx StdTx) GetSignBytes(ctx sdk.Context, acc AccountI) []byte { genesis := ctx.BlockHeight() == 0 chainID := ctx.ChainID() var accNum uint64 diff --git a/x/auth/types/types.pb.go b/x/auth/types/types.pb.go index ad102a4ce8..e90c4f1bf6 100644 --- a/x/auth/types/types.pb.go +++ b/x/auth/types/types.pb.go @@ -8,6 +8,7 @@ import ( github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" + _ "github.com/regen-network/cosmos-proto" io "io" math "math" math_bits "math/bits" @@ -190,47 +191,49 @@ func init() { func init() { proto.RegisterFile("x/auth/types/types.proto", fileDescriptor_2d526fa662daab74) } var fileDescriptor_2d526fa662daab74 = []byte{ - // 640 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x54, 0xbf, 0x6f, 0xd3, 0x40, - 0x14, 0x8e, 0x9b, 0xd0, 0x1f, 0x97, 0x16, 0xa9, 0x6e, 0xda, 0xba, 0x05, 0xf9, 0x82, 0x07, 0x54, - 0x24, 0xea, 0x28, 0x45, 0x45, 0x6a, 0x06, 0x44, 0x5d, 0x60, 0x29, 0xad, 0xaa, 0xab, 0xc4, 0xc0, - 0x62, 0x9d, 0xed, 0x23, 0xb1, 0x92, 0xcb, 0xb9, 0xbe, 0x73, 0x15, 0xf7, 0x2f, 0x40, 0x4c, 0x8c, - 0x8c, 0xfd, 0x1b, 0xf8, 0x2b, 0x18, 0x3b, 0x32, 0x19, 0x94, 0x2e, 0x88, 0xd1, 0x23, 0x13, 0xb2, - 0x2f, 0x4d, 0x9d, 0x2a, 0xb0, 0xd8, 0xf7, 0xde, 0xfb, 0xbe, 0xef, 0x3d, 0x7f, 0x4f, 0x67, 0xa0, - 0x0d, 0x1a, 0x38, 0x12, 0x9d, 0x86, 0x88, 0x03, 0xc2, 0xe5, 0xd3, 0x0c, 0x42, 0x26, 0x98, 0x5a, - 0x73, 0x19, 0xa7, 0x8c, 0xdb, 0xdc, 0xeb, 0x9a,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 0x25, 0xe3, - 0xab, 0x02, 0x96, 0x8e, 0x98, 0x17, 0xf5, 0xc6, 0x76, 0x60, 0xb0, 0xe8, 0x60, 0x4e, 0xec, 0x91, - 0x5a, 0xee, 0x49, 0x75, 0xe7, 0x91, 0x39, 0xcd, 0x73, 0xb3, 0xe0, 0xa3, 0xf5, 0xe0, 0x2a, 0x81, - 0x4a, 0x9a, 0xc0, 0x15, 0x39, 0x5e, 0x51, 0xc4, 0x40, 0x55, 0xa7, 0xe0, 0xb8, 0x0a, 0x2a, 0x7d, - 0x4c, 0x49, 0xee, 0xd0, 0x02, 0xca, 0xcf, 0x6a, 0x1d, 0x54, 0x03, 0x12, 0x52, 0x9f, 0x73, 0x9f, - 0xf5, 0xb9, 0x56, 0xae, 0x97, 0xb7, 0x16, 0x50, 0x31, 0x55, 0x18, 0xfa, 0x47, 0x19, 0xcc, 0x9e, - 0xe0, 0x10, 0x53, 0xae, 0x1e, 0x83, 0x15, 0x8a, 0x07, 0x36, 0x25, 0x94, 0xd9, 0x6e, 0x07, 0x87, - 0xd8, 0x15, 0x24, 0x94, 0x8b, 0xac, 0x58, 0x7a, 0x9a, 0xc0, 0x4d, 0x39, 0xcd, 0x14, 0x90, 0x81, - 0x96, 0x29, 0x1e, 0x1c, 0x11, 0xca, 0x0e, 0xc6, 0x39, 0x75, 0x0f, 0x2c, 0x8a, 0x81, 0xcd, 0xfd, - 0xb6, 0xdd, 0xf3, 0xa9, 0x2f, 0xf2, 0x11, 0x2b, 0xd6, 0xfa, 0xed, 0x67, 0x15, 0xab, 0x06, 0x02, - 0x62, 0x70, 0xea, 0xb7, 0xdf, 0x66, 0x81, 0x8a, 0xc0, 0x6a, 0x5e, 0xbc, 0x20, 0xb6, 0xcb, 0xb8, - 0xb0, 0x03, 0x12, 0xda, 0x4e, 0x2c, 0xc8, 0x68, 0x73, 0xf5, 0x34, 0x81, 0x0f, 0x0b, 0x1a, 0x77, - 0x61, 0x06, 0x5a, 0xce, 0xc4, 0x2e, 0xc8, 0x01, 0xe3, 0xe2, 0x84, 0x84, 0x56, 0x2c, 0x88, 0x7a, - 0x06, 0xd6, 0xb3, 0x6e, 0xe7, 0x24, 0xf4, 0x3f, 0xc4, 0x12, 0x4f, 0xbc, 0x9d, 0xdd, 0xdd, 0xe6, - 0x9e, 0xdc, 0xa9, 0xd5, 0x1a, 0x26, 0xb0, 0x76, 0xea, 0xb7, 0xdf, 0xe5, 0x88, 0x8c, 0xfa, 0xfa, - 0x55, 0x5e, 0x4f, 0x13, 0xa8, 0xcb, 0x6e, 0xff, 0x10, 0x30, 0x50, 0x8d, 0x4f, 0xf0, 0x64, 0x5a, - 0x8d, 0xc1, 0xc6, 0x5d, 0x06, 0x27, 0x6e, 0xb0, 0xb3, 0xfb, 0xbc, 0xdb, 0xd4, 0xee, 0xe5, 0x4d, - 0x5f, 0x0c, 0x13, 0xb8, 0x36, 0xd1, 0xf4, 0xf4, 0x06, 0x91, 0x26, 0xb0, 0x3e, 0xbd, 0xed, 0x58, - 0xc4, 0x40, 0x6b, 0x7c, 0x2a, 0xb7, 0x35, 0x9f, 0x6d, 0xf7, 0xd7, 0x25, 0x54, 0xac, 0x83, 0x6f, - 0x43, 0x5d, 0xb9, 0x1a, 0xea, 0xca, 0xcf, 0xa1, 0xae, 0x7c, 0xbe, 0xd6, 0x4b, 0x57, 0xd7, 0x7a, - 0xe9, 0xfb, 0xb5, 0x5e, 0x7a, 0xff, 0xe4, 0xbf, 0x17, 0xb3, 0xf8, 0xcb, 0x70, 0x66, 0xf3, 0xfb, - 0xfe, 0xec, 0x6f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xc6, 0x00, 0xf0, 0x01, 0x49, 0x04, 0x00, 0x00, + // 668 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x54, 0x4f, 0x4f, 0xdb, 0x48, + 0x14, 0x8f, 0x49, 0x96, 0x3f, 0x13, 0x40,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1, 0x13, 0x69, 0x39, 0x02, 0x9b, 0x77, + 0x19, 0x0c, 0x3b, 0xfe, 0xf6, 0xce, 0xc3, 0x6e, 0x53, 0xf9, 0x2b, 0x33, 0x7d, 0x34, 0x8c, 0xe1, + 0xfa, 0x84, 0xe9, 0xe9, 0x0d, 0x22, 0x89, 0x61, 0x6d, 0xba, 0xed, 0x58, 0x44, 0x33, 0xd7, 0xd9, + 0x54, 0x6e, 0x6b, 0x3e, 0xdd, 0xf7, 0xb7, 0x4b, 0x28, 0x19, 0xfb, 0x1f, 0x87, 0xaa, 0x74, 0x35, + 0x54, 0xa5, 0xaf, 0x43, 0x55, 0x7a, 0x73, 0xad, 0x16, 0xae, 0xae, 0xd5, 0xc2, 0xe7, 0x6b, 0xb5, + 0xf0, 0xf2, 0xff, 0x3f, 0xfe, 0xb6, 0xf9, 0xd7, 0xc7, 0x9e, 0xcd, 0x5e, 0x83, 0x07, 0x3f, 0x03, + 0x00, 0x00, 0xff, 0xff, 0x11, 0xf8, 0x99, 0x15, 0x94, 0x04, 0x00, 0x00, } func (this *Params) Equal(that interface{}) bool { diff --git a/x/auth/types/types.proto b/x/auth/types/types.proto index 49185dbb16..f59bd907b4 100644 --- a/x/auth/types/types.proto +++ b/x/auth/types/types.proto @@ -1,6 +1,7 @@ syntax = "proto3"; package cosmos_sdk.x.auth.v1; +import "third_party/proto/cosmos-proto/cosmos.proto"; import "third_party/proto/gogoproto/gogo.proto"; option go_package = "github.com/cosmos/cosmos-sdk/x/auth/types"; @@ -11,6 +12,7 @@ option go_package = "github.com/cosmos/cosmos-sdk/x/auth/types"; message BaseAccount { option (gogoproto.goproto_getters) = false; option (gogoproto.goproto_stringer) = false; + option (cosmos_proto.implements_interface) = "AccountI"; bytes address = 1 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"]; bytes pub_key = 2 [(gogoproto.jsontag) = "public_key,omitempty", (gogoproto.moretags) = "yaml:\"public_key\""]; @@ -22,6 +24,7 @@ message BaseAccount { message ModuleAccount { option (gogoproto.goproto_getters) = false; option (gogoproto.goproto_stringer) = false; + option (cosmos_proto.implements_interface) = "ModuleAccountI"; BaseAccount base_account = 1 [(gogoproto.embed) = true, (gogoproto.moretags) = "yaml:\"base_account\""]; string name = 2; diff --git a/x/auth/vesting/alias.go b/x/auth/vesting/alias.go index 9591aa12a0..256f61265b 100644 --- a/x/auth/vesting/alias.go +++ b/x/auth/vesting/alias.go @@ -9,6 +9,7 @@ import ( var ( RegisterCodec = types.RegisterCodec + RegisterInterfaces = types.RegisterInterfaces NewBaseVestingAccount = types.NewBaseVestingAccount NewContinuousVestingAccountRaw = types.NewContinuousVestingAccountRaw NewContinuousVestingAccount = types.NewContinuousVestingAccount diff --git a/x/auth/vesting/exported/exported.go b/x/auth/vesting/exported/exported.go index 09caaec4a4..f47d24ae9e 100644 --- a/x/auth/vesting/exported/exported.go +++ b/x/auth/vesting/exported/exported.go @@ -3,13 +3,14 @@ package exported import ( "time" + "github.com/cosmos/cosmos-sdk/x/auth/types" + sdk "github.com/cosmos/cosmos-sdk/types" - authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" ) // VestingAccount defines an account type that vests coins via a vesting schedule. type VestingAccount interface { - authexported.Account + types.AccountI // LockedCoins returns the set of coins that are not spendable (i.e. locked). // diff --git a/x/auth/vesting/types/codec.go b/x/auth/vesting/types/codec.go index c0b938e2e1..ac94ba2b67 100644 --- a/x/auth/vesting/types/codec.go +++ b/x/auth/vesting/types/codec.go @@ -2,6 +2,8 @@ package types import ( "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/auth/vesting/exported" ) @@ -14,3 +16,28 @@ func RegisterCodec(cdc *codec.Codec) { cdc.RegisterConcrete(&DelayedVestingAccount{}, "cosmos-sdk/DelayedVestingAccount", nil) cdc.RegisterConcrete(&PeriodicVestingAccount{}, "cosmos-sdk/PeriodicVestingAccount", nil) } + +// RegisterInterface associates protoName with AccountI and VestingAccount +// Interfaces and creates a registry of it's concrete implementations +func RegisterInterfaces(registry types.InterfaceRegistry) { + registry.RegisterInterface( + "cosmos_sdk.auth.vesting.v1.VestingAccount", + (*exported.VestingAccount)(nil), + &ContinuousVestingAccount{}, + &DelayedVestingAccount{}, + &PeriodicVestingAccount{}, + ) + registry.RegisterImplementations( + (*authtypes.AccountI)(nil), + &DelayedVestingAccount{}, + &ContinuousVestingAccount{}, + &PeriodicVestingAccount{}, + ) +} + +var amino = codec.New() + +func init() { + RegisterCodec(amino) + amino.Seal() +} diff --git a/x/auth/vesting/types/genesis_test.go b/x/auth/vesting/types/genesis_test.go index fb3fea0a2f..79913adf7d 100644 --- a/x/auth/vesting/types/genesis_test.go +++ b/x/auth/vesting/types/genesis_test.go @@ -7,7 +7,6 @@ import ( "github.com/tendermint/tendermint/crypto/ed25519" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/auth/exported" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" ) @@ -30,7 +29,7 @@ func TestValidateGenesisInvalidAccounts(t *testing.T) { acc2 := authtypes.NewBaseAccountWithAddress(sdk.AccAddress(addr2)) // acc2Balance := sdk.NewCoins(sdk.NewInt64Coin(sdk.DefaultBondDenom, 150)) - genAccs := make([]exported.GenesisAccount, 2) + genAccs := make([]authtypes.GenesisAccount, 2) genAccs[0] = baseVestingAcc genAccs[1] = acc2 diff --git a/x/auth/vesting/types/vesting_account.go b/x/auth/vesting/types/vesting_account.go index d4b6fc6345..b032499b34 100644 --- a/x/auth/vesting/types/vesting_account.go +++ b/x/auth/vesting/types/vesting_account.go @@ -6,7 +6,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" vestexported "github.com/cosmos/cosmos-sdk/x/auth/vesting/exported" @@ -16,7 +15,7 @@ import ( // Compile-time type assertions var ( - _ authexported.Account = (*BaseVestingAccount)(nil) + _ authtypes.AccountI = (*BaseVestingAccount)(nil) _ vestexported.VestingAccount = (*ContinuousVestingAccount)(nil) _ vestexported.VestingAccount = (*PeriodicVestingAccount)(nil) _ vestexported.VestingAccount = (*DelayedVestingAccount)(nil) @@ -265,7 +264,7 @@ func (bva *BaseVestingAccount) UnmarshalJSON(bz []byte) error { // Continuous Vesting Account var _ vestexported.VestingAccount = (*ContinuousVestingAccount)(nil) -var _ authexported.GenesisAccount = (*ContinuousVestingAccount)(nil) +var _ authtypes.GenesisAccount = (*ContinuousVestingAccount)(nil) // NewContinuousVestingAccountRaw creates a new ContinuousVestingAccount object from BaseVestingAccount func NewContinuousVestingAccountRaw(bva *BaseVestingAccount, startTime int64) *ContinuousVestingAccount { @@ -425,7 +424,7 @@ func (cva *ContinuousVestingAccount) UnmarshalJSON(bz []byte) error { // Periodic Vesting Account var _ vestexported.VestingAccount = (*PeriodicVestingAccount)(nil) -var _ authexported.GenesisAccount = (*PeriodicVestingAccount)(nil) +var _ authtypes.GenesisAccount = (*PeriodicVestingAccount)(nil) // NewPeriodicVestingAccountRaw creates a new PeriodicVestingAccount object from BaseVestingAccount func NewPeriodicVestingAccountRaw(bva *BaseVestingAccount, startTime int64, periods Periods) *PeriodicVestingAccount { @@ -617,7 +616,7 @@ func (pva *PeriodicVestingAccount) UnmarshalJSON(bz []byte) error { // Delayed Vesting Account var _ vestexported.VestingAccount = (*DelayedVestingAccount)(nil) -var _ authexported.GenesisAccount = (*DelayedVestingAccount)(nil) +var _ authtypes.GenesisAccount = (*DelayedVestingAccount)(nil) // NewDelayedVestingAccountRaw creates a new DelayedVestingAccount object from BaseVestingAccount func NewDelayedVestingAccountRaw(bva *BaseVestingAccount) *DelayedVestingAccount { diff --git a/x/auth/vesting/types/vesting_account_test.go b/x/auth/vesting/types/vesting_account_test.go index 974a1f3149..5f6d8a31cd 100644 --- a/x/auth/vesting/types/vesting_account_test.go +++ b/x/auth/vesting/types/vesting_account_test.go @@ -10,7 +10,6 @@ import ( tmtime "github.com/tendermint/tendermint/types/time" sdk "github.com/cosmos/cosmos-sdk/types" - authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" ) @@ -587,7 +586,7 @@ func TestGenesisAccountValidate(t *testing.T) { baseVestingWithCoins := types.NewBaseVestingAccount(baseAcc, initialVesting, 100) tests := []struct { name string - acc authexported.GenesisAccount + acc authtypes.GenesisAccount expErr bool }{ { @@ -674,16 +673,16 @@ func TestContinuousVestingAccountMarshal(t *testing.T) { baseVesting := types.NewBaseVestingAccount(baseAcc, coins, time.Now().Unix()) acc := types.NewContinuousVestingAccountRaw(baseVesting, baseVesting.EndTime) - bz, err := appCodec.MarshalAccount(acc) + bz, err := app.AccountKeeper.MarshalAccount(acc) require.Nil(t, err) - acc2, err := appCodec.UnmarshalAccount(bz) + acc2, err := app.AccountKeeper.UnmarshalAccount(bz) require.Nil(t, err) require.IsType(t, &types.ContinuousVestingAccount{}, acc2) require.Equal(t, acc.String(), acc2.String()) // error on bad bytes - _, err = appCodec.UnmarshalAccount(bz[:len(bz)/2]) + _, err = app.AccountKeeper.UnmarshalAccount(bz[:len(bz)/2]) require.NotNil(t, err) } @@ -716,16 +715,16 @@ func TestPeriodicVestingAccountMarshal(t *testing.T) { acc := types.NewPeriodicVestingAccount(baseAcc, coins, time.Now().Unix(), types.Periods{types.Period{3600, coins}}) - bz, err := appCodec.MarshalAccount(acc) + bz, err := app.AccountKeeper.MarshalAccount(acc) require.Nil(t, err) - acc2, err := appCodec.UnmarshalAccount(bz) + acc2, err := app.AccountKeeper.UnmarshalAccount(bz) require.Nil(t, err) require.IsType(t, &types.PeriodicVestingAccount{}, acc2) require.Equal(t, acc.String(), acc2.String()) // error on bad bytes - _, err = appCodec.UnmarshalAccount(bz[:len(bz)/2]) + _, err = app.AccountKeeper.UnmarshalAccount(bz[:len(bz)/2]) require.NotNil(t, err) } @@ -757,16 +756,16 @@ func TestDelayedVestingAccountMarshal(t *testing.T) { acc := types.NewDelayedVestingAccount(baseAcc, coins, time.Now().Unix()) - bz, err := appCodec.MarshalAccount(acc) + bz, err := app.AccountKeeper.MarshalAccount(acc) require.Nil(t, err) - acc2, err := appCodec.UnmarshalAccount(bz) + acc2, err := app.AccountKeeper.UnmarshalAccount(bz) require.Nil(t, err) require.IsType(t, &types.DelayedVestingAccount{}, acc2) require.Equal(t, acc.String(), acc2.String()) // error on bad bytes - _, err = appCodec.UnmarshalAccount(bz[:len(bz)/2]) + _, err = app.AccountKeeper.UnmarshalAccount(bz[:len(bz)/2]) require.NotNil(t, err) } diff --git a/x/bank/app_test.go b/x/bank/app_test.go index 47bbee7c72..c30cfc9f1c 100644 --- a/x/bank/app_test.go +++ b/x/bank/app_test.go @@ -14,7 +14,7 @@ import ( "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" - authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/bank/types" ) @@ -93,7 +93,7 @@ func TestSendNotEnoughBalance(t *testing.T) { Address: addr1, } - genAccs := []authexported.GenesisAccount{acc} + genAccs := []authtypes.GenesisAccount{acc} app := simapp.SetupWithGenesisAccounts(genAccs) ctx := app.BaseApp.NewContext(false, abci.Header{}) @@ -161,7 +161,7 @@ func TestSendToModuleAcc(t *testing.T) { Address: test.msg.FromAddress, } - genAccs := []authexported.GenesisAccount{acc} + genAccs := []authtypes.GenesisAccount{acc} app := simapp.SetupWithGenesisAccounts(genAccs) ctx := app.BaseApp.NewContext(false, abci.Header{}) @@ -202,7 +202,7 @@ func TestMsgMultiSendWithAccounts(t *testing.T) { Address: addr1, } - genAccs := []authexported.GenesisAccount{acc} + genAccs := []authtypes.GenesisAccount{acc} app := simapp.SetupWithGenesisAccounts(genAccs) ctx := app.BaseApp.NewContext(false, abci.Header{}) @@ -269,7 +269,7 @@ func TestMsgMultiSendMultipleOut(t *testing.T) { Address: addr2, } - genAccs := []authexported.GenesisAccount{acc1, acc2} + genAccs := []authtypes.GenesisAccount{acc1, acc2} app := simapp.SetupWithGenesisAccounts(genAccs) ctx := app.BaseApp.NewContext(false, abci.Header{}) @@ -319,7 +319,7 @@ func TestMsgMultiSendMultipleInOut(t *testing.T) { Address: addr4, } - genAccs := []authexported.GenesisAccount{acc1, acc2, acc4} + genAccs := []authtypes.GenesisAccount{acc1, acc2, acc4} app := simapp.SetupWithGenesisAccounts(genAccs) ctx := app.BaseApp.NewContext(false, abci.Header{}) @@ -368,7 +368,7 @@ func TestMsgMultiSendDependent(t *testing.T) { err := acc2.SetAccountNumber(1) require.NoError(t, err) - genAccs := []authexported.GenesisAccount{acc1, acc2} + genAccs := []authtypes.GenesisAccount{acc1, acc2} app := simapp.SetupWithGenesisAccounts(genAccs) ctx := app.BaseApp.NewContext(false, abci.Header{}) diff --git a/x/bank/bench_test.go b/x/bank/bench_test.go index 4bc978c3fc..a66e8d593d 100644 --- a/x/bank/bench_test.go +++ b/x/bank/bench_test.go @@ -9,7 +9,7 @@ import ( "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" - authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" + "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/staking" ) @@ -22,7 +22,7 @@ func BenchmarkOneBankSendTxPerBlock(b *testing.B) { } // construct genesis state - genAccs := []authexported.GenesisAccount{&acc} + genAccs := []types.GenesisAccount{&acc} benchmarkApp := simapp.SetupWithGenesisAccounts(genAccs) ctx := benchmarkApp.BaseApp.NewContext(false, abci.Header{}) @@ -62,7 +62,7 @@ func BenchmarkOneBankMultiSendTxPerBlock(b *testing.B) { } // Construct genesis state - genAccs := []authexported.GenesisAccount{&acc} + genAccs := []types.GenesisAccount{&acc} benchmarkApp := simapp.SetupWithGenesisAccounts(genAccs) ctx := benchmarkApp.BaseApp.NewContext(false, abci.Header{}) diff --git a/x/bank/types/expected_keepers.go b/x/bank/types/expected_keepers.go index 19a266354b..7307864b86 100644 --- a/x/bank/types/expected_keepers.go +++ b/x/bank/types/expected_keepers.go @@ -2,26 +2,26 @@ package types import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/auth/exported" + "github.com/cosmos/cosmos-sdk/x/auth/types" ) // AccountKeeper defines the account contract that must be fulfilled when // creating a x/bank keeper. type AccountKeeper interface { - NewAccount(sdk.Context, exported.Account) exported.Account - NewAccountWithAddress(ctx sdk.Context, addr sdk.AccAddress) exported.Account + NewAccount(sdk.Context, types.AccountI) types.AccountI + NewAccountWithAddress(ctx sdk.Context, addr sdk.AccAddress) types.AccountI - GetAccount(ctx sdk.Context, addr sdk.AccAddress) exported.Account - GetAllAccounts(ctx sdk.Context) []exported.Account - SetAccount(ctx sdk.Context, acc exported.Account) + GetAccount(ctx sdk.Context, addr sdk.AccAddress) types.AccountI + GetAllAccounts(ctx sdk.Context) []types.AccountI + SetAccount(ctx sdk.Context, acc types.AccountI) - IterateAccounts(ctx sdk.Context, process func(exported.Account) bool) + IterateAccounts(ctx sdk.Context, process func(types.AccountI) bool) - ValidatePermissions(macc exported.ModuleAccountI) error + ValidatePermissions(macc types.ModuleAccountI) error GetModuleAddress(moduleName string) sdk.AccAddress GetModuleAddressAndPermissions(moduleName string) (addr sdk.AccAddress, permissions []string) - GetModuleAccountAndPermissions(ctx sdk.Context, moduleName string) (exported.ModuleAccountI, []string) - GetModuleAccount(ctx sdk.Context, moduleName string) exported.ModuleAccountI - SetModuleAccount(ctx sdk.Context, macc exported.ModuleAccountI) + GetModuleAccountAndPermissions(ctx sdk.Context, moduleName string) (types.ModuleAccountI, []string) + GetModuleAccount(ctx sdk.Context, moduleName string) types.ModuleAccountI + SetModuleAccount(ctx sdk.Context, macc types.ModuleAccountI) } diff --git a/x/distribution/keeper/alias_functions.go b/x/distribution/keeper/alias_functions.go index 29406e326c..5d7f1b97f2 100644 --- a/x/distribution/keeper/alias_functions.go +++ b/x/distribution/keeper/alias_functions.go @@ -2,7 +2,7 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" - authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/distribution/types" ) @@ -17,6 +17,6 @@ func (k Keeper) GetFeePoolCommunityCoins(ctx sdk.Context) sdk.DecCoins { } // GetDistributionAccount returns the distribution ModuleAccount -func (k Keeper) GetDistributionAccount(ctx sdk.Context) authexported.ModuleAccountI { +func (k Keeper) GetDistributionAccount(ctx sdk.Context) authtypes.ModuleAccountI { return k.authKeeper.GetModuleAccount(ctx, types.ModuleName) } diff --git a/x/distribution/keeper/delegation.go b/x/distribution/keeper/delegation.go index 5604bf92fd..3febc98614 100644 --- a/x/distribution/keeper/delegation.go +++ b/x/distribution/keeper/delegation.go @@ -100,7 +100,7 @@ func (k Keeper) CalculateDelegationRewards(ctx sdk.Context, val exported.Validat currentStake := val.TokensFromShares(del.GetShares()) if stake.GT(currentStake) { - // Account for rounding inconsistencies between: + // AccountI for rounding inconsistencies between: // // currentStake: calculated as in staking with a single computation // stake: calculated as an accumulation of stake diff --git a/x/distribution/types/expected_keepers.go b/x/distribution/types/expected_keepers.go index 4e39b3ff33..7a6d134d0f 100644 --- a/x/distribution/types/expected_keepers.go +++ b/x/distribution/types/expected_keepers.go @@ -2,20 +2,20 @@ package types import ( sdk "github.com/cosmos/cosmos-sdk/types" - authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" + "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/staking" stakingexported "github.com/cosmos/cosmos-sdk/x/staking/exported" ) // AccountKeeper defines the expected account keeper used for simulations (noalias) type AccountKeeper interface { - GetAccount(ctx sdk.Context, addr sdk.AccAddress) authexported.Account + GetAccount(ctx sdk.Context, addr sdk.AccAddress) types.AccountI GetModuleAddress(name string) sdk.AccAddress - GetModuleAccount(ctx sdk.Context, name string) authexported.ModuleAccountI + GetModuleAccount(ctx sdk.Context, name string) types.ModuleAccountI // TODO remove with genesis 2-phases refactor https://github.com/cosmos/cosmos-sdk/issues/2862 - SetModuleAccount(sdk.Context, authexported.ModuleAccountI) + SetModuleAccount(sdk.Context, types.ModuleAccountI) } // BankKeeper defines the expected interface needed to retrieve account balances. diff --git a/x/genutil/types/expected_keepers.go b/x/genutil/types/expected_keepers.go index bd0e750f2f..e003610a17 100644 --- a/x/genutil/types/expected_keepers.go +++ b/x/genutil/types/expected_keepers.go @@ -7,7 +7,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" + auth "github.com/cosmos/cosmos-sdk/x/auth/types" bankexported "github.com/cosmos/cosmos-sdk/x/bank/exported" ) @@ -18,9 +18,9 @@ type StakingKeeper interface { // AccountKeeper defines the expected account keeper (noalias) type AccountKeeper interface { - NewAccount(sdk.Context, authexported.Account) authexported.Account - SetAccount(sdk.Context, authexported.Account) - IterateAccounts(ctx sdk.Context, process func(authexported.Account) (stop bool)) + NewAccount(sdk.Context, auth.AccountI) auth.AccountI + SetAccount(sdk.Context, auth.AccountI) + IterateAccounts(ctx sdk.Context, process func(auth.AccountI) (stop bool)) } // GenesisAccountsIterator defines the expected iterating genesis accounts object (noalias) @@ -28,7 +28,7 @@ type GenesisAccountsIterator interface { IterateGenesisAccounts( cdc *codec.Codec, appGenesis map[string]json.RawMessage, - cb func(authexported.Account) (stop bool), + cb func(auth.AccountI) (stop bool), ) } diff --git a/x/gov/keeper/keeper.go b/x/gov/keeper/keeper.go index b892febfff..083711bbda 100644 --- a/x/gov/keeper/keeper.go +++ b/x/gov/keeper/keeper.go @@ -8,7 +8,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/gov/types" ) @@ -77,7 +77,7 @@ func (keeper Keeper) Router() types.Router { } // GetGovernanceAccount returns the governance ModuleAccount -func (keeper Keeper) GetGovernanceAccount(ctx sdk.Context) authexported.ModuleAccountI { +func (keeper Keeper) GetGovernanceAccount(ctx sdk.Context) authtypes.ModuleAccountI { return keeper.authKeeper.GetModuleAccount(ctx, types.ModuleName) } diff --git a/x/gov/types/expected_keepers.go b/x/gov/types/expected_keepers.go index 2ff31a2612..fcaa095369 100644 --- a/x/gov/types/expected_keepers.go +++ b/x/gov/types/expected_keepers.go @@ -2,7 +2,7 @@ package types import ( sdk "github.com/cosmos/cosmos-sdk/types" - authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" + "github.com/cosmos/cosmos-sdk/x/auth/types" stakingexported "github.com/cosmos/cosmos-sdk/x/staking/exported" ) @@ -28,13 +28,13 @@ type StakingKeeper interface { // AccountKeeper defines the expected account keeper (noalias) type AccountKeeper interface { - GetAccount(ctx sdk.Context, addr sdk.AccAddress) authexported.Account + GetAccount(ctx sdk.Context, addr sdk.AccAddress) types.AccountI GetModuleAddress(name string) sdk.AccAddress - GetModuleAccount(ctx sdk.Context, name string) authexported.ModuleAccountI + GetModuleAccount(ctx sdk.Context, name string) types.ModuleAccountI // TODO remove with genesis 2-phases refactor https://github.com/cosmos/cosmos-sdk/issues/2862 - SetModuleAccount(sdk.Context, authexported.ModuleAccountI) + SetModuleAccount(sdk.Context, types.ModuleAccountI) } // BankKeeper defines the expected interface needed to retrieve account balances. diff --git a/x/ibc-transfer/keeper/keeper.go b/x/ibc-transfer/keeper/keeper.go index 7c8ff18ef7..1202f1a7d1 100644 --- a/x/ibc-transfer/keeper/keeper.go +++ b/x/ibc-transfer/keeper/keeper.go @@ -8,7 +8,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/capability" "github.com/cosmos/cosmos-sdk/x/ibc-transfer/types" channel "github.com/cosmos/cosmos-sdk/x/ibc/04-channel" @@ -67,7 +67,7 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger { } // GetTransferAccount returns the ICS20 - transfers ModuleAccount -func (k Keeper) GetTransferAccount(ctx sdk.Context) authexported.ModuleAccountI { +func (k Keeper) GetTransferAccount(ctx sdk.Context) authtypes.ModuleAccountI { return k.authKeeper.GetModuleAccount(ctx, types.ModuleName) } diff --git a/x/ibc-transfer/types/expected_keepers.go b/x/ibc-transfer/types/expected_keepers.go index 5c5e26da1a..b01d9840c7 100644 --- a/x/ibc-transfer/types/expected_keepers.go +++ b/x/ibc-transfer/types/expected_keepers.go @@ -2,7 +2,7 @@ package types import ( sdk "github.com/cosmos/cosmos-sdk/types" - authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" + "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/capability" clientexported "github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported" connection "github.com/cosmos/cosmos-sdk/x/ibc/03-connection" @@ -13,7 +13,7 @@ import ( // AccountKeeper defines the contract required for account APIs. type AccountKeeper interface { GetModuleAddress(name string) sdk.AccAddress - GetModuleAccount(ctx sdk.Context, name string) authexported.ModuleAccountI + GetModuleAccount(ctx sdk.Context, name string) types.ModuleAccountI } // BankKeeper defines the expected bank keeper diff --git a/x/mint/types/expected_keepers.go b/x/mint/types/expected_keepers.go index 542b293258..85b6d776c5 100644 --- a/x/mint/types/expected_keepers.go +++ b/x/mint/types/expected_keepers.go @@ -2,7 +2,7 @@ package types // noalias import ( sdk "github.com/cosmos/cosmos-sdk/types" - authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" + "github.com/cosmos/cosmos-sdk/x/auth/types" ) // StakingKeeper defines the expected staking keeper @@ -16,8 +16,8 @@ type AccountKeeper interface { GetModuleAddress(name string) sdk.AccAddress // TODO remove with genesis 2-phases refactor https://github.com/cosmos/cosmos-sdk/issues/2862 - SetModuleAccount(sdk.Context, authexported.ModuleAccountI) - GetModuleAccount(ctx sdk.Context, moduleName string) authexported.ModuleAccountI + SetModuleAccount(sdk.Context, types.ModuleAccountI) + GetModuleAccount(ctx sdk.Context, moduleName string) types.ModuleAccountI } // BankKeeper defines the contract needed to be fulfilled for banking and supply diff --git a/x/slashing/app_test.go b/x/slashing/app_test.go index 364bb8e51a..cc82ebd339 100644 --- a/x/slashing/app_test.go +++ b/x/slashing/app_test.go @@ -11,7 +11,7 @@ import ( "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" - authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/bank" "github.com/cosmos/cosmos-sdk/x/slashing" "github.com/cosmos/cosmos-sdk/x/staking" @@ -45,7 +45,7 @@ func TestSlashingMsgs(t *testing.T) { acc1 := &auth.BaseAccount{ Address: addr1, } - accs := authexported.GenesisAccounts{acc1} + accs := authtypes.GenesisAccounts{acc1} balances := []bank.Balance{ { Address: addr1, diff --git a/x/slashing/types/expected_keepers.go b/x/slashing/types/expected_keepers.go index 50e71cb614..4a09ca7298 100644 --- a/x/slashing/types/expected_keepers.go +++ b/x/slashing/types/expected_keepers.go @@ -4,15 +4,15 @@ package types import ( sdk "github.com/cosmos/cosmos-sdk/types" - authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" + auth "github.com/cosmos/cosmos-sdk/x/auth/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" stakingexported "github.com/cosmos/cosmos-sdk/x/staking/exported" ) // AccountKeeper expected account keeper type AccountKeeper interface { - GetAccount(ctx sdk.Context, addr sdk.AccAddress) authexported.Account - IterateAccounts(ctx sdk.Context, process func(authexported.Account) (stop bool)) + GetAccount(ctx sdk.Context, addr sdk.AccAddress) auth.AccountI + IterateAccounts(ctx sdk.Context, process func(auth.AccountI) (stop bool)) } // BankKeeper defines the expected interface needed to retrieve account balances. diff --git a/x/staking/app_test.go b/x/staking/app_test.go index c333078840..635898ee92 100644 --- a/x/staking/app_test.go +++ b/x/staking/app_test.go @@ -9,7 +9,6 @@ import ( "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" - authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" "github.com/cosmos/cosmos-sdk/x/bank" "github.com/cosmos/cosmos-sdk/x/staking" ) @@ -47,7 +46,7 @@ func TestStakingMsgs(t *testing.T) { acc1 := &auth.BaseAccount{Address: addr1} acc2 := &auth.BaseAccount{Address: addr2} - accs := authexported.GenesisAccounts{acc1, acc2} + accs := auth.GenesisAccounts{acc1, acc2} balances := []bank.Balance{ { Address: addr1, diff --git a/x/staking/keeper/pool.go b/x/staking/keeper/pool.go index a6fe909864..5ced841e2f 100644 --- a/x/staking/keeper/pool.go +++ b/x/staking/keeper/pool.go @@ -2,17 +2,17 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" - authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/staking/types" ) // GetBondedPool returns the bonded tokens pool's module account -func (k Keeper) GetBondedPool(ctx sdk.Context) (bondedPool authexported.ModuleAccountI) { +func (k Keeper) GetBondedPool(ctx sdk.Context) (bondedPool authtypes.ModuleAccountI) { return k.authKeeper.GetModuleAccount(ctx, types.BondedPoolName) } // GetNotBondedPool returns the not bonded tokens pool's module account -func (k Keeper) GetNotBondedPool(ctx sdk.Context) (notBondedPool authexported.ModuleAccountI) { +func (k Keeper) GetNotBondedPool(ctx sdk.Context) (notBondedPool authtypes.ModuleAccountI) { return k.authKeeper.GetModuleAccount(ctx, types.NotBondedPoolName) } diff --git a/x/staking/types/expected_keepers.go b/x/staking/types/expected_keepers.go index e0f58b86cb..9dd80419a4 100644 --- a/x/staking/types/expected_keepers.go +++ b/x/staking/types/expected_keepers.go @@ -2,7 +2,7 @@ package types import ( sdk "github.com/cosmos/cosmos-sdk/types" - authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" bankexported "github.com/cosmos/cosmos-sdk/x/bank/exported" stakingexported "github.com/cosmos/cosmos-sdk/x/staking/exported" ) @@ -15,14 +15,14 @@ type DistributionKeeper interface { // AccountKeeper defines the expected account keeper (noalias) type AccountKeeper interface { - IterateAccounts(ctx sdk.Context, process func(authexported.Account) (stop bool)) - GetAccount(ctx sdk.Context, addr sdk.AccAddress) authexported.Account // only used for simulation + IterateAccounts(ctx sdk.Context, process func(authtypes.AccountI) (stop bool)) + GetAccount(ctx sdk.Context, addr sdk.AccAddress) authtypes.AccountI // only used for simulation GetModuleAddress(name string) sdk.AccAddress - GetModuleAccount(ctx sdk.Context, moduleName string) authexported.ModuleAccountI + GetModuleAccount(ctx sdk.Context, moduleName string) authtypes.ModuleAccountI // TODO remove with genesis 2-phases refactor https://github.com/cosmos/cosmos-sdk/issues/2862 - SetModuleAccount(sdk.Context, authexported.ModuleAccountI) + SetModuleAccount(sdk.Context, authtypes.ModuleAccountI) } // BankKeeper defines the expected interface needed to retrieve account balances.