2018-06-26 19:00:12 -07:00
|
|
|
package keeper
|
|
|
|
|
|
|
|
import (
|
2018-09-13 11:17:32 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
2018-06-26 19:00:12 -07:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/bank"
|
2018-08-31 02:03:43 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/params"
|
2018-06-26 19:00:12 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/stake/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
// keeper of the stake store
|
|
|
|
type Keeper struct {
|
2018-09-24 21:09:31 -07:00
|
|
|
storeKey sdk.StoreKey
|
|
|
|
storeTKey sdk.StoreKey
|
|
|
|
cdc *codec.Codec
|
|
|
|
bankKeeper bank.Keeper
|
2018-09-25 23:11:57 -07:00
|
|
|
hooks sdk.StakingHooks
|
2018-10-10 13:01:30 -07:00
|
|
|
paramstore params.Subspace
|
2018-06-26 19:00:12 -07:00
|
|
|
|
2018-09-18 10:16:51 -07:00
|
|
|
// codespace
|
|
|
|
codespace sdk.CodespaceType
|
2018-06-26 19:00:12 -07:00
|
|
|
}
|
|
|
|
|
2018-10-10 13:01:30 -07:00
|
|
|
func NewKeeper(cdc *codec.Codec, key, tkey sdk.StoreKey, ck bank.Keeper, paramstore params.Subspace, codespace sdk.CodespaceType) Keeper {
|
2018-06-26 19:00:12 -07:00
|
|
|
keeper := Keeper{
|
2018-09-24 21:09:31 -07:00
|
|
|
storeKey: key,
|
|
|
|
storeTKey: tkey,
|
|
|
|
cdc: cdc,
|
|
|
|
bankKeeper: ck,
|
2018-10-10 13:01:30 -07:00
|
|
|
paramstore: paramstore.WithTypeTable(ParamTypeTable()),
|
2018-09-24 21:09:31 -07:00
|
|
|
hooks: nil,
|
2018-09-18 10:16:51 -07:00
|
|
|
codespace: codespace,
|
2018-06-26 19:00:12 -07:00
|
|
|
}
|
|
|
|
return keeper
|
|
|
|
}
|
|
|
|
|
2018-08-31 17:01:23 -07:00
|
|
|
// Set the validator hooks
|
2018-09-25 23:11:57 -07:00
|
|
|
func (k Keeper) WithHooks(sh sdk.StakingHooks) Keeper {
|
2018-09-24 21:09:31 -07:00
|
|
|
if k.hooks != nil {
|
2018-08-31 17:01:23 -07:00
|
|
|
panic("cannot set validator hooks twice")
|
|
|
|
}
|
2018-09-24 21:09:31 -07:00
|
|
|
k.hooks = sh
|
2018-08-31 17:01:23 -07:00
|
|
|
return k
|
|
|
|
}
|
|
|
|
|
2018-06-26 19:00:12 -07:00
|
|
|
//_________________________________________________________________________
|
|
|
|
|
2018-09-18 10:16:51 -07:00
|
|
|
// return the codespace
|
2018-06-26 19:00:12 -07:00
|
|
|
func (k Keeper) Codespace() sdk.CodespaceType {
|
2018-09-18 10:16:51 -07:00
|
|
|
return k.codespace
|
2018-06-26 19:00:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//_______________________________________________________________________
|
|
|
|
|
|
|
|
// load/save the pool
|
|
|
|
func (k Keeper) GetPool(ctx sdk.Context) (pool types.Pool) {
|
|
|
|
store := ctx.KVStore(k.storeKey)
|
|
|
|
b := store.Get(PoolKey)
|
|
|
|
if b == nil {
|
|
|
|
panic("Stored pool should not have been nil")
|
|
|
|
}
|
|
|
|
k.cdc.MustUnmarshalBinary(b, &pool)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// set the pool
|
|
|
|
func (k Keeper) SetPool(ctx sdk.Context, pool types.Pool) {
|
|
|
|
store := ctx.KVStore(k.storeKey)
|
|
|
|
b := k.cdc.MustMarshalBinary(pool)
|
|
|
|
store.Set(PoolKey, b)
|
|
|
|
}
|
|
|
|
|
|
|
|
//__________________________________________________________________________
|
|
|
|
|
|
|
|
// get the current in-block validator operation counter
|
|
|
|
func (k Keeper) InitIntraTxCounter(ctx sdk.Context) {
|
|
|
|
store := ctx.KVStore(k.storeKey)
|
|
|
|
b := store.Get(IntraTxCounterKey)
|
|
|
|
if b == nil {
|
|
|
|
k.SetIntraTxCounter(ctx, 0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// get the current in-block validator operation counter
|
|
|
|
func (k Keeper) GetIntraTxCounter(ctx sdk.Context) int16 {
|
|
|
|
store := ctx.KVStore(k.storeKey)
|
|
|
|
b := store.Get(IntraTxCounterKey)
|
|
|
|
var counter int16
|
|
|
|
k.cdc.MustUnmarshalBinary(b, &counter)
|
|
|
|
return counter
|
|
|
|
}
|
|
|
|
|
|
|
|
// set the current in-block validator operation counter
|
|
|
|
func (k Keeper) SetIntraTxCounter(ctx sdk.Context, counter int16) {
|
|
|
|
store := ctx.KVStore(k.storeKey)
|
|
|
|
bz := k.cdc.MustMarshalBinary(counter)
|
|
|
|
store.Set(IntraTxCounterKey, bz)
|
|
|
|
}
|