diff --git a/x/gov/keeper.go b/x/gov/keeper.go index fbdf795554..0a31d5bf2c 100644 --- a/x/gov/keeper.go +++ b/x/gov/keeper.go @@ -7,9 +7,9 @@ import ( "github.com/cosmos/cosmos-sdk/x/params" ) -// Parameter store default namespace +// Parameter store default namestore const ( - DefaultParamSpace = "gov" + DefaultParamspace = "gov" ) // Parameter store key @@ -25,7 +25,7 @@ type Keeper struct { pk params.Keeper // The reference to the Paramstore to get and set gov specific params - ps params.Space + ps params.Store // The reference to the CoinKeeper to modify balances ck bank.Keeper @@ -42,8 +42,8 @@ type Keeper struct { // The codec codec for binary encoding/decoding. cdc *codec.Codec - // Reserved codespace - codespace sdk.CodespaceType + // Reserved codestore + codestore sdk.CodespaceType } // NewKeeper returns a governance keeper. It handles: @@ -51,7 +51,7 @@ type Keeper struct { // - depositing funds into proposals, and activating upon sufficient funds being deposited // - users voting on proposals, with weight proportional to stake in the system // - and tallying the result of the vote. -func NewKeeper(cdc *codec.Codec, key sdk.StoreKey, pk params.Keeper, ps params.Space, ck bank.Keeper, ds sdk.DelegationSet, codespace sdk.CodespaceType) Keeper { +func NewKeeper(cdc *codec.Codec, key sdk.StoreKey, pk params.Keeper, ps params.Store, ck bank.Keeper, ds sdk.DelegationSet, codestore sdk.CodespaceType) Keeper { return Keeper{ storeKey: key, pk: pk, @@ -60,7 +60,7 @@ func NewKeeper(cdc *codec.Codec, key sdk.StoreKey, pk params.Keeper, ps params.S ds: ds, vs: ds.GetValidatorSet(), cdc: cdc, - codespace: codespace, + codestore: codestore, } } @@ -164,7 +164,7 @@ func (keeper Keeper) setInitialProposalID(ctx sdk.Context, proposalID int64) sdk store := ctx.KVStore(keeper.storeKey) bz := store.Get(KeyNextProposalID) if bz != nil { - return ErrInvalidGenesis(keeper.codespace, "Initial ProposalID already set") + return ErrInvalidGenesis(keeper.codestore, "Initial ProposalID already set") } bz = keeper.cdc.MustMarshalBinary(proposalID) store.Set(KeyNextProposalID, bz) @@ -186,7 +186,7 @@ func (keeper Keeper) getNewProposalID(ctx sdk.Context) (proposalID int64, err sd store := ctx.KVStore(keeper.storeKey) bz := store.Get(KeyNextProposalID) if bz == nil { - return -1, ErrInvalidGenesis(keeper.codespace, "InitialProposalID never set") + return -1, ErrInvalidGenesis(keeper.codestore, "InitialProposalID never set") } keeper.cdc.MustUnmarshalBinary(bz, &proposalID) bz = keeper.cdc.MustMarshalBinary(proposalID + 1) @@ -199,7 +199,7 @@ func (keeper Keeper) peekCurrentProposalID(ctx sdk.Context) (proposalID int64, e store := ctx.KVStore(keeper.storeKey) bz := store.Get(KeyNextProposalID) if bz == nil { - return -1, ErrInvalidGenesis(keeper.codespace, "InitialProposalID never set") + return -1, ErrInvalidGenesis(keeper.codestore, "InitialProposalID never set") } keeper.cdc.MustUnmarshalBinary(bz, &proposalID) return proposalID, nil @@ -261,14 +261,14 @@ func (keeper Keeper) setTallyingProcedure(ctx sdk.Context, tallyingProcedure Tal func (keeper Keeper) AddVote(ctx sdk.Context, proposalID int64, voterAddr sdk.AccAddress, option VoteOption) sdk.Error { proposal := keeper.GetProposal(ctx, proposalID) if proposal == nil { - return ErrUnknownProposal(keeper.codespace, proposalID) + return ErrUnknownProposal(keeper.codestore, proposalID) } if proposal.GetStatus() != StatusVotingPeriod { - return ErrInactiveProposal(keeper.codespace, proposalID) + return ErrInactiveProposal(keeper.codestore, proposalID) } if !validVoteOption(option) { - return ErrInvalidVote(keeper.codespace, option) + return ErrInvalidVote(keeper.codestore, option) } vote := Vote{ @@ -337,12 +337,12 @@ func (keeper Keeper) AddDeposit(ctx sdk.Context, proposalID int64, depositerAddr // Checks to see if proposal exists proposal := keeper.GetProposal(ctx, proposalID) if proposal == nil { - return ErrUnknownProposal(keeper.codespace, proposalID), false + return ErrUnknownProposal(keeper.codestore, proposalID), false } // Check if proposal is still depositable if (proposal.GetStatus() != StatusDepositPeriod) && (proposal.GetStatus() != StatusVotingPeriod) { - return ErrAlreadyFinishedProposal(keeper.codespace, proposalID), false + return ErrAlreadyFinishedProposal(keeper.codestore, proposalID), false } // Subtract coins from depositer's account diff --git a/x/gov/simulation/sim_test.go b/x/gov/simulation/sim_test.go index 280f73bf90..382b3efcdd 100644 --- a/x/gov/simulation/sim_test.go +++ b/x/gov/simulation/sim_test.go @@ -30,9 +30,9 @@ func TestGovWithRandomMessages(t *testing.T) { paramKey := sdk.NewKVStoreKey("params") paramTKey := sdk.NewTransientStoreKey("transient_params") paramKeeper := params.NewKeeper(mapp.Cdc, paramKey, paramTKey) - stakeKeeper := stake.NewKeeper(mapp.Cdc, stakeKey, stakeTKey, bankKeeper, paramKeeper.Subspace(stake.DefaultParamSpace), stake.DefaultCodespace) + stakeKeeper := stake.NewKeeper(mapp.Cdc, stakeKey, stakeTKey, bankKeeper, paramKeeper.Substore(stake.DefaultParamspace), stake.DefaultCodespace) govKey := sdk.NewKVStoreKey("gov") - govKeeper := gov.NewKeeper(mapp.Cdc, govKey, paramKeeper, paramKeeper.Subspace(gov.DefaultParamSpace), bankKeeper, stakeKeeper, gov.DefaultCodespace) + govKeeper := gov.NewKeeper(mapp.Cdc, govKey, paramKeeper, paramKeeper.Substore(gov.DefaultParamspace), bankKeeper, stakeKeeper, gov.DefaultCodespace) mapp.Router().AddRoute("gov", gov.NewHandler(govKeeper)) mapp.SetEndBlocker(func(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock { gov.EndBlocker(ctx, govKeeper) diff --git a/x/gov/test_common.go b/x/gov/test_common.go index 45c885971f..7ee68627b4 100644 --- a/x/gov/test_common.go +++ b/x/gov/test_common.go @@ -34,8 +34,8 @@ func getMockApp(t *testing.T, numGenAccs int) (*mock.App, Keeper, stake.Keeper, pk := params.NewKeeper(mapp.Cdc, keyGlobalParams, tkeyGlobalParams) ck := bank.NewBaseKeeper(mapp.AccountMapper) - sk := stake.NewKeeper(mapp.Cdc, keyStake, tkeyStake, ck, pk.Subspace(stake.DefaultParamSpace), mapp.RegisterCodespace(stake.DefaultCodespace)) - keeper := NewKeeper(mapp.Cdc, keyGov, pk, pk.Subspace("testgov"), ck, sk, DefaultCodespace) + sk := stake.NewKeeper(mapp.Cdc, keyStake, tkeyStake, ck, pk.Substore(stake.DefaultParamspace), mapp.RegisterCodespace(stake.DefaultCodespace)) + keeper := NewKeeper(mapp.Cdc, keyGov, pk, pk.Substore("testgov"), ck, sk, DefaultCodespace) mapp.Router().AddRoute("gov", NewHandler(keeper)) diff --git a/x/params/doc.go b/x/params/doc.go index 1843abce9d..64b3312233 100644 --- a/x/params/doc.go +++ b/x/params/doc.go @@ -3,12 +3,75 @@ package params /* Package params provides a globally available parameter store . -There are two main types, Keeper and Space. Space is an isolated namespace, prefixed by preconfigured spacename. Keeper has a permission to access all existing spaces and create new space. +There are two main types, Keeper and Space. Space is an isolated namespace for a paramstore, where keys are prefixed by preconfigured spacename. Keeper has a permission to access all existing spaces and create new space. Space can be used by the individual keepers, who needs a private parameter store that the other keeper are not able to modify. Keeper can be used by the Governance keeper, who need to modify any parameter in case of the proposal passes. Basic Usage: +First, declare parameter space and parameter keys for the module. Then include params.Store in the keeper. Since we prefix the keys with the spacename, it is recommended to use the same name with the module's. + const ( + DefaultParamspace = "mymodule" + ) + + const ( + KeyParameter1 = "myparameter1" + KeyParameter2 = "myparameter2" + ) + + type Keeper struct { + cdc *wire.Codec + key sdk.StoreKey + + ps params.Store + } + +Pass a params.Store to NewKeeper with DefaultParamSpace(or another) + + app.myKeeper = mymodule.NewKeeper(app.paramStore.SubStore(mymodule.DefaultParamspace)) + +Now we can access to the paramstore using Paramstore Keys + + k.ps.Get(KeyParameter1, ¶m) + k.ps.Set(KeyParameter2, param) + +Genesis Usage: + +Declare a struct for parameters and make it implement ParamStruct. It will then be able to be passed to SetFromParamStruct. + + type MyParams struct { + Parameter1 uint64 + Parameter2 string + } + + func (p *MyParams) KeyFieldPairs() params.KeyFieldPairs { + return params.KeyFieldPairs { + {KeyParameter1, &p.Parameter1}, + {KeyParameter2, &p.Parameter2}, + } + } + + func InitGenesis(ctx sdk.Context, k Keeper, data GenesisState) { + k.ps.SetFromParamStruct(ctx, &data.params) + } + +The method is pointer receiver because there could be a case that we read from the store and set the result to the struct. + +Master Permission Usage: + +Keepers those requires master permission to the paramstore, such as gov, can take params.Keeper itself to access all substores(using GetSubstore) + + type MasterKeeper struct { + ps params.Store + } + + func (k MasterKeeper) SetParam(ctx sdk.Context, space string, key string, param interface{}) { + store, ok := k.ps.GetSubstore(space) + if !ok { + return + } + store.Set(ctx, key, param) + } */ diff --git a/x/params/keeper.go b/x/params/keeper.go index 97b17f9a03..8677c63d53 100644 --- a/x/params/keeper.go +++ b/x/params/keeper.go @@ -4,7 +4,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/params/space" + "github.com/cosmos/cosmos-sdk/x/params/store" ) // Keeper of the global paramstore @@ -13,7 +13,7 @@ type Keeper struct { key sdk.StoreKey tkey sdk.StoreKey - spaces map[string]*Space + stores map[string]*Store } // NewKeeper construct a params keeper @@ -23,35 +23,35 @@ func NewKeeper(cdc *codec.Codec, key *sdk.KVStoreKey, tkey *sdk.TransientStoreKe key: key, tkey: tkey, - spaces: make(map[string]*Space), + stores: make(map[string]*Store), } return k } // Allocate substore used for keepers -func (k Keeper) Subspace(spacename string) Space { - _, ok := k.spaces[spacename] +func (k Keeper) Substore(storename string) Store { + _, ok := k.stores[storename] if ok { - panic("subspace already occupied") + panic("substore already occupied") } - if spacename == "" { - panic("cannot use empty string for subspace") + if storename == "" { + panic("cannot use empty string for substore") } - space := space.NewSpace(k.cdc, k.key, k.tkey, spacename) + store := store.NewStore(k.cdc, k.key, k.tkey, storename) - k.spaces[spacename] = &space + k.stores[storename] = &store - return space + return store } -// Get existing subspace from keeper -func (k Keeper) GetSubspace(spacename string) (Space, bool) { - space, ok := k.spaces[spacename] +// Get existing substore from keeper +func (k Keeper) GetSubstore(storename string) (Store, bool) { + store, ok := k.stores[storename] if !ok { - return Space{}, false + return Store{}, false } - return *space, ok + return *store, ok } diff --git a/x/params/keeper_test.go b/x/params/keeper_test.go index 29c05d111e..2372b68978 100644 --- a/x/params/keeper_test.go +++ b/x/params/keeper_test.go @@ -44,29 +44,29 @@ func TestKeeper(t *testing.T) { {"key3", 182}, {"key4", 17582}, {"key5", 2768554}, - {"space1/key1", 1157279}, - {"space1/key2", 9058701}, + {"store1/key1", 1157279}, + {"store1/key2", 9058701}, } skey := sdk.NewKVStoreKey("test") tkey := sdk.NewTransientStoreKey("transient_test") ctx := defaultContext(skey, tkey) - space := NewKeeper(codec.New(), skey, tkey).Subspace("test") + store := NewKeeper(codec.New(), skey, tkey).Substore("test") for _, kv := range kvs { - require.NotPanics(t, func() { space.Set(ctx, kv.key, kv.param) }) + require.NotPanics(t, func() { store.Set(ctx, kv.key, kv.param) }) } for _, kv := range kvs { var param int64 - require.NotPanics(t, func() { space.Get(ctx, kv.key, ¶m) }) + require.NotPanics(t, func() { store.Get(ctx, kv.key, ¶m) }) require.Equal(t, kv.param, param) } cdc := codec.New() for _, kv := range kvs { var param int64 - bz := space.GetRaw(ctx, kv.key) + bz := store.GetRaw(ctx, kv.key) err := cdc.UnmarshalJSON(bz, ¶m) require.Nil(t, err) require.Equal(t, kv.param, param) @@ -74,11 +74,11 @@ func TestKeeper(t *testing.T) { for _, kv := range kvs { var param bool - require.Panics(t, func() { space.Get(ctx, kv.key, ¶m) }) + require.Panics(t, func() { store.Get(ctx, kv.key, ¶m) }) } for _, kv := range kvs { - require.Panics(t, func() { space.Set(ctx, kv.key, true) }) + require.Panics(t, func() { store.Set(ctx, kv.key, true) }) } } @@ -88,7 +88,7 @@ func TestGet(t *testing.T) { ctx := defaultContext(key, tkey) keeper := NewKeeper(createTestCodec(), key, tkey) - space := keeper.Subspace("test") + store := keeper.Substore("test") kvs := []struct { key string @@ -112,24 +112,24 @@ func TestGet(t *testing.T) { } for _, kv := range kvs { - require.NotPanics(t, func() { space.Set(ctx, kv.key, kv.param) }) + require.NotPanics(t, func() { store.Set(ctx, kv.key, kv.param) }) } for _, kv := range kvs { - require.NotPanics(t, func() { space.GetIfExists(ctx, "invalid", kv.ptr) }) + require.NotPanics(t, func() { store.GetIfExists(ctx, "invalid", kv.ptr) }) require.Equal(t, kv.zero, reflect.ValueOf(kv.ptr).Elem().Interface()) - require.Panics(t, func() { space.Get(ctx, "invalid", kv.ptr) }) + require.Panics(t, func() { store.Get(ctx, "invalid", kv.ptr) }) require.Equal(t, kv.zero, reflect.ValueOf(kv.ptr).Elem().Interface()) - require.NotPanics(t, func() { space.GetIfExists(ctx, kv.key, kv.ptr) }) + require.NotPanics(t, func() { store.GetIfExists(ctx, kv.key, kv.ptr) }) require.Equal(t, kv.param, reflect.ValueOf(kv.ptr).Elem().Interface()) - require.NotPanics(t, func() { space.Get(ctx, kv.key, kv.ptr) }) + require.NotPanics(t, func() { store.Get(ctx, kv.key, kv.ptr) }) require.Equal(t, kv.param, reflect.ValueOf(kv.ptr).Elem().Interface()) - require.Panics(t, func() { space.Get(ctx, "invalid", kv.ptr) }) + require.Panics(t, func() { store.Get(ctx, "invalid", kv.ptr) }) require.Equal(t, kv.param, reflect.ValueOf(kv.ptr).Elem().Interface()) - require.Panics(t, func() { space.Get(ctx, kv.key, nil) }) - require.Panics(t, func() { space.Get(ctx, kv.key, new(s)) }) + require.Panics(t, func() { store.Get(ctx, kv.key, nil) }) + require.Panics(t, func() { store.Get(ctx, kv.key, new(s)) }) } } diff --git a/x/params/space.go b/x/params/space.go deleted file mode 100644 index b993493380..0000000000 --- a/x/params/space.go +++ /dev/null @@ -1,17 +0,0 @@ -package params - -import ( - "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/x/params/space" -) - -// nolint - reexport -type Space = space.Space -type ReadOnlySpace = space.ReadOnlySpace -type ParamStruct = space.ParamStruct -type KeyFieldPairs = space.KeyFieldPairs - -// nolint - reexport -func UnmarshalParamsFromMap(m map[string][]byte, cdc *codec.Codec, ps space.ParamStruct) error { - return space.UnmarshalParamsFromMap(m, cdc, ps) -} diff --git a/x/params/store.go b/x/params/store.go new file mode 100644 index 0000000000..39b2c2a510 --- /dev/null +++ b/x/params/store.go @@ -0,0 +1,17 @@ +package params + +import ( + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/x/params/store" +) + +// nolint - reexport +type Store = store.Store +type ReadOnlyStore = store.ReadOnlyStore +type ParamStruct = store.ParamStruct +type KeyFieldPairs = store.KeyFieldPairs + +// nolint - reexport +func UnmarshalParamsFromMap(m map[string][]byte, cdc *codec.Codec, ps store.ParamStruct) error { + return store.UnmarshalParamsFromMap(m, cdc, ps) +} diff --git a/x/params/space/doc.go b/x/params/store/doc.go similarity index 97% rename from x/params/space/doc.go rename to x/params/store/doc.go index c02b69e7e9..67a64e0a17 100644 --- a/x/params/space/doc.go +++ b/x/params/store/doc.go @@ -1,4 +1,4 @@ -package space +package store /* To prevent namespace collision between comsumer modules, we define type diff --git a/x/params/space/pair.go b/x/params/store/pair.go similarity index 97% rename from x/params/space/pair.go rename to x/params/store/pair.go index c37c599fe3..97e56d2a74 100644 --- a/x/params/space/pair.go +++ b/x/params/store/pair.go @@ -1,4 +1,4 @@ -package space +package store import ( "github.com/cosmos/cosmos-sdk/codec" diff --git a/x/params/space/space.go b/x/params/store/store.go similarity index 52% rename from x/params/space/space.go rename to x/params/store/store.go index ca3757f443..c91827a997 100644 --- a/x/params/space/space.go +++ b/x/params/store/store.go @@ -1,4 +1,4 @@ -package space +package store import ( "fmt" @@ -11,32 +11,32 @@ import ( ) // Individual parameter store for each keeper -type Space struct { +type Store struct { cdc *codec.Codec key sdk.StoreKey tkey sdk.StoreKey - space []byte + store []byte } -// NewSpace constructs a store with namespace -func NewSpace(cdc *codec.Codec, key sdk.StoreKey, tkey sdk.StoreKey, space string) Space { - if !tmlibs.IsASCIIText(space) { - panic("paramstore space expressions can only contain alphanumeric characters") +// NewStore constructs a store with namestore +func NewStore(cdc *codec.Codec, key sdk.StoreKey, tkey sdk.StoreKey, store string) Store { + if !tmlibs.IsASCIIText(store) { + panic("paramstore store expressions can only contain alphanumeric characters") } - return Space{ + return Store{ cdc: cdc, key: key, tkey: tkey, - space: append([]byte(space), '/'), + store: append([]byte(store), '/'), } } // Get parameter from store -func (s Space) Get(ctx sdk.Context, key string, ptr interface{}) { - store := ctx.KVStore(s.key).Prefix(s.space) +func (s Store) Get(ctx sdk.Context, key string, ptr interface{}) { + store := ctx.KVStore(s.key).Prefix(s.store) bz := store.Get([]byte(key)) err := s.cdc.UnmarshalJSON(bz, ptr) if err != nil { @@ -45,8 +45,8 @@ func (s Space) Get(ctx sdk.Context, key string, ptr interface{}) { } // GetIfExists do not modify ptr if the stored parameter is nil -func (s Space) GetIfExists(ctx sdk.Context, key string, ptr interface{}) { - store := ctx.KVStore(s.key).Prefix(s.space) +func (s Store) GetIfExists(ctx sdk.Context, key string, ptr interface{}) { + store := ctx.KVStore(s.key).Prefix(s.store) bz := store.Get([]byte(key)) if bz == nil { return @@ -58,27 +58,27 @@ func (s Space) GetIfExists(ctx sdk.Context, key string, ptr interface{}) { } // Get raw bytes of parameter from store -func (s Space) GetRaw(ctx sdk.Context, key string) []byte { - store := ctx.KVStore(s.key).Prefix(s.space) +func (s Store) GetRaw(ctx sdk.Context, key string) []byte { + store := ctx.KVStore(s.key).Prefix(s.store) res := store.Get([]byte(key)) return res } // Check if the parameter is set in the store -func (s Space) Has(ctx sdk.Context, key string) bool { - store := ctx.KVStore(s.key).Prefix(s.space) +func (s Store) Has(ctx sdk.Context, key string) bool { + store := ctx.KVStore(s.key).Prefix(s.store) return store.Has([]byte(key)) } // Returns true if the parameter is set in the block -func (s Space) Modified(ctx sdk.Context, key string) bool { - tstore := ctx.KVStore(s.tkey).Prefix(s.space) +func (s Store) Modified(ctx sdk.Context, key string) bool { + tstore := ctx.KVStore(s.tkey).Prefix(s.store) return tstore.Has([]byte(key)) } // Set parameter, return error if stored parameter has different type from input -func (s Space) Set(ctx sdk.Context, key string, param interface{}) { - store := ctx.KVStore(s.key).Prefix(s.space) +func (s Store) Set(ctx sdk.Context, key string, param interface{}) { + store := ctx.KVStore(s.key).Prefix(s.store) keybz := []byte(key) bz := store.Get(keybz) @@ -97,54 +97,54 @@ func (s Space) Set(ctx sdk.Context, key string, param interface{}) { } store.Set(keybz, bz) - tstore := ctx.KVStore(s.tkey).Prefix(s.space) + tstore := ctx.KVStore(s.tkey).Prefix(s.store) tstore.Set(keybz, []byte{}) } // Set raw bytes of parameter -func (s Space) SetRaw(ctx sdk.Context, key string, param []byte) { +func (s Store) SetRaw(ctx sdk.Context, key string, param []byte) { keybz := []byte(key) - store := ctx.KVStore(s.key).Prefix(s.space) + store := ctx.KVStore(s.key).Prefix(s.store) store.Set(keybz, param) - tstore := ctx.KVStore(s.tkey).Prefix(s.space) + tstore := ctx.KVStore(s.tkey).Prefix(s.store) tstore.Set(keybz, []byte{}) } // Set from ParamStruct -func (s Space) SetFromParamStruct(ctx sdk.Context, ps ParamStruct) { +func (s Store) SetFromParamStruct(ctx sdk.Context, ps ParamStruct) { for _, pair := range ps.KeyFieldPairs() { s.Set(ctx, pair.Key, pair.Field) } } -// Returns a KVStore identical with the paramspace -func (s Space) KVStore(ctx sdk.Context) sdk.KVStore { - return ctx.KVStore(s.key).Prefix(s.space) +// Returns a KVStore identical with the paramstore +func (s Store) KVStore(ctx sdk.Context) sdk.KVStore { + return ctx.KVStore(s.key).Prefix(s.store) } -// Wrapper of Space, provides immutable functions only -type ReadOnlySpace struct { - s Space +// Wrapper of Store, provides immutable functions only +type ReadOnlyStore struct { + s Store } // Exposes Get -func (ros ReadOnlySpace) Get(ctx sdk.Context, key string, ptr interface{}) { +func (ros ReadOnlyStore) Get(ctx sdk.Context, key string, ptr interface{}) { ros.s.Get(ctx, key, ptr) } // Exposes GetRaw -func (ros ReadOnlySpace) GetRaw(ctx sdk.Context, key string) []byte { +func (ros ReadOnlyStore) GetRaw(ctx sdk.Context, key string) []byte { return ros.s.GetRaw(ctx, key) } // Exposes Has -func (ros ReadOnlySpace) Has(ctx sdk.Context, key string) bool { +func (ros ReadOnlyStore) Has(ctx sdk.Context, key string) bool { return ros.s.Has(ctx, key) } // Exposes Modified -func (ros ReadOnlySpace) Modified(ctx sdk.Context, key string) bool { +func (ros ReadOnlyStore) Modified(ctx sdk.Context, key string) bool { return ros.s.Modified(ctx, key) } diff --git a/x/params/space/test_common.go b/x/params/store/test_common.go similarity index 85% rename from x/params/space/test_common.go rename to x/params/store/test_common.go index c006e3f057..2e82c78275 100644 --- a/x/params/space/test_common.go +++ b/x/params/store/test_common.go @@ -1,4 +1,4 @@ -package space +package store import ( "os" @@ -17,11 +17,11 @@ import ( // Keys for parameter access const ( - TestParamSpace = "ParamsTest" + TestParamStore = "ParamsTest" ) // Returns components for testing -func DefaultTestComponents(t *testing.T) (sdk.Context, Space, func() sdk.CommitID) { +func DefaultTestComponents(t *testing.T) (sdk.Context, Store, func() sdk.CommitID) { cdc := codec.New() key := sdk.NewKVStoreKey("params") tkey := sdk.NewTransientStoreKey("tparams") @@ -34,7 +34,7 @@ func DefaultTestComponents(t *testing.T) (sdk.Context, Space, func() sdk.CommitI err := ms.LoadLatestVersion() require.Nil(t, err) ctx := sdk.NewContext(ms, abci.Header{}, false, log.NewTMLogger(os.Stdout)) - store := NewSpace(cdc, key, tkey, TestParamSpace) + store := NewStore(cdc, key, tkey, TestParamStore) return ctx, store, ms.Commit } diff --git a/x/slashing/app_test.go b/x/slashing/app_test.go index ecdb6c79f1..8c7b11753c 100644 --- a/x/slashing/app_test.go +++ b/x/slashing/app_test.go @@ -34,8 +34,8 @@ func getMockApp(t *testing.T) (*mock.App, stake.Keeper, Keeper) { bankKeeper := bank.NewBaseKeeper(mapp.AccountMapper) paramsKeeper := params.NewKeeper(mapp.Cdc, keyParams, tkeyParams) - stakeKeeper := stake.NewKeeper(mapp.Cdc, keyStake, tkeyStake, bankKeeper, paramsKeeper.Subspace(stake.DefaultParamSpace), mapp.RegisterCodespace(stake.DefaultCodespace)) - keeper := NewKeeper(mapp.Cdc, keySlashing, stakeKeeper, paramsKeeper.Subspace(DefaultParamSpace), mapp.RegisterCodespace(DefaultCodespace)) + stakeKeeper := stake.NewKeeper(mapp.Cdc, keyStake, tkeyStake, bankKeeper, paramsKeeper.Substore(stake.DefaultParamspace), mapp.RegisterCodespace(stake.DefaultCodespace)) + keeper := NewKeeper(mapp.Cdc, keySlashing, stakeKeeper, paramsKeeper.Substore(DefaultParamspace), mapp.RegisterCodespace(DefaultCodespace)) mapp.Router().AddRoute("stake", stake.NewHandler(stakeKeeper)) mapp.Router().AddRoute("slashing", NewHandler(keeper)) diff --git a/x/slashing/keeper.go b/x/slashing/keeper.go index 93bff70a2e..a46889c765 100644 --- a/x/slashing/keeper.go +++ b/x/slashing/keeper.go @@ -18,14 +18,14 @@ type Keeper struct { storeKey sdk.StoreKey cdc *codec.Codec validatorSet sdk.ValidatorSet - paramstore params.Space + paramstore params.Store // codespace codespace sdk.CodespaceType } // NewKeeper creates a slashing keeper -func NewKeeper(cdc *codec.Codec, key sdk.StoreKey, vs sdk.ValidatorSet, paramstore params.Space, codespace sdk.CodespaceType) Keeper { +func NewKeeper(cdc *codec.Codec, key sdk.StoreKey, vs sdk.ValidatorSet, paramstore params.Store, codespace sdk.CodespaceType) Keeper { keeper := Keeper{ storeKey: key, cdc: cdc, diff --git a/x/slashing/params.go b/x/slashing/params.go index 5366b16555..dfc5237625 100644 --- a/x/slashing/params.go +++ b/x/slashing/params.go @@ -9,7 +9,7 @@ import ( // Default parameter namespace const ( - DefaultParamSpace = "slashing" + DefaultParamspace = "slashing" ) // Parameter store key diff --git a/x/slashing/test_common.go b/x/slashing/test_common.go index ea3316aef2..9dcddd9d05 100644 --- a/x/slashing/test_common.go +++ b/x/slashing/test_common.go @@ -49,7 +49,7 @@ func createTestCodec() *codec.Codec { return cdc } -func createTestInput(t *testing.T, defaults Params) (sdk.Context, bank.Keeper, stake.Keeper, params.Space, Keeper) { +func createTestInput(t *testing.T, defaults Params) (sdk.Context, bank.Keeper, stake.Keeper, params.Store, Keeper) { keyAcc := sdk.NewKVStoreKey("acc") keyStake := sdk.NewKVStoreKey("stake") tkeyStake := sdk.NewTransientStoreKey("transient_stake") @@ -71,7 +71,7 @@ func createTestInput(t *testing.T, defaults Params) (sdk.Context, bank.Keeper, s accountMapper := auth.NewAccountMapper(cdc, keyAcc, auth.ProtoBaseAccount) ck := bank.NewBaseKeeper(accountMapper) - paramstore := params.NewKeeper(cdc, keyParams, tkeyParams).Subspace(DefaultParamSpace) + paramstore := params.NewKeeper(cdc, keyParams, tkeyParams).Substore(DefaultParamspace) sk := stake.NewKeeper(cdc, keyStake, tkeyStake, ck, paramstore, stake.DefaultCodespace) genesis := stake.DefaultGenesisState() diff --git a/x/stake/app_test.go b/x/stake/app_test.go index 1251e45625..0e09dfaa80 100644 --- a/x/stake/app_test.go +++ b/x/stake/app_test.go @@ -45,7 +45,7 @@ func getMockApp(t *testing.T) (*mock.App, Keeper) { bankKeeper := bank.NewBaseKeeper(mApp.AccountMapper) pk := params.NewKeeper(mApp.Cdc, keyParams, tkeyParams) - keeper := NewKeeper(mApp.Cdc, keyStake, tkeyStake, bankKeeper, pk.Subspace("stake"), mApp.RegisterCodespace(DefaultCodespace)) + keeper := NewKeeper(mApp.Cdc, keyStake, tkeyStake, bankKeeper, pk.Substore("stake"), mApp.RegisterCodespace(DefaultCodespace)) mApp.Router().AddRoute("stake", NewHandler(keeper)) mApp.SetEndBlocker(getEndBlocker(keeper)) diff --git a/x/stake/keeper/keeper.go b/x/stake/keeper/keeper.go index e3f2ed9c01..a349797c6b 100644 --- a/x/stake/keeper/keeper.go +++ b/x/stake/keeper/keeper.go @@ -16,13 +16,13 @@ type Keeper struct { cdc *codec.Codec bankKeeper bank.Keeper hooks sdk.StakingHooks - paramstore params.Space + paramstore params.Store - // codespace - codespace sdk.CodespaceType + // codestore + codestore sdk.CodespaceType } -func NewKeeper(cdc *codec.Codec, key, tkey sdk.StoreKey, ck bank.Keeper, paramstore params.Space, codespace sdk.CodespaceType) Keeper { +func NewKeeper(cdc *codec.Codec, key, tkey sdk.StoreKey, ck bank.Keeper, paramstore params.Store, codestore sdk.CodespaceType) Keeper { keeper := Keeper{ storeKey: key, storeTKey: tkey, @@ -30,7 +30,7 @@ func NewKeeper(cdc *codec.Codec, key, tkey sdk.StoreKey, ck bank.Keeper, paramst bankKeeper: ck, paramstore: paramstore, hooks: nil, - codespace: codespace, + codestore: codestore, } return keeper } @@ -46,9 +46,9 @@ func (k Keeper) WithHooks(sh sdk.StakingHooks) Keeper { //_________________________________________________________________________ -// return the codespace +// return the codestore func (k Keeper) Codespace() sdk.CodespaceType { - return k.codespace + return k.codestore } //_______________________________________________________________________ diff --git a/x/stake/keeper/params.go b/x/stake/keeper/params.go index a6b1eec1f6..1a42450a8f 100644 --- a/x/stake/keeper/params.go +++ b/x/stake/keeper/params.go @@ -9,7 +9,7 @@ import ( // Default parameter namespace const ( - DefaultParamSpace = "stake" + DefaultParamspace = "stake" ) // InflationRateChange - Maximum annual change in inflation rate diff --git a/x/stake/keeper/test_common.go b/x/stake/keeper/test_common.go index 58977cd3c2..8856f4863e 100644 --- a/x/stake/keeper/test_common.go +++ b/x/stake/keeper/test_common.go @@ -117,7 +117,7 @@ func CreateTestInput(t *testing.T, isCheckTx bool, initCoins int64) (sdk.Context ck := bank.NewBaseKeeper(accountMapper) pk := params.NewKeeper(cdc, keyParams, tkeyParams) - keeper := NewKeeper(cdc, keyStake, tkeyStake, ck, pk.Subspace("stake"), types.DefaultCodespace) + keeper := NewKeeper(cdc, keyStake, tkeyStake, ck, pk.Substore("stake"), types.DefaultCodespace) keeper.SetPool(ctx, types.InitialPool()) keeper.SetParams(ctx, types.DefaultParams()) keeper.InitIntraTxCounter(ctx) diff --git a/x/stake/simulation/sim_test.go b/x/stake/simulation/sim_test.go index aba0c9eb70..8120a8a2bb 100644 --- a/x/stake/simulation/sim_test.go +++ b/x/stake/simulation/sim_test.go @@ -27,7 +27,7 @@ func TestStakeWithRandomMessages(t *testing.T) { paramsKey := sdk.NewKVStoreKey("params") paramsTKey := sdk.NewTransientStoreKey("transient_params") - paramstore := params.NewKeeper(mapp.Cdc, paramsKey, paramsTKey).Subspace(stake.DefaultParamSpace) + paramstore := params.NewKeeper(mapp.Cdc, paramsKey, paramsTKey).Substore(stake.DefaultParamspace) stakeKeeper := stake.NewKeeper(mapp.Cdc, stakeKey, stakeTKey, bankKeeper, paramstore, stake.DefaultCodespace) mapp.Router().AddRoute("stake", stake.NewHandler(stakeKeeper)) mapp.SetEndBlocker(func(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock { diff --git a/x/stake/stake.go b/x/stake/stake.go index ffe7a45903..c518ad4d29 100644 --- a/x/stake/stake.go +++ b/x/stake/stake.go @@ -59,7 +59,7 @@ var ( GetREDsToValDstIndexKey = keeper.GetREDsToValDstIndexKey GetREDsByDelToValDstIndexKey = keeper.GetREDsByDelToValDstIndexKey - DefaultParamSpace = keeper.DefaultParamSpace + DefaultParamspace = keeper.DefaultParamspace KeyInflationRateChange = types.KeyInflationRateChange KeyInflationMax = types.KeyInflationMax KeyGoalBonded = types.KeyGoalBonded