cosmos-sdk/x/distribution/keeper/keeper.go

130 lines
3.7 KiB
Go
Raw Normal View History

2018-09-03 17:46:33 -07:00
package keeper
import (
2018-09-19 16:00:21 -07:00
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/distribution/types"
2018-09-18 21:42:05 -07:00
"github.com/cosmos/cosmos-sdk/x/params"
)
// keeper of the stake store
type Keeper struct {
2018-09-19 19:13:12 -07:00
storeKey sdk.StoreKey
cdc *codec.Codec
paramSpace params.Subspace
2018-09-19 19:13:12 -07:00
bankKeeper types.BankKeeper
stakeKeeper types.StakeKeeper
feeCollectionKeeper types.FeeCollectionKeeper
// codespace
codespace sdk.CodespaceType
}
func NewKeeper(cdc *codec.Codec, key sdk.StoreKey, paramSpace params.Subspace, ck types.BankKeeper,
2018-09-19 19:13:12 -07:00
sk types.StakeKeeper, fck types.FeeCollectionKeeper, codespace sdk.CodespaceType) Keeper {
keeper := Keeper{
2018-09-19 19:13:12 -07:00
storeKey: key,
cdc: cdc,
paramSpace: paramSpace.WithTypeTable(ParamTypeTable()),
2018-09-19 19:13:12 -07:00
bankKeeper: ck,
stakeKeeper: sk,
feeCollectionKeeper: fck,
codespace: codespace,
}
return keeper
}
//______________________________________________________________________
2018-09-04 23:41:17 -07:00
// get the global fee pool distribution info
2018-09-05 16:15:15 -07:00
func (k Keeper) GetFeePool(ctx sdk.Context) (feePool types.FeePool) {
store := ctx.KVStore(k.storeKey)
2018-09-13 00:03:30 -07:00
b := store.Get(FeePoolKey)
if b == nil {
2018-09-04 23:41:17 -07:00
panic("Stored fee pool should not have been nil")
}
2018-09-04 23:41:17 -07:00
k.cdc.MustUnmarshalBinary(b, &feePool)
return
}
2018-09-04 23:41:17 -07:00
// set the global fee pool distribution info
2018-09-05 16:15:15 -07:00
func (k Keeper) SetFeePool(ctx sdk.Context, feePool types.FeePool) {
store := ctx.KVStore(k.storeKey)
2018-09-04 23:41:17 -07:00
b := k.cdc.MustMarshalBinary(feePool)
2018-09-13 00:03:30 -07:00
store.Set(FeePoolKey, b)
}
//______________________________________________________________________
2018-09-13 23:35:02 -07:00
// set the proposer public key for this block
func (k Keeper) GetPreviousProposerConsAddr(ctx sdk.Context) (consAddr sdk.ConsAddress) {
store := ctx.KVStore(k.storeKey)
2018-09-13 23:35:02 -07:00
b := store.Get(ProposerKey)
2018-09-13 23:35:02 -07:00
if b == nil {
panic("Previous proposer not set")
2018-09-13 23:35:02 -07:00
}
k.cdc.MustUnmarshalBinary(b, &consAddr)
return
}
// get the proposer public key for this block
func (k Keeper) SetPreviousProposerConsAddr(ctx sdk.Context, consAddr sdk.ConsAddress) {
store := ctx.KVStore(k.storeKey)
2018-09-13 23:35:02 -07:00
b := k.cdc.MustMarshalBinary(consAddr)
store.Set(ProposerKey, b)
}
//______________________________________________________________________
// PARAM STORE
// Type declaration for parameters
func ParamTypeTable() params.TypeTable {
return params.NewTypeTable(
ParamStoreKeyCommunityTax, sdk.Dec{},
2018-10-15 13:12:42 -07:00
ParamStoreKeyBaseProposerReward, sdk.Dec{},
ParamStoreKeyBonusProposerReward, sdk.Dec{},
)
}
// Returns the current CommunityTax rate from the global param store
2018-09-18 21:42:05 -07:00
// nolint: errcheck
func (k Keeper) GetCommunityTax(ctx sdk.Context) sdk.Dec {
2018-10-15 13:12:42 -07:00
var percent sdk.Dec
k.paramSpace.Get(ctx, ParamStoreKeyCommunityTax, &percent)
return percent
2018-09-18 21:42:05 -07:00
}
// nolint: errcheck
2018-10-15 13:12:42 -07:00
func (k Keeper) SetCommunityTax(ctx sdk.Context, percent sdk.Dec) {
k.paramSpace.Set(ctx, ParamStoreKeyCommunityTax, &percent)
}
// Returns the current BaseProposerReward rate from the global param store
// nolint: errcheck
func (k Keeper) GetBaseProposerReward(ctx sdk.Context) sdk.Dec {
var percent sdk.Dec
k.paramSpace.Get(ctx, ParamStoreKeyBaseProposerReward, &percent)
return percent
}
// nolint: errcheck
func (k Keeper) SetBaseProposerReward(ctx sdk.Context, percent sdk.Dec) {
k.paramSpace.Set(ctx, ParamStoreKeyBaseProposerReward, &percent)
}
// Returns the current BaseProposerReward rate from the global param store
// nolint: errcheck
func (k Keeper) GetBonusProposerReward(ctx sdk.Context) sdk.Dec {
var percent sdk.Dec
k.paramSpace.Get(ctx, ParamStoreKeyBonusProposerReward, &percent)
return percent
}
// nolint: errcheck
func (k Keeper) SetBonusProposerReward(ctx sdk.Context, percent sdk.Dec) {
k.paramSpace.Set(ctx, ParamStoreKeyBonusProposerReward, &percent)
2018-09-18 21:42:05 -07:00
}