2018-09-03 17:46:33 -07:00
|
|
|
package keeper
|
2018-09-04 13:19:37 -07:00
|
|
|
|
|
|
|
import (
|
2018-09-19 16:00:21 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
2018-09-04 13:19:37 -07:00
|
|
|
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"
|
|
|
|
)
|
|
|
|
|
|
|
|
// nolint
|
|
|
|
const (
|
|
|
|
ParamStoreKeyCommunityTax = "distr/community-tax"
|
2018-09-04 13:19:37 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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
|
2018-09-04 13:19:37 -07:00
|
|
|
|
|
|
|
// 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 {
|
2018-09-04 13:19:37 -07:00
|
|
|
|
|
|
|
keeper := Keeper{
|
2018-09-19 19:13:12 -07:00
|
|
|
storeKey: key,
|
|
|
|
storeTKey: tkey,
|
|
|
|
cdc: cdc,
|
|
|
|
bankKeeper: ck,
|
|
|
|
stakeKeeper: sk,
|
|
|
|
feeCollectionKeeper: fck,
|
|
|
|
codespace: codespace,
|
2018-09-04 13:19:37 -07:00
|
|
|
}
|
|
|
|
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) {
|
2018-09-04 13:19:37 -07:00
|
|
|
store := ctx.KVStore(k.storeKey)
|
2018-09-13 00:03:30 -07:00
|
|
|
b := store.Get(FeePoolKey)
|
2018-09-04 13:19:37 -07:00
|
|
|
if b == nil {
|
2018-09-04 23:41:17 -07:00
|
|
|
panic("Stored fee pool should not have been nil")
|
2018-09-04 13:19:37 -07:00
|
|
|
}
|
2018-09-04 23:41:17 -07:00
|
|
|
k.cdc.MustUnmarshalBinary(b, &feePool)
|
2018-09-04 13:19:37 -07:00
|
|
|
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) {
|
2018-09-04 13:19:37 -07:00
|
|
|
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("Stored fee pool should not have been nil")
|
|
|
|
}
|
|
|
|
|
|
|
|
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-04 13:19:37 -07:00
|
|
|
}
|
2018-09-18 21:42:05 -07:00
|
|
|
|
|
|
|
//______________________________________________________________________
|
|
|
|
|
|
|
|
// Returns the current Deposit Procedure from the global param store
|
|
|
|
// nolint: errcheck
|
|
|
|
func (k Keeper) GetCommunityTax(ctx sdk.Context) sdk.Dec {
|
|
|
|
var communityTax sdk.Dec
|
2018-09-19 19:54:46 -07:00
|
|
|
k.ps.Get(ctx, ParamStoreKeyCommunityTax, &communityTax)
|
2018-09-18 21:42:05 -07:00
|
|
|
return communityTax
|
|
|
|
}
|
|
|
|
|
|
|
|
// nolint: errcheck
|
|
|
|
func (k Keeper) setCommunityTax(ctx sdk.Context, communityTax sdk.Dec) {
|
2018-09-19 19:54:46 -07:00
|
|
|
k.ps.Set(ctx, ParamStoreKeyCommunityTax, &communityTax)
|
2018-09-18 21:42:05 -07:00
|
|
|
}
|