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
|
|
|
|
2018-09-18 04:16:20 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/params/store"
|
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-09-18 04:16:20 -07:00
|
|
|
stores map[string]*Store
|
2018-07-13 17:12:23 -07:00
|
|
|
}
|
|
|
|
|
2018-09-26 08:36:26 -07:00
|
|
|
// NewKeeper constructs a params keeper
|
2018-08-31 02:03:43 -07:00
|
|
|
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-09-18 04:16:20 -07:00
|
|
|
stores: make(map[string]*Store),
|
2018-07-13 17:12:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return k
|
|
|
|
}
|
|
|
|
|
2018-08-31 02:03:43 -07:00
|
|
|
// Allocate substore used for keepers
|
2018-10-06 08:32:41 -07:00
|
|
|
func (k Keeper) Substore(storename string, table Table) Store {
|
2018-09-18 04:16:20 -07:00
|
|
|
_, ok := k.stores[storename]
|
2018-08-31 02:03:43 -07:00
|
|
|
if ok {
|
2018-09-18 04:16:20 -07:00
|
|
|
panic("substore already occupied")
|
2018-07-13 17:12:23 -07:00
|
|
|
}
|
|
|
|
|
2018-09-18 04:16:20 -07:00
|
|
|
if storename == "" {
|
|
|
|
panic("cannot use empty string for substore")
|
2018-07-13 17:12:23 -07:00
|
|
|
}
|
|
|
|
|
2018-10-06 08:32:41 -07:00
|
|
|
store := store.NewStore(k.cdc, k.key, k.tkey, storename, table)
|
2018-07-13 17:12:23 -07:00
|
|
|
|
2018-09-18 04:16:20 -07:00
|
|
|
k.stores[storename] = &store
|
2018-07-13 17:12:23 -07:00
|
|
|
|
2018-09-18 04:16:20 -07:00
|
|
|
return store
|
2018-07-13 17:12:23 -07:00
|
|
|
}
|
2018-09-10 04:59:05 -07:00
|
|
|
|
2018-09-18 04:16:20 -07:00
|
|
|
// Get existing substore from keeper
|
|
|
|
func (k Keeper) GetSubstore(storename string) (Store, bool) {
|
|
|
|
store, ok := k.stores[storename]
|
2018-09-10 04:59:05 -07:00
|
|
|
if !ok {
|
2018-09-18 04:16:20 -07:00
|
|
|
return Store{}, false
|
2018-09-10 04:59:05 -07:00
|
|
|
}
|
2018-09-18 04:16:20 -07:00
|
|
|
return *store, ok
|
2018-09-10 04:59:05 -07:00
|
|
|
}
|