2018-07-13 17:12:23 -07:00
|
|
|
package params
|
|
|
|
|
|
|
|
import (
|
2018-09-13 11:17:32 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
2018-07-13 17:12:23 -07:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2018-08-31 02:03:43 -07:00
|
|
|
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/params/space"
|
2018-07-13 17:12:23 -07:00
|
|
|
)
|
|
|
|
|
2018-08-31 02:03:43 -07:00
|
|
|
// Keeper of the global paramstore
|
2018-07-13 17:12:23 -07:00
|
|
|
type Keeper struct {
|
2018-08-31 02:03:43 -07:00
|
|
|
cdc *codec.Codec
|
|
|
|
key sdk.StoreKey
|
|
|
|
tkey sdk.StoreKey
|
2018-07-13 17:12:23 -07:00
|
|
|
|
2018-08-31 02:03:43 -07:00
|
|
|
spaces map[string]*Space
|
2018-07-13 17:12:23 -07:00
|
|
|
}
|
|
|
|
|
2018-08-31 02:03:43 -07:00
|
|
|
// NewKeeper construct a params keeper
|
|
|
|
func NewKeeper(cdc *codec.Codec, key *sdk.KVStoreKey, tkey *sdk.TransientStoreKey) (k Keeper) {
|
|
|
|
k = Keeper{
|
|
|
|
cdc: cdc,
|
|
|
|
key: key,
|
|
|
|
tkey: tkey,
|
2018-07-13 17:12:23 -07:00
|
|
|
|
2018-08-31 02:03:43 -07:00
|
|
|
spaces: make(map[string]*Space),
|
2018-07-13 17:12:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return k
|
|
|
|
}
|
|
|
|
|
2018-08-31 02:03:43 -07:00
|
|
|
// Allocate substore used for keepers
|
2018-09-10 04:59:05 -07:00
|
|
|
func (k Keeper) Subspace(spacename string) Space {
|
|
|
|
_, ok := k.spaces[spacename]
|
2018-08-31 02:03:43 -07:00
|
|
|
if ok {
|
|
|
|
panic("subspace already occupied")
|
2018-07-13 17:12:23 -07:00
|
|
|
}
|
|
|
|
|
2018-08-31 02:03:43 -07:00
|
|
|
if spacename == "" {
|
|
|
|
panic("cannot use empty string for subspace")
|
2018-07-13 17:12:23 -07:00
|
|
|
}
|
|
|
|
|
2018-08-31 02:03:43 -07:00
|
|
|
space := space.NewSpace(k.cdc, k.key, k.tkey, spacename)
|
2018-07-13 17:12:23 -07:00
|
|
|
|
2018-08-31 02:03:43 -07:00
|
|
|
k.spaces[spacename] = &space
|
2018-07-13 17:12:23 -07:00
|
|
|
|
2018-08-31 02:03:43 -07:00
|
|
|
return space
|
2018-07-13 17:12:23 -07:00
|
|
|
}
|
2018-09-10 04:59:05 -07:00
|
|
|
|
|
|
|
// Get existing subspace from keeper
|
|
|
|
func (k Keeper) GetSubspace(spacename string) (Space, bool) {
|
|
|
|
space, ok := k.spaces[spacename]
|
|
|
|
if !ok {
|
|
|
|
return Space{}, false
|
|
|
|
}
|
|
|
|
return *space, ok
|
|
|
|
}
|