2020-02-19 03:52:20 -08:00
|
|
|
package keeper
|
2018-07-13 17:12:23 -07:00
|
|
|
|
|
|
|
import (
|
2019-06-26 09:41:14 -07:00
|
|
|
"fmt"
|
|
|
|
|
2020-02-19 03:52:20 -08:00
|
|
|
"github.com/tendermint/tendermint/libs/log"
|
|
|
|
|
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"
|
2019-06-26 09:41:14 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/params/types"
|
2020-02-19 03:52:20 -08:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/params/types/proposal"
|
2018-12-19 11:58:30 -08: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 {
|
2020-08-13 06:20:02 -07:00
|
|
|
cdc codec.BinaryMarshaler
|
|
|
|
legacyAmino *codec.LegacyAmino
|
|
|
|
key sdk.StoreKey
|
|
|
|
tkey sdk.StoreKey
|
|
|
|
spaces map[string]*types.Subspace
|
2018-07-13 17:12:23 -07:00
|
|
|
}
|
|
|
|
|
2018-09-26 08:36:26 -07:00
|
|
|
// NewKeeper constructs a params keeper
|
2020-08-13 06:20:02 -07:00
|
|
|
func NewKeeper(cdc codec.BinaryMarshaler, legacyAmino *codec.LegacyAmino, key, tkey sdk.StoreKey) Keeper {
|
2019-12-10 08:48:57 -08:00
|
|
|
return Keeper{
|
2020-08-13 06:20:02 -07:00
|
|
|
cdc: cdc,
|
|
|
|
legacyAmino: legacyAmino,
|
|
|
|
key: key,
|
|
|
|
tkey: tkey,
|
|
|
|
spaces: make(map[string]*types.Subspace),
|
2018-07-13 17:12:23 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-30 09:31:38 -07:00
|
|
|
// Logger returns a module-specific logger.
|
|
|
|
func (k Keeper) Logger(ctx sdk.Context) log.Logger {
|
2020-02-19 03:52:20 -08:00
|
|
|
return ctx.Logger().With("module", fmt.Sprintf("x/%s", proposal.ModuleName))
|
2019-04-30 09:31:38 -07:00
|
|
|
}
|
|
|
|
|
2018-10-10 13:01:30 -07:00
|
|
|
// Allocate subspace used for keepers
|
2020-02-19 03:52:20 -08:00
|
|
|
func (k Keeper) Subspace(s string) types.Subspace {
|
2019-04-30 09:31:38 -07:00
|
|
|
_, ok := k.spaces[s]
|
2018-08-31 02:03:43 -07:00
|
|
|
if ok {
|
2018-10-10 13:01:30 -07:00
|
|
|
panic("subspace already occupied")
|
2018-07-13 17:12:23 -07:00
|
|
|
}
|
|
|
|
|
2019-04-30 09:31:38 -07:00
|
|
|
if s == "" {
|
2018-10-10 13:01:30 -07:00
|
|
|
panic("cannot use empty string for subspace")
|
2018-07-13 17:12:23 -07:00
|
|
|
}
|
|
|
|
|
2020-08-13 06:20:02 -07:00
|
|
|
space := types.NewSubspace(k.cdc, k.legacyAmino, k.key, k.tkey, s)
|
2019-04-30 09:31:38 -07:00
|
|
|
k.spaces[s] = &space
|
2018-07-13 17:12:23 -07:00
|
|
|
|
2018-10-10 13:01:30 -07:00
|
|
|
return space
|
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
|
2020-02-19 03:52:20 -08:00
|
|
|
func (k Keeper) GetSubspace(s string) (types.Subspace, bool) {
|
2019-04-30 09:31:38 -07:00
|
|
|
space, ok := k.spaces[s]
|
2018-09-10 04:59:05 -07:00
|
|
|
if !ok {
|
2020-02-19 03:52:20 -08:00
|
|
|
return types.Subspace{}, false
|
2018-09-10 04:59:05 -07:00
|
|
|
}
|
2018-10-10 13:01:30 -07:00
|
|
|
return *space, ok
|
2018-09-10 04:59:05 -07:00
|
|
|
}
|