feat(staking)!: add consensus and validator address codec in staking (#16959)
Co-authored-by: Facundo Medica <14063057+facundomedica@users.noreply.github.com>
This commit is contained in:
parent
b1ac5768f7
commit
e0be2b80fc
@ -56,6 +56,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
||||
|
||||
### API Breaking Changes
|
||||
|
||||
* (staking) [#16959](https://github.com/cosmos/cosmos-sdk/pull/16959) Add validator and consensus address codec as staking keeper arguments.
|
||||
* (types) [#16272](https://github.com/cosmos/cosmos-sdk/pull/16272) From now the `FeeGranter` in the `FeeTx` interface takes the byte type instead of string.
|
||||
* (testutil) [#16899](https://github.com/cosmos/cosmos-sdk/pull/16899) The *cli testutil* `QueryBalancesExec` has been removed. Use the gRPC or REST query instead.
|
||||
* (x/auth) [#16650](https://github.com/cosmos/cosmos-sdk/pull/16650) The *cli testutil* `QueryAccountExec` has been removed. Use the gRPC or REST query instead.
|
||||
@ -111,7 +112,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
||||
|
||||
* (x/staking) [#16324](https://github.com/cosmos/cosmos-sdk/pull/16324) `NewKeeper` now takes a `KVStoreService` instead of a `StoreKey`, and methods in the `Keeper` now take a `context.Context` instead of a `sdk.Context` and return an `error`. Notable changes:
|
||||
* `Validator` method now returns `types.ErrNoValidatorFound` instead of `nil` when not found.
|
||||
* (x/auth) [#16621](https://github.com/cosmos/cosmos-sdk/pull/16621), [#16768](https://github.com/cosmos/cosmos-sdk/pull/16768) Pass address codecs to auth new keeper constructor.
|
||||
* (x/auth) [#16621](https://github.com/cosmos/cosmos-sdk/pull/16621) Pass address codec to auth new keeper constructor.
|
||||
* (x/auth/vesting) [#16741](https://github.com/cosmos/cosmos-sdk/pull/16741) Vesting account constructor now return an error with the result of their validate function.
|
||||
|
||||
## [v0.50.0-alpha.0](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.50.0-alpha.0) - 2023-06-07
|
||||
|
||||
@ -14,7 +14,7 @@ import (
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
)
|
||||
|
||||
// AppOptions are autocli options for an app. These options can be built via depinject based on an app config. Ex:
|
||||
@ -39,7 +39,7 @@ type AppOptions struct {
|
||||
|
||||
// AddressCodec is the address codec to use for the app.
|
||||
AddressCodec address.Codec
|
||||
ValidatorAddressCodec authtypes.ValidatorAddressCodec
|
||||
ValidatorAddressCodec stakingtypes.ValidatorAddressCodec
|
||||
}
|
||||
|
||||
// EnhanceRootCommand enhances the provided root command with autocli AppOptions,
|
||||
|
||||
@ -3,12 +3,12 @@ module cosmossdk.io/client/v2
|
||||
go 1.20
|
||||
|
||||
require (
|
||||
cosmossdk.io/api v0.5.0
|
||||
cosmossdk.io/api v0.6.0
|
||||
cosmossdk.io/core v0.9.0
|
||||
cosmossdk.io/depinject v1.0.0-alpha.3
|
||||
github.com/cockroachdb/errors v1.10.0
|
||||
github.com/cosmos/cosmos-proto v1.0.0-beta.3
|
||||
github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230630082137-cba58097ef9a
|
||||
github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230712155822-3b269baa9c90
|
||||
github.com/cosmos/gogoproto v1.4.10
|
||||
github.com/spf13/cobra v1.7.0
|
||||
github.com/spf13/pflag v1.0.5
|
||||
@ -22,7 +22,7 @@ require (
|
||||
require (
|
||||
cosmossdk.io/collections v0.3.0 // indirect
|
||||
cosmossdk.io/errors v1.0.0 // indirect
|
||||
cosmossdk.io/log v1.1.0 // indirect
|
||||
cosmossdk.io/log v1.1.1-0.20230704160919-88f2c830b0ca // indirect
|
||||
cosmossdk.io/math v1.0.1 // indirect
|
||||
cosmossdk.io/store v1.0.0-alpha.1 // indirect
|
||||
cosmossdk.io/x/tx v0.8.0 // indirect
|
||||
@ -30,7 +30,6 @@ require (
|
||||
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
|
||||
github.com/99designs/keyring v1.2.1 // indirect
|
||||
github.com/DataDog/zstd v1.5.5 // indirect
|
||||
github.com/armon/go-metrics v0.4.1 // indirect
|
||||
github.com/beorn7/perks v1.0.1 // indirect
|
||||
github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 // indirect
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
|
||||
|
||||
@ -35,8 +35,8 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl
|
||||
cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs=
|
||||
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
|
||||
cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo=
|
||||
cosmossdk.io/api v0.5.0 h1:C0gzb5N3qYE0VEUlXleuilv7Z/7/MHhdOKkgn2Ugfnc=
|
||||
cosmossdk.io/api v0.5.0/go.mod h1:5Jc00Q4tSTcrZXvvE3J/ybvZK6DopLcp3ThK3X703QE=
|
||||
cosmossdk.io/api v0.6.0 h1:AEpx/sRZaQEusARZqAxbg20zRXnS6e1F+uoal39trOM=
|
||||
cosmossdk.io/api v0.6.0/go.mod h1:kJFAEMLN57y0viszHDPLMmieF0471o5QAwwApa+270M=
|
||||
cosmossdk.io/collections v0.3.0 h1:v0eEqLBxebAV+t+Ahwf9tSJOu95HVLINwROXx2TTZ08=
|
||||
cosmossdk.io/collections v0.3.0/go.mod h1:CHE1+niUElL9ikCpevRZcp0yqQ4TU0TrEEGirN0mvIg=
|
||||
cosmossdk.io/core v0.9.0 h1:30ScAOHDIUOCg1DKAwqkho9wuQJnu7GUrMcg0XLioic=
|
||||
@ -45,8 +45,8 @@ cosmossdk.io/depinject v1.0.0-alpha.3 h1:6evFIgj//Y3w09bqOUOzEpFj5tsxBqdc5CfkO7z
|
||||
cosmossdk.io/depinject v1.0.0-alpha.3/go.mod h1:eRbcdQ7MRpIPEM5YUJh8k97nxHpYbc3sMUnEtt8HPWU=
|
||||
cosmossdk.io/errors v1.0.0 h1:nxF07lmlBbB8NKQhtJ+sJm6ef5uV1XkvPXG2bUntb04=
|
||||
cosmossdk.io/errors v1.0.0/go.mod h1:+hJZLuhdDE0pYN8HkOrVNwrIOYvUGnn6+4fjnJs/oV0=
|
||||
cosmossdk.io/log v1.1.0 h1:v0ogPHYeTzPcBTcPR1A3j1hkei4pZama8kz8LKlCMv0=
|
||||
cosmossdk.io/log v1.1.0/go.mod h1:6zjroETlcDs+mm62gd8Ig7mZ+N+fVOZS91V17H+M4N4=
|
||||
cosmossdk.io/log v1.1.1-0.20230704160919-88f2c830b0ca h1:msenprh2BLLRwNT7zN56TbBHOGk/7ARQckXHxXyvjoQ=
|
||||
cosmossdk.io/log v1.1.1-0.20230704160919-88f2c830b0ca/go.mod h1:PkIAKXZvaxrTRc++z53XMRvFk8AcGGWYHcMIPzVYX9c=
|
||||
cosmossdk.io/math v1.0.1 h1:Qx3ifyOPaMLNH/89WeZFH268yCvU4xEcnPLu3sJqPPg=
|
||||
cosmossdk.io/math v1.0.1/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k=
|
||||
cosmossdk.io/store v1.0.0-alpha.1 h1:/151XxAgm0tiKuYrtJzMG61lf6enpPuP+D/hIN8cRjQ=
|
||||
@ -85,8 +85,6 @@ github.com/apache/thrift v0.13.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb
|
||||
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
|
||||
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
|
||||
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
|
||||
github.com/armon/go-metrics v0.4.1 h1:hR91U9KYmb6bLBYLQjyM+3j+rcd/UhE+G78SFnF8gJA=
|
||||
github.com/armon/go-metrics v0.4.1/go.mod h1:E6amYzXo6aW1tqzoZGT755KkbgrJsSdpwZ+3JqfkOG4=
|
||||
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
|
||||
github.com/aryann/difflib v0.0.0-20170710044230-e206f873d14a/go.mod h1:DAHtR1m6lCRdSC2Tm3DSWRPvIPr6xNKyeHdqDQSQT+A=
|
||||
github.com/aws/aws-lambda-go v1.13.3/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQwij/eHl5CU=
|
||||
@ -100,6 +98,7 @@ github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6r
|
||||
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
|
||||
github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 h1:41iFGWnSlI2gVpmOtVTJZNodLdLQLn/KsJqFvXwnd/s=
|
||||
github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
|
||||
github.com/bits-and-blooms/bitset v1.8.0 h1:FD+XqgOZDUxxZ8hzoBFuV9+cGWY9CslN6d5MS5JVb4c=
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.2 h1:5n0X6hX0Zk+6omWcihdYvdAlGf2DfasC0GMf7DClJ3U=
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.2/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04=
|
||||
github.com/btcsuite/btcd/btcutil v1.1.3 h1:xfbtw8lwpp0G6NwSHb+UE67ryTFHJAiNuipusjXSohQ=
|
||||
@ -162,8 +161,8 @@ github.com/cosmos/cosmos-db v1.0.0 h1:EVcQZ+qYag7W6uorBKFPvX6gRjw6Uq2hIh4hCWjuQ0
|
||||
github.com/cosmos/cosmos-db v1.0.0/go.mod h1:iBvi1TtqaedwLdcrZVYRSSCb6eSy61NLj4UNmdIgs0U=
|
||||
github.com/cosmos/cosmos-proto v1.0.0-beta.3 h1:VitvZ1lPORTVxkmF2fAp3IiA61xVwArQYKXTdEcpW6o=
|
||||
github.com/cosmos/cosmos-proto v1.0.0-beta.3/go.mod h1:t8IASdLaAq+bbHbjq4p960BvcTqtwuAxid3b/2rOD6I=
|
||||
github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230630082137-cba58097ef9a h1:UKvuk7VcwbBu5W5809Ji/6K3+LaYo4BgOiO7RMvoHXY=
|
||||
github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230630082137-cba58097ef9a/go.mod h1:arRrlj5ZEon77cGo+1OIQK3hZK40/qSPJ35Gs6gbXNc=
|
||||
github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230712155822-3b269baa9c90 h1:DBxe7gSu1/UPsSqsimostzeis6P732bBTbxG511s/WA=
|
||||
github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230712155822-3b269baa9c90/go.mod h1:L/QMvN62eJFdeaf5AlQPI3g4dSwwsdPA5YCnMbxCvjc=
|
||||
github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY=
|
||||
github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw=
|
||||
github.com/cosmos/gogogateway v1.2.0 h1:Ae/OivNhp8DqBi/sh2A8a1D0y638GpL3tkmLQAiKxTE=
|
||||
|
||||
2
go.mod
2
go.mod
@ -3,7 +3,7 @@ go 1.20
|
||||
module github.com/cosmos/cosmos-sdk
|
||||
|
||||
require (
|
||||
cosmossdk.io/api v0.5.0
|
||||
cosmossdk.io/api v0.6.0
|
||||
cosmossdk.io/collections v0.3.0
|
||||
cosmossdk.io/core v0.9.0
|
||||
cosmossdk.io/depinject v1.0.0-alpha.3
|
||||
|
||||
4
go.sum
4
go.sum
@ -35,8 +35,8 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl
|
||||
cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs=
|
||||
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
|
||||
cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo=
|
||||
cosmossdk.io/api v0.5.0 h1:C0gzb5N3qYE0VEUlXleuilv7Z/7/MHhdOKkgn2Ugfnc=
|
||||
cosmossdk.io/api v0.5.0/go.mod h1:5Jc00Q4tSTcrZXvvE3J/ybvZK6DopLcp3ThK3X703QE=
|
||||
cosmossdk.io/api v0.6.0 h1:AEpx/sRZaQEusARZqAxbg20zRXnS6e1F+uoal39trOM=
|
||||
cosmossdk.io/api v0.6.0/go.mod h1:kJFAEMLN57y0viszHDPLMmieF0471o5QAwwApa+270M=
|
||||
cosmossdk.io/collections v0.3.0 h1:v0eEqLBxebAV+t+Ahwf9tSJOu95HVLINwROXx2TTZ08=
|
||||
cosmossdk.io/collections v0.3.0/go.mod h1:CHE1+niUElL9ikCpevRZcp0yqQ4TU0TrEEGirN0mvIg=
|
||||
cosmossdk.io/core v0.9.0 h1:30ScAOHDIUOCg1DKAwqkho9wuQJnu7GUrMcg0XLioic=
|
||||
|
||||
@ -280,7 +280,7 @@ func NewSimApp(
|
||||
bApp.SetParamStore(app.ConsensusParamsKeeper.ParamsStore)
|
||||
|
||||
// add keepers
|
||||
app.AccountKeeper = authkeeper.NewAccountKeeper(appCodec, runtime.NewKVStoreService(keys[authtypes.StoreKey]), authtypes.ProtoBaseAccount, maccPerms, authcodec.NewBech32Codec(sdk.Bech32MainPrefix), authcodec.NewBech32Codec(sdk.Bech32PrefixValAddr), sdk.Bech32MainPrefix, authtypes.NewModuleAddress(govtypes.ModuleName).String())
|
||||
app.AccountKeeper = authkeeper.NewAccountKeeper(appCodec, runtime.NewKVStoreService(keys[authtypes.StoreKey]), authtypes.ProtoBaseAccount, maccPerms, authcodec.NewBech32Codec(sdk.Bech32MainPrefix), sdk.Bech32MainPrefix, authtypes.NewModuleAddress(govtypes.ModuleName).String())
|
||||
|
||||
app.BankKeeper = bankkeeper.NewBaseKeeper(
|
||||
appCodec,
|
||||
@ -291,7 +291,7 @@ func NewSimApp(
|
||||
logger,
|
||||
)
|
||||
app.StakingKeeper = stakingkeeper.NewKeeper(
|
||||
appCodec, runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), app.AccountKeeper, app.BankKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(),
|
||||
appCodec, runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), app.AccountKeeper, app.BankKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(), authcodec.NewBech32Codec(sdk.Bech32PrefixValAddr), authcodec.NewBech32Codec(sdk.Bech32PrefixConsAddr),
|
||||
)
|
||||
app.MintKeeper = mintkeeper.NewKeeper(appCodec, runtime.NewKVStoreService(keys[minttypes.StoreKey]), app.StakingKeeper, app.AccountKeeper, app.BankKeeper, authtypes.FeeCollectorName, authtypes.NewModuleAddress(govtypes.ModuleName).String())
|
||||
|
||||
|
||||
@ -168,7 +168,6 @@ var (
|
||||
Name: authtypes.ModuleName,
|
||||
Config: appconfig.WrapAny(&authmodulev1.Module{
|
||||
Bech32Prefix: "cosmos",
|
||||
Bech32PrefixValidator: "cosmosvaloper",
|
||||
ModuleAccountPermissions: moduleAccPerms,
|
||||
// By default modules authority is the governance module. This is configurable with the following:
|
||||
// Authority: "group", // A custom module authority can be set using a module name
|
||||
@ -186,8 +185,13 @@ var (
|
||||
}),
|
||||
},
|
||||
{
|
||||
Name: stakingtypes.ModuleName,
|
||||
Config: appconfig.WrapAny(&stakingmodulev1.Module{}),
|
||||
Name: stakingtypes.ModuleName,
|
||||
Config: appconfig.WrapAny(&stakingmodulev1.Module{
|
||||
// NOTE: specifying a prefix is only necessary when using bech32 addresses
|
||||
// If not specfied, the auth Bech32Prefix appended with "valoper" and "valcons" is used by default
|
||||
Bech32PrefixValidator: "cosmosvaloper",
|
||||
Bech32PrefixConsensus: "cosmosvalcons",
|
||||
}),
|
||||
},
|
||||
{
|
||||
Name: slashingtypes.ModuleName,
|
||||
|
||||
@ -28,7 +28,6 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/types/module"
|
||||
"github.com/cosmos/cosmos-sdk/types/msgservice"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/vesting"
|
||||
authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module"
|
||||
"github.com/cosmos/cosmos-sdk/x/bank"
|
||||
@ -42,6 +41,7 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/x/params"
|
||||
"github.com/cosmos/cosmos-sdk/x/slashing"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking"
|
||||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
)
|
||||
|
||||
func TestSimAppExportAndBlockedAddrs(t *testing.T) {
|
||||
@ -317,14 +317,15 @@ func (c customAddressCodec) BytesToString(bz []byte) (string, error) {
|
||||
|
||||
func TestAddressCodecFactory(t *testing.T) {
|
||||
var addrCodec address.Codec
|
||||
var valAddressCodec authtypes.ValidatorAddressCodec
|
||||
var valAddressCodec stakingtypes.ValidatorAddressCodec
|
||||
var consAddressCodec stakingtypes.ConsensusAddressCodec
|
||||
|
||||
err := depinject.Inject(
|
||||
depinject.Configs(
|
||||
network.MinimumAppConfig(),
|
||||
depinject.Supply(log.NewNopLogger()),
|
||||
),
|
||||
&addrCodec, &valAddressCodec)
|
||||
&addrCodec, &valAddressCodec, &consAddressCodec)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, addrCodec)
|
||||
_, ok := addrCodec.(customAddressCodec)
|
||||
@ -332,6 +333,9 @@ func TestAddressCodecFactory(t *testing.T) {
|
||||
require.NotNil(t, valAddressCodec)
|
||||
_, ok = valAddressCodec.(customAddressCodec)
|
||||
require.False(t, ok)
|
||||
require.NotNil(t, consAddressCodec)
|
||||
_, ok = consAddressCodec.(customAddressCodec)
|
||||
require.False(t, ok)
|
||||
|
||||
// Set the address codec to the custom one
|
||||
err = depinject.Inject(
|
||||
@ -340,10 +344,11 @@ func TestAddressCodecFactory(t *testing.T) {
|
||||
depinject.Supply(
|
||||
log.NewNopLogger(),
|
||||
func() address.Codec { return customAddressCodec{} },
|
||||
func() authtypes.ValidatorAddressCodec { return customAddressCodec{} },
|
||||
func() stakingtypes.ValidatorAddressCodec { return customAddressCodec{} },
|
||||
func() stakingtypes.ConsensusAddressCodec { return customAddressCodec{} },
|
||||
),
|
||||
),
|
||||
&addrCodec, &valAddressCodec)
|
||||
&addrCodec, &valAddressCodec, &consAddressCodec)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, addrCodec)
|
||||
_, ok = addrCodec.(customAddressCodec)
|
||||
@ -351,4 +356,7 @@ func TestAddressCodecFactory(t *testing.T) {
|
||||
require.NotNil(t, valAddressCodec)
|
||||
_, ok = valAddressCodec.(customAddressCodec)
|
||||
require.True(t, ok)
|
||||
require.NotNil(t, consAddressCodec)
|
||||
_, ok = consAddressCodec.(customAddressCodec)
|
||||
require.True(t, ok)
|
||||
}
|
||||
|
||||
@ -128,20 +128,28 @@ func NewSimApp(
|
||||
// add it below. By default the auth module uses simulation.RandomGenesisAccounts.
|
||||
//
|
||||
// authtypes.RandomGenesisAccountsFn(simulation.RandomGenesisAccounts),
|
||||
|
||||
//
|
||||
// For providing a custom a base account type add it below.
|
||||
// By default the auth module uses authtypes.ProtoBaseAccount().
|
||||
//
|
||||
// func() sdk.AccountI { return authtypes.ProtoBaseAccount() },
|
||||
|
||||
//
|
||||
// For providing a different address codec, add it below.
|
||||
// By default the auth module uses a Bech32 address codec,
|
||||
// with the prefix defined in the auth module configuration.
|
||||
// NOTE, if a custom address codec is provided, a custom validator
|
||||
// address codec must be provided as well.
|
||||
//
|
||||
// func() address.Codec { return <- custom address codec type -> }
|
||||
// func() auth.ValidatorAddressCodec { return <- custom validator address codec type -> }
|
||||
|
||||
//
|
||||
// STAKING
|
||||
//
|
||||
// For provinding a different validator and consensus address codec, add it below.
|
||||
// By default the staking module uses the bech32 prefix provided in the auth config,
|
||||
// and appends "valoper" and "valcons" for validator and consensus addresses respectively.
|
||||
// When providing a custom address codec in auth, a custom codec must be provided here as well.
|
||||
//
|
||||
// func() stakingtypes.ValidatorAddressCodec { return <- custom validator address codec type -> }
|
||||
// func() stakingtypes.ConsensusAddressCodec { return <- custom consensus address codec type -> }
|
||||
|
||||
//
|
||||
// MINT
|
||||
|
||||
@ -3,7 +3,7 @@ module cosmossdk.io/simapp
|
||||
go 1.20
|
||||
|
||||
require (
|
||||
cosmossdk.io/api v0.5.0
|
||||
cosmossdk.io/api v0.6.0
|
||||
cosmossdk.io/client/v2 v2.0.0-20230630094428-02b760776860
|
||||
cosmossdk.io/core v0.9.0
|
||||
cosmossdk.io/depinject v1.0.0-alpha.3
|
||||
|
||||
@ -187,8 +187,8 @@ cloud.google.com/go/webrisk v1.4.0/go.mod h1:Hn8X6Zr+ziE2aNd8SliSDWpEnSS1u4R9+xX
|
||||
cloud.google.com/go/webrisk v1.5.0/go.mod h1:iPG6fr52Tv7sGk0H6qUFzmL3HHZev1htXuWDEEsqMTg=
|
||||
cloud.google.com/go/workflows v1.6.0/go.mod h1:6t9F5h/unJz41YqfBmqSASJSXccBLtD1Vwf+KmJENM0=
|
||||
cloud.google.com/go/workflows v1.7.0/go.mod h1:JhSrZuVZWuiDfKEFxU0/F1PQjmpnpcoISEXH2bcHC3M=
|
||||
cosmossdk.io/api v0.5.0 h1:C0gzb5N3qYE0VEUlXleuilv7Z/7/MHhdOKkgn2Ugfnc=
|
||||
cosmossdk.io/api v0.5.0/go.mod h1:5Jc00Q4tSTcrZXvvE3J/ybvZK6DopLcp3ThK3X703QE=
|
||||
cosmossdk.io/api v0.6.0 h1:AEpx/sRZaQEusARZqAxbg20zRXnS6e1F+uoal39trOM=
|
||||
cosmossdk.io/api v0.6.0/go.mod h1:kJFAEMLN57y0viszHDPLMmieF0471o5QAwwApa+270M=
|
||||
cosmossdk.io/collections v0.3.0 h1:v0eEqLBxebAV+t+Ahwf9tSJOu95HVLINwROXx2TTZ08=
|
||||
cosmossdk.io/collections v0.3.0/go.mod h1:CHE1+niUElL9ikCpevRZcp0yqQ4TU0TrEEGirN0mvIg=
|
||||
cosmossdk.io/core v0.9.0 h1:30ScAOHDIUOCg1DKAwqkho9wuQJnu7GUrMcg0XLioic=
|
||||
|
||||
@ -3,7 +3,7 @@ module github.com/cosmos/cosmos-sdk/tests
|
||||
go 1.20
|
||||
|
||||
require (
|
||||
cosmossdk.io/api v0.5.0
|
||||
cosmossdk.io/api v0.6.0
|
||||
cosmossdk.io/collections v0.3.0
|
||||
cosmossdk.io/core v0.9.0
|
||||
cosmossdk.io/depinject v1.0.0-alpha.3
|
||||
|
||||
@ -187,8 +187,8 @@ cloud.google.com/go/webrisk v1.4.0/go.mod h1:Hn8X6Zr+ziE2aNd8SliSDWpEnSS1u4R9+xX
|
||||
cloud.google.com/go/webrisk v1.5.0/go.mod h1:iPG6fr52Tv7sGk0H6qUFzmL3HHZev1htXuWDEEsqMTg=
|
||||
cloud.google.com/go/workflows v1.6.0/go.mod h1:6t9F5h/unJz41YqfBmqSASJSXccBLtD1Vwf+KmJENM0=
|
||||
cloud.google.com/go/workflows v1.7.0/go.mod h1:JhSrZuVZWuiDfKEFxU0/F1PQjmpnpcoISEXH2bcHC3M=
|
||||
cosmossdk.io/api v0.5.0 h1:C0gzb5N3qYE0VEUlXleuilv7Z/7/MHhdOKkgn2Ugfnc=
|
||||
cosmossdk.io/api v0.5.0/go.mod h1:5Jc00Q4tSTcrZXvvE3J/ybvZK6DopLcp3ThK3X703QE=
|
||||
cosmossdk.io/api v0.6.0 h1:AEpx/sRZaQEusARZqAxbg20zRXnS6e1F+uoal39trOM=
|
||||
cosmossdk.io/api v0.6.0/go.mod h1:kJFAEMLN57y0viszHDPLMmieF0471o5QAwwApa+270M=
|
||||
cosmossdk.io/collections v0.3.0 h1:v0eEqLBxebAV+t+Ahwf9tSJOu95HVLINwROXx2TTZ08=
|
||||
cosmossdk.io/collections v0.3.0/go.mod h1:CHE1+niUElL9ikCpevRZcp0yqQ4TU0TrEEGirN0mvIg=
|
||||
cosmossdk.io/core v0.9.0 h1:30ScAOHDIUOCg1DKAwqkho9wuQJnu7GUrMcg0XLioic=
|
||||
|
||||
@ -84,7 +84,6 @@ func initDeterministicFixture(t *testing.T) *deterministicFixture {
|
||||
authtypes.ProtoBaseAccount,
|
||||
maccPerms,
|
||||
addresscodec.NewBech32Codec(sdk.Bech32MainPrefix),
|
||||
addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr),
|
||||
sdk.Bech32MainPrefix,
|
||||
authority.String(),
|
||||
)
|
||||
|
||||
@ -84,7 +84,6 @@ func initFixture(tb testing.TB) *fixture {
|
||||
authtypes.ProtoBaseAccount,
|
||||
maccPerms,
|
||||
addresscodec.NewBech32Codec(sdk.Bech32MainPrefix),
|
||||
addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr),
|
||||
sdk.Bech32MainPrefix,
|
||||
authority.String(),
|
||||
)
|
||||
@ -101,7 +100,7 @@ func initFixture(tb testing.TB) *fixture {
|
||||
log.NewNopLogger(),
|
||||
)
|
||||
|
||||
stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), accountKeeper, bankKeeper, authority.String())
|
||||
stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr))
|
||||
|
||||
distrKeeper := distrkeeper.NewKeeper(
|
||||
cdc, runtime.NewKVStoreService(keys[distrtypes.StoreKey]), accountKeeper, bankKeeper, stakingKeeper, distrtypes.ModuleName, authority.String(),
|
||||
|
||||
@ -105,7 +105,6 @@ func initFixture(tb testing.TB) *fixture {
|
||||
authtypes.ProtoBaseAccount,
|
||||
maccPerms,
|
||||
addresscodec.NewBech32Codec(sdk.Bech32MainPrefix),
|
||||
addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr),
|
||||
sdk.Bech32MainPrefix,
|
||||
authority.String(),
|
||||
)
|
||||
@ -122,7 +121,7 @@ func initFixture(tb testing.TB) *fixture {
|
||||
log.NewNopLogger(),
|
||||
)
|
||||
|
||||
stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), accountKeeper, bankKeeper, authority.String())
|
||||
stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr))
|
||||
|
||||
slashingKeeper := slashingkeeper.NewKeeper(cdc, codec.NewLegacyAmino(), runtime.NewKVStoreService(keys[slashingtypes.StoreKey]), stakingKeeper, authority.String())
|
||||
|
||||
|
||||
@ -76,7 +76,6 @@ func initFixture(tb testing.TB) *fixture {
|
||||
authtypes.ProtoBaseAccount,
|
||||
maccPerms,
|
||||
addresscodec.NewBech32Codec(sdk.Bech32MainPrefix),
|
||||
addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr),
|
||||
sdk.Bech32MainPrefix,
|
||||
authority.String(),
|
||||
)
|
||||
@ -93,7 +92,7 @@ func initFixture(tb testing.TB) *fixture {
|
||||
log.NewNopLogger(),
|
||||
)
|
||||
|
||||
stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), accountKeeper, bankKeeper, authority.String())
|
||||
stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr))
|
||||
|
||||
// set default staking params
|
||||
err := stakingKeeper.SetParams(newCtx, stakingtypes.DefaultParams())
|
||||
|
||||
@ -76,7 +76,6 @@ func initFixture(tb testing.TB) *fixture {
|
||||
authtypes.ProtoBaseAccount,
|
||||
maccPerms,
|
||||
addresscodec.NewBech32Codec(sdk.Bech32MainPrefix),
|
||||
addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr),
|
||||
sdk.Bech32MainPrefix,
|
||||
authority.String(),
|
||||
)
|
||||
@ -93,7 +92,7 @@ func initFixture(tb testing.TB) *fixture {
|
||||
log.NewNopLogger(),
|
||||
)
|
||||
|
||||
stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), accountKeeper, bankKeeper, authority.String())
|
||||
stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr))
|
||||
|
||||
slashingKeeper := slashingkeeper.NewKeeper(cdc, &codec.LegacyAmino{}, runtime.NewKVStoreService(keys[slashingtypes.StoreKey]), stakingKeeper, authority.String())
|
||||
|
||||
|
||||
@ -120,7 +120,6 @@ func initFixture(tb testing.TB) *fixture {
|
||||
authtypes.ProtoBaseAccount,
|
||||
maccPerms,
|
||||
addresscodec.NewBech32Codec(sdk.Bech32MainPrefix),
|
||||
addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr),
|
||||
sdk.Bech32MainPrefix,
|
||||
authority.String(),
|
||||
)
|
||||
@ -137,7 +136,7 @@ func initFixture(tb testing.TB) *fixture {
|
||||
log.NewNopLogger(),
|
||||
)
|
||||
|
||||
stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewKVStoreService(keys[types.StoreKey]), accountKeeper, bankKeeper, authority.String())
|
||||
stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewKVStoreService(keys[types.StoreKey]), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr))
|
||||
|
||||
authModule := auth.NewAppModule(cdc, accountKeeper, authsims.RandomGenesisAccounts, nil)
|
||||
bankModule := bank.NewAppModule(cdc, bankKeeper, accountKeeper, nil)
|
||||
|
||||
@ -91,7 +91,6 @@ func initDeterministicFixture(t *testing.T) *deterministicFixture {
|
||||
authtypes.ProtoBaseAccount,
|
||||
maccPerms,
|
||||
addresscodec.NewBech32Codec(sdk.Bech32MainPrefix),
|
||||
addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr),
|
||||
sdk.Bech32MainPrefix,
|
||||
authority.String(),
|
||||
)
|
||||
@ -108,7 +107,7 @@ func initDeterministicFixture(t *testing.T) *deterministicFixture {
|
||||
log.NewNopLogger(),
|
||||
)
|
||||
|
||||
stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), accountKeeper, bankKeeper, authority.String())
|
||||
stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr))
|
||||
|
||||
authModule := auth.NewAppModule(cdc, accountKeeper, authsims.RandomGenesisAccounts, nil)
|
||||
bankModule := bank.NewAppModule(cdc, bankKeeper, accountKeeper, nil)
|
||||
|
||||
@ -46,7 +46,6 @@ func Example() {
|
||||
authtypes.ProtoBaseAccount,
|
||||
map[string][]string{minttypes.ModuleName: {authtypes.Minter}},
|
||||
addresscodec.NewBech32Codec("cosmos"),
|
||||
addresscodec.NewBech32Codec("cosmosvaloper"),
|
||||
"cosmos",
|
||||
authority,
|
||||
)
|
||||
@ -136,7 +135,6 @@ func Example_oneModule() {
|
||||
authtypes.ProtoBaseAccount,
|
||||
map[string][]string{minttypes.ModuleName: {authtypes.Minter}},
|
||||
addresscodec.NewBech32Codec("cosmos"),
|
||||
addresscodec.NewBech32Codec("cosmosvaloper"),
|
||||
"cosmos",
|
||||
authority,
|
||||
)
|
||||
|
||||
@ -78,7 +78,7 @@ func SetupTestSuite(t *testing.T, isCheckTx bool) *AnteTestSuite {
|
||||
}
|
||||
|
||||
suite.accountKeeper = keeper.NewAccountKeeper(
|
||||
suite.encCfg.Codec, runtime.NewKVStoreService(key), types.ProtoBaseAccount, maccPerms, authcodec.NewBech32Codec("cosmos"), authcodec.NewBech32Codec("cosmosvaloper"),
|
||||
suite.encCfg.Codec, runtime.NewKVStoreService(key), types.ProtoBaseAccount, maccPerms, authcodec.NewBech32Codec("cosmos"),
|
||||
sdk.Bech32MainPrefix, types.NewModuleAddress("gov").String(),
|
||||
)
|
||||
suite.accountKeeper.GetModuleAccount(suite.ctx, types.FeeCollectorName)
|
||||
|
||||
@ -74,7 +74,6 @@ func (suite *DeterministicTestSuite) SetupTest() {
|
||||
types.ProtoBaseAccount,
|
||||
maccPerms,
|
||||
authcodec.NewBech32Codec("cosmos"),
|
||||
authcodec.NewBech32Codec("cosmosvaloper"),
|
||||
"cosmos",
|
||||
types.NewModuleAddress("gov").String(),
|
||||
)
|
||||
@ -295,7 +294,6 @@ func (suite *DeterministicTestSuite) TestGRPCQueryModuleAccounts() {
|
||||
types.ProtoBaseAccount,
|
||||
maccPerms,
|
||||
authcodec.NewBech32Codec("cosmos"),
|
||||
authcodec.NewBech32Codec("cosmosvaloper"),
|
||||
"cosmos",
|
||||
types.NewModuleAddress("gov").String(),
|
||||
)
|
||||
@ -343,7 +341,6 @@ func (suite *DeterministicTestSuite) TestGRPCQueryModuleAccountByName() {
|
||||
types.ProtoBaseAccount,
|
||||
maccPerms,
|
||||
authcodec.NewBech32Codec("cosmos"),
|
||||
authcodec.NewBech32Codec("cosmosvaloper"),
|
||||
"cosmos",
|
||||
types.NewModuleAddress("gov").String(),
|
||||
)
|
||||
|
||||
@ -56,9 +56,6 @@ type AccountKeeperI interface {
|
||||
|
||||
// AddressCodec returns the account address codec.
|
||||
AddressCodec() address.Codec
|
||||
|
||||
// ValidatorAddressCodec returns the validator address codec.
|
||||
ValidatorAddressCodec() address.Codec
|
||||
}
|
||||
|
||||
func NewAccountIndexes(sb *collections.SchemaBuilder) AccountsIndexes {
|
||||
@ -86,8 +83,7 @@ func (a AccountsIndexes) IndexesList() []collections.Index[sdk.AccAddress, sdk.A
|
||||
// AccountKeeper encodes/decodes accounts using the go-amino (binary)
|
||||
// encoding/decoding library.
|
||||
type AccountKeeper struct {
|
||||
addressCodec address.Codec
|
||||
validatorAddressCodec address.Codec
|
||||
addressCodec address.Codec
|
||||
|
||||
storeService store.KVStoreService
|
||||
cdc codec.BinaryCodec
|
||||
@ -118,7 +114,7 @@ var _ AccountKeeperI = &AccountKeeper{}
|
||||
// may use auth.Keeper to access the accounts permissions map.
|
||||
func NewAccountKeeper(
|
||||
cdc codec.BinaryCodec, storeService store.KVStoreService, proto func() sdk.AccountI,
|
||||
maccPerms map[string][]string, ac, vac address.Codec, bech32Prefix, authority string,
|
||||
maccPerms map[string][]string, ac address.Codec, bech32Prefix, authority string,
|
||||
) AccountKeeper {
|
||||
permAddrs := make(map[string]types.PermissionsForAddress)
|
||||
for name, perms := range maccPerms {
|
||||
@ -128,17 +124,16 @@ func NewAccountKeeper(
|
||||
sb := collections.NewSchemaBuilder(storeService)
|
||||
|
||||
ak := AccountKeeper{
|
||||
addressCodec: ac,
|
||||
validatorAddressCodec: vac,
|
||||
bech32Prefix: bech32Prefix,
|
||||
storeService: storeService,
|
||||
proto: proto,
|
||||
cdc: cdc,
|
||||
permAddrs: permAddrs,
|
||||
authority: authority,
|
||||
Params: collections.NewItem(sb, types.ParamsKey, "params", codec.CollValue[types.Params](cdc)),
|
||||
AccountNumber: collections.NewSequence(sb, types.GlobalAccountNumberKey, "account_number"),
|
||||
Accounts: collections.NewIndexedMap(sb, types.AddressStoreKeyPrefix, "accounts", sdk.AccAddressKey, codec.CollInterfaceValue[sdk.AccountI](cdc), NewAccountIndexes(sb)),
|
||||
addressCodec: ac,
|
||||
bech32Prefix: bech32Prefix,
|
||||
storeService: storeService,
|
||||
proto: proto,
|
||||
cdc: cdc,
|
||||
permAddrs: permAddrs,
|
||||
authority: authority,
|
||||
Params: collections.NewItem(sb, types.ParamsKey, "params", codec.CollValue[types.Params](cdc)),
|
||||
AccountNumber: collections.NewSequence(sb, types.GlobalAccountNumberKey, "account_number"),
|
||||
Accounts: collections.NewIndexedMap(sb, types.AddressStoreKeyPrefix, "accounts", sdk.AccAddressKey, codec.CollInterfaceValue[sdk.AccountI](cdc), NewAccountIndexes(sb)),
|
||||
}
|
||||
schema, err := sb.Build()
|
||||
if err != nil {
|
||||
@ -159,11 +154,6 @@ func (ak AccountKeeper) AddressCodec() address.Codec {
|
||||
return ak.addressCodec
|
||||
}
|
||||
|
||||
// ValidatorAddressCodec returns the x/auth validator address codec.
|
||||
func (ak AccountKeeper) ValidatorAddressCodec() address.Codec {
|
||||
return ak.validatorAddressCodec
|
||||
}
|
||||
|
||||
// Logger returns a module-specific logger.
|
||||
func (ak AccountKeeper) Logger(ctx context.Context) log.Logger {
|
||||
return sdk.UnwrapSDKContext(ctx).Logger().With("module", "x/"+types.ModuleName)
|
||||
|
||||
@ -66,7 +66,6 @@ func (suite *KeeperTestSuite) SetupTest() {
|
||||
types.ProtoBaseAccount,
|
||||
maccPerms,
|
||||
authcodec.NewBech32Codec("cosmos"),
|
||||
authcodec.NewBech32Codec("cosmosvaloper"),
|
||||
"cosmos",
|
||||
types.NewModuleAddress("gov").String(),
|
||||
)
|
||||
|
||||
@ -195,28 +195,22 @@ func init() {
|
||||
type AddressCodecInputs struct {
|
||||
depinject.In
|
||||
|
||||
Config *modulev1.Module
|
||||
AddressCodecFactory func() address.Codec `optional:"true"`
|
||||
ValidatorAddressCodecFactory func() types.ValidatorAddressCodec `optional:"true"`
|
||||
Config *modulev1.Module
|
||||
AddressCodecFactory func() address.Codec `optional:"true"`
|
||||
}
|
||||
|
||||
// ProvideAddressCodec provides an address.Codec to the container for any
|
||||
// modules that want to do address string <> bytes conversion.
|
||||
func ProvideAddressCodec(in AddressCodecInputs) (address.Codec, types.ValidatorAddressCodec) {
|
||||
if in.AddressCodecFactory != nil && in.ValidatorAddressCodecFactory != nil {
|
||||
return in.AddressCodecFactory(), in.ValidatorAddressCodecFactory()
|
||||
func ProvideAddressCodec(in AddressCodecInputs) address.Codec {
|
||||
if in.AddressCodecFactory != nil {
|
||||
return in.AddressCodecFactory()
|
||||
}
|
||||
|
||||
if (in.AddressCodecFactory != nil && in.ValidatorAddressCodecFactory == nil) ||
|
||||
(in.AddressCodecFactory == nil && in.ValidatorAddressCodecFactory != nil) {
|
||||
panic("either both or none of AddressCodecFactory and ValidatorAddressCodecFactory must be provided")
|
||||
if in.Config.Bech32Prefix == "" {
|
||||
panic("bech32 prefix cannot be empty")
|
||||
}
|
||||
|
||||
if in.Config.Bech32PrefixValidator == "" {
|
||||
in.Config.Bech32PrefixValidator = fmt.Sprintf("%svaloper", in.Config.Bech32Prefix)
|
||||
}
|
||||
|
||||
return authcodec.NewBech32Codec(in.Config.Bech32Prefix), authcodec.NewBech32Codec(in.Config.Bech32PrefixValidator)
|
||||
return authcodec.NewBech32Codec(in.Config.Bech32Prefix)
|
||||
}
|
||||
|
||||
type ModuleInputs struct {
|
||||
@ -227,7 +221,6 @@ type ModuleInputs struct {
|
||||
Cdc codec.Codec
|
||||
|
||||
AddressCodec address.Codec
|
||||
ValidatorAddressCodec types.ValidatorAddressCodec
|
||||
RandomGenesisAccountsFn types.RandomGenesisAccountsFn `optional:"true"`
|
||||
AccountI func() sdk.AccountI `optional:"true"`
|
||||
|
||||
@ -262,11 +255,7 @@ func ProvideModule(in ModuleInputs) ModuleOutputs {
|
||||
in.AccountI = types.ProtoBaseAccount
|
||||
}
|
||||
|
||||
k := keeper.NewAccountKeeper(
|
||||
in.Cdc, in.StoreService, in.AccountI,
|
||||
maccPerms, in.AddressCodec, in.ValidatorAddressCodec,
|
||||
in.Config.Bech32Prefix, authority.String(),
|
||||
)
|
||||
k := keeper.NewAccountKeeper(in.Cdc, in.StoreService, in.AccountI, maccPerms, in.AddressCodec, in.Config.Bech32Prefix, authority.String())
|
||||
m := NewAppModule(in.Cdc, k, in.RandomGenesisAccountsFn, in.LegacySubspace)
|
||||
|
||||
return ModuleOutputs{AccountKeeper: k, Module: m}
|
||||
|
||||
@ -1,6 +0,0 @@
|
||||
package types
|
||||
|
||||
import "cosmossdk.io/core/address"
|
||||
|
||||
// ValidatorAddressCodec is an alias for address.Codec for validator addresses.
|
||||
type ValidatorAddressCodec address.Codec
|
||||
@ -59,7 +59,6 @@ func (s *VestingTestSuite) SetupTest() {
|
||||
authtypes.ProtoBaseAccount,
|
||||
maccPerms,
|
||||
authcodec.NewBech32Codec("cosmos"),
|
||||
authcodec.NewBech32Codec("cosmosvaloper"),
|
||||
"cosmos",
|
||||
authtypes.NewModuleAddress("gov").String(),
|
||||
)
|
||||
|
||||
@ -60,7 +60,6 @@ func (s *VestingAccountTestSuite) SetupTest() {
|
||||
authtypes.ProtoBaseAccount,
|
||||
maccPerms,
|
||||
authcodec.NewBech32Codec("cosmos"),
|
||||
authcodec.NewBech32Codec("cosmosvaloper"),
|
||||
"cosmos",
|
||||
authtypes.NewModuleAddress("gov").String(),
|
||||
)
|
||||
|
||||
@ -79,7 +79,7 @@ func createGroupPolicies(ctx sdk.Context, storeKey storetypes.StoreKey, cdc code
|
||||
|
||||
// createOldPolicyAccount re-creates the group policy account using a module account
|
||||
func createOldPolicyAccount(ctx sdk.Context, storeKey storetypes.StoreKey, cdc codec.Codec, policies []sdk.AccAddress) ([]*authtypes.ModuleAccount, group.AccountKeeper) {
|
||||
accountKeeper := authkeeper.NewAccountKeeper(cdc, runtime.NewKVStoreService(storeKey.(*storetypes.KVStoreKey)), authtypes.ProtoBaseAccount, nil, addresscodec.NewBech32Codec(sdk.Bech32MainPrefix), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), sdk.Bech32MainPrefix, authorityAddr.String())
|
||||
accountKeeper := authkeeper.NewAccountKeeper(cdc, runtime.NewKVStoreService(storeKey.(*storetypes.KVStoreKey)), authtypes.ProtoBaseAccount, nil, addresscodec.NewBech32Codec(sdk.Bech32MainPrefix), sdk.Bech32MainPrefix, authorityAddr.String())
|
||||
|
||||
oldPolicyAccounts := make([]*authtypes.ModuleAccount, len(policies))
|
||||
for i, policyAddr := range policies {
|
||||
|
||||
@ -6,6 +6,7 @@ import (
|
||||
|
||||
abci "github.com/cometbft/cometbft/abci/types"
|
||||
|
||||
addresscodec "cosmossdk.io/core/address"
|
||||
storetypes "cosmossdk.io/core/store"
|
||||
"cosmossdk.io/log"
|
||||
"cosmossdk.io/math"
|
||||
@ -23,12 +24,14 @@ var _ types.DelegationSet = Keeper{}
|
||||
|
||||
// Keeper of the x/staking store
|
||||
type Keeper struct {
|
||||
storeService storetypes.KVStoreService
|
||||
cdc codec.BinaryCodec
|
||||
authKeeper types.AccountKeeper
|
||||
bankKeeper types.BankKeeper
|
||||
hooks types.StakingHooks
|
||||
authority string
|
||||
storeService storetypes.KVStoreService
|
||||
cdc codec.BinaryCodec
|
||||
authKeeper types.AccountKeeper
|
||||
bankKeeper types.BankKeeper
|
||||
hooks types.StakingHooks
|
||||
authority string
|
||||
validatorAddressCodec addresscodec.Codec
|
||||
consensusAddressCodec addresscodec.Codec
|
||||
}
|
||||
|
||||
// NewKeeper creates a new staking Keeper instance
|
||||
@ -38,6 +41,8 @@ func NewKeeper(
|
||||
ak types.AccountKeeper,
|
||||
bk types.BankKeeper,
|
||||
authority string,
|
||||
validatorAddressCodec addresscodec.Codec,
|
||||
consensusAddressCodec addresscodec.Codec,
|
||||
) *Keeper {
|
||||
// ensure bonded and not bonded module accounts are set
|
||||
if addr := ak.GetModuleAddress(types.BondedPoolName); addr == nil {
|
||||
@ -53,13 +58,19 @@ func NewKeeper(
|
||||
panic("authority is not a valid acc address")
|
||||
}
|
||||
|
||||
if validatorAddressCodec == nil || consensusAddressCodec == nil {
|
||||
panic("validator and/or consensus address codec are nil")
|
||||
}
|
||||
|
||||
return &Keeper{
|
||||
storeService: storeService,
|
||||
cdc: cdc,
|
||||
authKeeper: ak,
|
||||
bankKeeper: bk,
|
||||
hooks: nil,
|
||||
authority: authority,
|
||||
storeService: storeService,
|
||||
cdc: cdc,
|
||||
authKeeper: ak,
|
||||
bankKeeper: bk,
|
||||
hooks: nil,
|
||||
authority: authority,
|
||||
validatorAddressCodec: validatorAddressCodec,
|
||||
consensusAddressCodec: consensusAddressCodec,
|
||||
}
|
||||
}
|
||||
|
||||
@ -124,6 +135,16 @@ func (k Keeper) GetAuthority() string {
|
||||
return k.authority
|
||||
}
|
||||
|
||||
// ValidatorAddressCodec returns the app validator address codec.
|
||||
func (k Keeper) ValidatorAddressCodec() addresscodec.Codec {
|
||||
return k.validatorAddressCodec
|
||||
}
|
||||
|
||||
// ConsensusAddressCodec returns the app consensus address codec.
|
||||
func (k Keeper) ConsensusAddressCodec() addresscodec.Codec {
|
||||
return k.consensusAddressCodec
|
||||
}
|
||||
|
||||
// SetValidatorUpdates sets the ABCI validator power updates for the current block.
|
||||
func (k Keeper) SetValidatorUpdates(ctx context.Context, valUpdates []abci.ValidatorUpdate) error {
|
||||
store := k.storeService.OpenKVStore(ctx)
|
||||
|
||||
@ -54,7 +54,6 @@ func (s *KeeperTestSuite) SetupTest() {
|
||||
accountKeeper.EXPECT().GetModuleAddress(stakingtypes.BondedPoolName).Return(bondedAcc.GetAddress())
|
||||
accountKeeper.EXPECT().GetModuleAddress(stakingtypes.NotBondedPoolName).Return(notBondedAcc.GetAddress())
|
||||
accountKeeper.EXPECT().AddressCodec().Return(address.NewBech32Codec("cosmos")).AnyTimes()
|
||||
accountKeeper.EXPECT().ValidatorAddressCodec().Return(address.NewBech32Codec("cosmosvaloper")).AnyTimes()
|
||||
|
||||
bankKeeper := stakingtestutil.NewMockBankKeeper(ctrl)
|
||||
|
||||
@ -64,6 +63,8 @@ func (s *KeeperTestSuite) SetupTest() {
|
||||
accountKeeper,
|
||||
bankKeeper,
|
||||
authtypes.NewModuleAddress(stakingtypes.GovModuleName).String(),
|
||||
address.NewBech32Codec("cosmosvaloper"),
|
||||
address.NewBech32Codec("cosmosvalcons"),
|
||||
)
|
||||
require.NoError(keeper.SetParams(ctx, stakingtypes.DefaultParams()))
|
||||
|
||||
|
||||
@ -188,7 +188,7 @@ func (k Keeper) ApplyAndReturnValidatorSetUpdates(ctx context.Context) (updates
|
||||
}
|
||||
|
||||
// fetch the old power bytes
|
||||
valAddrStr, err := k.authKeeper.ValidatorAddressCodec().BytesToString(valAddr)
|
||||
valAddrStr, err := k.validatorAddressCodec.BytesToString(valAddr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -456,7 +456,7 @@ func (k Keeper) getLastValidatorsByAddr(ctx context.Context) (validatorsByAddr,
|
||||
for ; iterator.Valid(); iterator.Next() {
|
||||
// extract the validator address from the key (prefix is 1-byte, addrLen is 1-byte)
|
||||
valAddr := types.AddressFromLastValidatorPowerKey(iterator.Key())
|
||||
valAddrStr, err := k.authKeeper.ValidatorAddressCodec().BytesToString(valAddr)
|
||||
valAddrStr, err := k.validatorAddressCodec.BytesToString(valAddr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -11,6 +11,7 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
"golang.org/x/exp/maps"
|
||||
|
||||
authmodulev1 "cosmossdk.io/api/cosmos/auth/module/v1"
|
||||
modulev1 "cosmossdk.io/api/cosmos/staking/module/v1"
|
||||
"cosmossdk.io/core/appmodule"
|
||||
"cosmossdk.io/core/store"
|
||||
@ -22,6 +23,7 @@ import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/module"
|
||||
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
|
||||
authcodec "github.com/cosmos/cosmos-sdk/x/auth/codec"
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/client/cli"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/exported"
|
||||
@ -197,18 +199,59 @@ func init() {
|
||||
appmodule.Register(
|
||||
&modulev1.Module{},
|
||||
appmodule.Provide(ProvideModule),
|
||||
appmodule.Provide(ProvideAddressCodec),
|
||||
appmodule.Invoke(InvokeSetStakingHooks),
|
||||
)
|
||||
}
|
||||
|
||||
type AddressCodecInputs struct {
|
||||
depinject.In
|
||||
|
||||
AccountKeeper types.AccountKeeper
|
||||
Config *modulev1.Module
|
||||
AuthConfig *authmodulev1.Module
|
||||
ValidatorAddressCodecFactory func() types.ValidatorAddressCodec `optional:"true"`
|
||||
ConsensusAddressCodecFactory func() types.ConsensusAddressCodec `optional:"true"`
|
||||
}
|
||||
|
||||
// ProvideAddressCodec provides an address.Codec to the container for any
|
||||
// modules that want to do address string <> bytes conversion.
|
||||
func ProvideAddressCodec(in AddressCodecInputs) (types.ValidatorAddressCodec, types.ConsensusAddressCodec) {
|
||||
if in.ValidatorAddressCodecFactory != nil && in.ConsensusAddressCodecFactory != nil {
|
||||
return in.ValidatorAddressCodecFactory(), in.ConsensusAddressCodecFactory()
|
||||
}
|
||||
|
||||
if in.ValidatorAddressCodecFactory != nil || in.ConsensusAddressCodecFactory != nil {
|
||||
panic("either both or none of validator and consensus address codecs must be provided")
|
||||
}
|
||||
|
||||
if in.AuthConfig.Bech32Prefix != "" {
|
||||
if in.Config.Bech32PrefixValidator == "" {
|
||||
in.Config.Bech32PrefixValidator = fmt.Sprintf("%svaloper", in.AuthConfig.Bech32Prefix)
|
||||
}
|
||||
|
||||
if in.Config.Bech32PrefixConsensus == "" {
|
||||
in.Config.Bech32PrefixConsensus = fmt.Sprintf("%svalcons", in.AuthConfig.Bech32Prefix)
|
||||
}
|
||||
}
|
||||
|
||||
if in.Config.Bech32PrefixValidator == "" || in.Config.Bech32PrefixConsensus == "" {
|
||||
panic("bech32 prefixes for validator and/or consensus addresses must be provided (cannot fallback to auth bech32 prefixes)")
|
||||
}
|
||||
|
||||
return authcodec.NewBech32Codec(in.Config.Bech32PrefixValidator), authcodec.NewBech32Codec(in.Config.Bech32PrefixConsensus)
|
||||
}
|
||||
|
||||
type ModuleInputs struct {
|
||||
depinject.In
|
||||
|
||||
Config *modulev1.Module
|
||||
AccountKeeper types.AccountKeeper
|
||||
BankKeeper types.BankKeeper
|
||||
Cdc codec.Codec
|
||||
StoreService store.KVStoreService
|
||||
Config *modulev1.Module
|
||||
ValidatorAddressCodec types.ValidatorAddressCodec
|
||||
ConsensusAddressCodec types.ConsensusAddressCodec
|
||||
AccountKeeper types.AccountKeeper
|
||||
BankKeeper types.BankKeeper
|
||||
Cdc codec.Codec
|
||||
StoreService store.KVStoreService
|
||||
|
||||
// LegacySubspace is used solely for migration of x/params managed parameters
|
||||
LegacySubspace exported.Subspace `optional:"true"`
|
||||
@ -235,6 +278,8 @@ func ProvideModule(in ModuleInputs) ModuleOutputs {
|
||||
in.AccountKeeper,
|
||||
in.BankKeeper,
|
||||
authority.String(),
|
||||
in.ValidatorAddressCodec,
|
||||
in.ConsensusAddressCodec,
|
||||
)
|
||||
m := NewAppModule(in.Cdc, k, in.AccountKeeper, in.BankKeeper, in.LegacySubspace)
|
||||
return ModuleOutputs{StakingKeeper: k, Module: m}
|
||||
|
||||
@ -169,20 +169,6 @@ func (mr *MockAccountKeeperMockRecorder) SetModuleAccount(arg0, arg1 interface{}
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetModuleAccount", reflect.TypeOf((*MockAccountKeeper)(nil).SetModuleAccount), arg0, arg1)
|
||||
}
|
||||
|
||||
// ValidatorAddressCodec mocks base method.
|
||||
func (m *MockAccountKeeper) ValidatorAddressCodec() address.Codec {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "ValidatorAddressCodec")
|
||||
ret0, _ := ret[0].(address.Codec)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// ValidatorAddressCodec indicates an expected call of ValidatorAddressCodec.
|
||||
func (mr *MockAccountKeeperMockRecorder) ValidatorAddressCodec() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidatorAddressCodec", reflect.TypeOf((*MockAccountKeeper)(nil).ValidatorAddressCodec))
|
||||
}
|
||||
|
||||
// MockBankKeeper is a mock of BankKeeper interface.
|
||||
type MockBankKeeper struct {
|
||||
ctrl *gomock.Controller
|
||||
|
||||
11
x/staking/types/depinject_alias.go
Normal file
11
x/staking/types/depinject_alias.go
Normal file
@ -0,0 +1,11 @@
|
||||
package types
|
||||
|
||||
import "cosmossdk.io/core/address"
|
||||
|
||||
type (
|
||||
// ValidatorAddressCodec is an alias for address.Codec for validator addresses.
|
||||
ValidatorAddressCodec address.Codec
|
||||
|
||||
// ConsensusAddressCodec is an alias for address.Codec for validator consensus addresses.
|
||||
ConsensusAddressCodec address.Codec
|
||||
)
|
||||
@ -18,7 +18,6 @@ type DistributionKeeper interface {
|
||||
// AccountKeeper defines the expected account keeper (noalias)
|
||||
type AccountKeeper interface {
|
||||
AddressCodec() address.Codec
|
||||
ValidatorAddressCodec() address.Codec
|
||||
|
||||
IterateAccounts(ctx context.Context, process func(sdk.AccountI) (stop bool))
|
||||
GetAccount(ctx context.Context, addr sdk.AccAddress) sdk.AccountI // only used for simulation
|
||||
|
||||
Loading…
Reference in New Issue
Block a user