* stake/fees spec updates * staking overview.md revisions, moving files * docs reorganization * staking spec state revisions * transaction stake updates * complete staking spec update * WIP adding unbonding/redelegation commands * added msg types for unbonding, redelegation * stake sub-package reorg * working stake reorg * modify lcd tests to not use hardcoded json strings * add description update * index keys * key managment for unbonding redelegation complete * update stake errors * completed handleMsgCompleteUnbonding fn * updated to use begin/complete unbonding/redelegation * fix token shares bug * develop docs into unbonding * got non-tests compiling after merge develop * working fixing tests * PrivlegedKeeper -> PrivilegedKeeper * tests compile * fix some tests * fixing tests * remove PrivilegedKeeper * get unbonding bug * only rpc sig verification failed tests now * move percent unbonding/redelegation to the CLI and out of handler logic * remove min unbonding height * add lcd txs * add pool sanity checks, fix a buncha tests * fix ante. set lcd log to debug (#1322) * redelegation tests, adding query functionality for bonds * add self-delegations at genesis ref #1165 * PR comments (mostly) addressed * cleanup, added Query LCD functionality * test cleanup/fixes * fix governance test * SlashValidatorSet -> ValidatorSet * changelog * stake lcd fix * x/auth: fix chainID in ante * fix lcd test * fix lint, update lint make command for spelling * lowercase error string * don't expose coinkeeper in staking * remove a few duplicate lines in changelog * chain_id in stake lcd tests * added transient redelegation * 'transient' => 'transitive' * Re-add nolint instruction * Fix tiny linter error
123 lines
3.2 KiB
Go
123 lines
3.2 KiB
Go
package keeper
|
|
|
|
import (
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
"github.com/cosmos/cosmos-sdk/wire"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/bank"
|
|
"github.com/cosmos/cosmos-sdk/x/stake/types"
|
|
)
|
|
|
|
// keeper of the stake store
|
|
type Keeper struct {
|
|
storeKey sdk.StoreKey
|
|
cdc *wire.Codec
|
|
coinKeeper bank.Keeper
|
|
|
|
// codespace
|
|
codespace sdk.CodespaceType
|
|
}
|
|
|
|
func NewKeeper(cdc *wire.Codec, key sdk.StoreKey, ck bank.Keeper, codespace sdk.CodespaceType) Keeper {
|
|
keeper := Keeper{
|
|
storeKey: key,
|
|
cdc: cdc,
|
|
coinKeeper: ck,
|
|
codespace: codespace,
|
|
}
|
|
return keeper
|
|
}
|
|
|
|
//_________________________________________________________________________
|
|
|
|
// return the codespace
|
|
func (k Keeper) Codespace() sdk.CodespaceType {
|
|
return k.codespace
|
|
}
|
|
|
|
//_________________________________________________________________________
|
|
// some generic reads/writes that don't need their own files
|
|
|
|
// load/save the global staking params
|
|
func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) {
|
|
store := ctx.KVStore(k.storeKey)
|
|
|
|
b := store.Get(ParamKey)
|
|
if b == nil {
|
|
panic("Stored params should not have been nil")
|
|
}
|
|
|
|
k.cdc.MustUnmarshalBinary(b, ¶ms)
|
|
return
|
|
}
|
|
|
|
// Need a distinct function because setParams depends on an existing previous
|
|
// record of params to exist (to check if maxValidators has changed) - and we
|
|
// panic on retrieval if it doesn't exist - hence if we use setParams for the very
|
|
// first params set it will panic.
|
|
func (k Keeper) SetNewParams(ctx sdk.Context, params types.Params) {
|
|
store := ctx.KVStore(k.storeKey)
|
|
b := k.cdc.MustMarshalBinary(params)
|
|
store.Set(ParamKey, b)
|
|
}
|
|
|
|
// set the params
|
|
func (k Keeper) SetParams(ctx sdk.Context, params types.Params) {
|
|
store := ctx.KVStore(k.storeKey)
|
|
exParams := k.GetParams(ctx)
|
|
|
|
// if max validator count changes, must recalculate validator set
|
|
if exParams.MaxValidators != params.MaxValidators {
|
|
k.UpdateBondedValidatorsFull(ctx)
|
|
}
|
|
b := k.cdc.MustMarshalBinary(params)
|
|
store.Set(ParamKey, b)
|
|
}
|
|
|
|
//_______________________________________________________________________
|
|
|
|
// 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)
|
|
}
|