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

119 lines
3.4 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
storeTKey sdk.StoreKey
cdc *codec.Codec
ps params.Setter
bankKeeper types.BankKeeper
stakeKeeper types.StakeKeeper
feeCollectionKeeper types.FeeCollectionKeeper
// codespace
codespace sdk.CodespaceType
}
2018-09-19 19:13:12 -07:00
func NewKeeper(cdc *codec.Codec, key, tkey sdk.StoreKey, ps params.Setter, ck types.BankKeeper,
sk types.StakeKeeper, fck types.FeeCollectionKeeper, codespace sdk.CodespaceType) Keeper {
keeper := Keeper{
2018-09-19 19:13:12 -07:00
storeKey: key,
storeTKey: tkey,
cdc: cdc,
2018-10-04 17:20:43 -07:00
ps: ps,
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) GetProposerConsAddr(ctx sdk.Context) (consAddr sdk.ConsAddress) {
2018-09-28 01:02:07 -07:00
tstore := ctx.KVStore(k.storeTKey)
2018-09-13 23:35:02 -07:00
2018-09-28 01:02:07 -07:00
b := tstore.Get(ProposerKey)
2018-09-13 23:35:02 -07:00
if b == nil {
panic("Proposer cons address was likely not set in begin block")
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) SetProposerConsAddr(ctx sdk.Context, consAddr sdk.ConsAddress) {
2018-09-28 01:02:07 -07:00
tstore := ctx.KVStore(k.storeTKey)
2018-09-13 23:35:02 -07:00
b := k.cdc.MustMarshalBinary(consAddr)
2018-09-28 01:02:07 -07:00
tstore.Set(ProposerKey, b)
}
2018-09-18 21:42:05 -07:00
//______________________________________________________________________
// set the proposer public key for this block
2018-10-14 23:34:01 -07:00
func (k Keeper) GetPercentPrecommitVotes(ctx sdk.Context) (percentPrecommitVotes sdk.Dec) {
tstore := ctx.KVStore(k.storeTKey)
2018-10-14 23:34:01 -07:00
b := tstore.Get(PercentPrecommitVotesKey)
if b == nil {
panic("Proposer cons address was likely not set in begin block")
}
2018-10-14 23:34:01 -07:00
k.cdc.MustUnmarshalBinary(b, &percentPrecommitVotes)
return
}
// get the proposer public key for this block
2018-10-14 23:34:01 -07:00
func (k Keeper) SetPercentPrecommitVotes(ctx sdk.Context, percentPrecommitVotes sdk.Dec) {
tstore := ctx.KVStore(k.storeTKey)
2018-10-14 23:34:01 -07:00
b := k.cdc.MustMarshalBinary(percentPrecommitVotes)
tstore.Set(PercentPrecommitVotesKey, b)
}
//______________________________________________________________________
// PARAM STORE
// 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 {
var communityTax sdk.Dec
k.ps.Get(ctx, ParamStoreKeyCommunityTax, &communityTax)
2018-09-18 21:42:05 -07:00
return communityTax
}
// nolint: errcheck
2018-10-04 17:20:43 -07:00
func (k Keeper) SetCommunityTax(ctx sdk.Context, communityTax sdk.Dec) {
k.ps.Set(ctx, ParamStoreKeyCommunityTax, &communityTax)
2018-09-18 21:42:05 -07:00
}