cosmos-sdk/x/params/keeper/keeper.go
Aaron Craelius 816c5a37bd
Enable proto JSON generally and remove HybridCodec (#6859)
* Remove HybridCodec

* WIP on fixing proto JSON issues

* WIP on fixing proto JSON issues

* WIP on fixing proto JSON issues

* WIP on fixing proto JSON issues

* WIP on fixing proto JSON issues

* Test fixes

* Delete hybrid_codec.go

* Fixes

* Fixes

* Fixes

* Test fixes

* Test fixes

* Test fixes

* Lint

* Sim fixes

* Sim fixes

* Revert

* Remove vesting account JSON tests

* Update CHANGELOG.md

* Lint

* Sim fixes

* Sim fixes

* Docs

* Migrate more amino usages

* Remove custom VoteOption String() and json marshaling

* Fix tests

* Add comments, update CHANGELOG.md

Co-authored-by: Jonathan Gimeno <jgimeno@gmail.com>
Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>
2020-08-13 13:20:02 +00:00

64 lines
1.5 KiB
Go

package keeper
import (
"fmt"
"github.com/tendermint/tendermint/libs/log"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/cosmos/cosmos-sdk/x/params/types/proposal"
)
// Keeper of the global paramstore
type Keeper struct {
cdc codec.BinaryMarshaler
legacyAmino *codec.LegacyAmino
key sdk.StoreKey
tkey sdk.StoreKey
spaces map[string]*types.Subspace
}
// NewKeeper constructs a params keeper
func NewKeeper(cdc codec.BinaryMarshaler, legacyAmino *codec.LegacyAmino, key, tkey sdk.StoreKey) Keeper {
return Keeper{
cdc: cdc,
legacyAmino: legacyAmino,
key: key,
tkey: tkey,
spaces: make(map[string]*types.Subspace),
}
}
// Logger returns a module-specific logger.
func (k Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", fmt.Sprintf("x/%s", proposal.ModuleName))
}
// Allocate subspace used for keepers
func (k Keeper) Subspace(s string) types.Subspace {
_, ok := k.spaces[s]
if ok {
panic("subspace already occupied")
}
if s == "" {
panic("cannot use empty string for subspace")
}
space := types.NewSubspace(k.cdc, k.legacyAmino, k.key, k.tkey, s)
k.spaces[s] = &space
return space
}
// Get existing substore from keeper
func (k Keeper) GetSubspace(s string) (types.Subspace, bool) {
space, ok := k.spaces[s]
if !ok {
return types.Subspace{}, false
}
return *space, ok
}