2018-10-19 11:36:00 -07:00
|
|
|
package mint
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/params"
|
|
|
|
)
|
|
|
|
|
2019-05-02 13:50:01 -07:00
|
|
|
var minterKey = []byte{0x00} // the one key to use for the keeper store
|
|
|
|
|
2019-04-01 10:28:36 -07:00
|
|
|
const (
|
|
|
|
// default paramspace for params keeper
|
2019-05-16 08:25:32 -07:00
|
|
|
DefaultParamspace = ModuleName
|
2019-04-01 10:28:36 -07:00
|
|
|
|
|
|
|
// StoreKey is the default store key for mint
|
2019-05-16 08:25:32 -07:00
|
|
|
StoreKey = ModuleName
|
2019-04-01 10:28:36 -07:00
|
|
|
|
|
|
|
// QuerierRoute is the querier route for the minting store.
|
|
|
|
QuerierRoute = StoreKey
|
|
|
|
)
|
|
|
|
|
2019-01-11 12:08:01 -08:00
|
|
|
// keeper of the staking store
|
2018-10-19 11:36:00 -07:00
|
|
|
type Keeper struct {
|
|
|
|
storeKey sdk.StoreKey
|
|
|
|
cdc *codec.Codec
|
|
|
|
paramSpace params.Subspace
|
2019-01-11 12:08:01 -08:00
|
|
|
sk StakingKeeper
|
2018-10-19 11:36:00 -07:00
|
|
|
fck FeeCollectionKeeper
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewKeeper(cdc *codec.Codec, key sdk.StoreKey,
|
2019-01-11 12:08:01 -08:00
|
|
|
paramSpace params.Subspace, sk StakingKeeper, fck FeeCollectionKeeper) Keeper {
|
2018-10-19 11:36:00 -07:00
|
|
|
|
|
|
|
keeper := Keeper{
|
|
|
|
storeKey: key,
|
|
|
|
cdc: cdc,
|
2019-02-04 18:13:04 -08:00
|
|
|
paramSpace: paramSpace.WithKeyTable(ParamKeyTable()),
|
2018-10-19 11:36:00 -07:00
|
|
|
sk: sk,
|
|
|
|
fck: fck,
|
|
|
|
}
|
|
|
|
return keeper
|
|
|
|
}
|
|
|
|
|
|
|
|
//______________________________________________________________________
|
|
|
|
|
|
|
|
// get the minter
|
2019-04-05 13:20:58 -07:00
|
|
|
func (k Keeper) GetMinter(ctx sdk.Context) (minter Minter) {
|
2018-10-19 11:36:00 -07:00
|
|
|
store := ctx.KVStore(k.storeKey)
|
|
|
|
b := store.Get(minterKey)
|
|
|
|
if b == nil {
|
2019-05-16 08:25:32 -07:00
|
|
|
panic("stored minter should not have been nil")
|
2018-10-19 11:36:00 -07:00
|
|
|
}
|
2018-11-04 18:28:38 -08:00
|
|
|
k.cdc.MustUnmarshalBinaryLengthPrefixed(b, &minter)
|
2018-10-19 11:36:00 -07:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// set the minter
|
|
|
|
func (k Keeper) SetMinter(ctx sdk.Context, minter Minter) {
|
|
|
|
store := ctx.KVStore(k.storeKey)
|
2018-11-04 18:28:38 -08:00
|
|
|
b := k.cdc.MustMarshalBinaryLengthPrefixed(minter)
|
2018-10-19 11:36:00 -07:00
|
|
|
store.Set(minterKey, b)
|
|
|
|
}
|
|
|
|
|
|
|
|
//______________________________________________________________________
|
|
|
|
|
2019-05-16 08:25:32 -07:00
|
|
|
// GetParams returns the total set of minting parameters.
|
2019-05-02 13:50:01 -07:00
|
|
|
func (k Keeper) GetParams(ctx sdk.Context) (params Params) {
|
|
|
|
k.paramSpace.GetParamSet(ctx, ¶ms)
|
2019-04-05 13:20:58 -07:00
|
|
|
return params
|
2018-10-19 11:36:00 -07:00
|
|
|
}
|
|
|
|
|
2019-05-16 08:25:32 -07:00
|
|
|
// SetParams sets the total set of minting parameters.
|
2019-04-05 13:20:58 -07:00
|
|
|
func (k Keeper) SetParams(ctx sdk.Context, params Params) {
|
2019-05-02 13:50:01 -07:00
|
|
|
k.paramSpace.SetParamSet(ctx, ¶ms)
|
2018-10-19 11:36:00 -07:00
|
|
|
}
|