2018-09-03 17:46:33 -07:00
|
|
|
package keeper
|
2018-09-04 13:19:37 -07:00
|
|
|
|
|
|
|
import (
|
2018-09-13 23:35:02 -07:00
|
|
|
wire "github.com/tendermint/go-wire"
|
|
|
|
|
2018-09-04 13:19:37 -07:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/distribution/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
// keeper of the stake store
|
|
|
|
type Keeper struct {
|
|
|
|
storeKey sdk.StoreKey
|
2018-09-13 00:03:30 -07:00
|
|
|
storeTKey sdk.StoreKey
|
2018-09-04 13:19:37 -07:00
|
|
|
cdc *wire.Codec
|
2018-09-04 23:41:17 -07:00
|
|
|
coinKeeper types.CoinKeeper
|
|
|
|
stakeKeeper types.StakeKeeper
|
2018-09-04 13:19:37 -07:00
|
|
|
|
|
|
|
// codespace
|
|
|
|
codespace sdk.CodespaceType
|
|
|
|
}
|
|
|
|
|
2018-09-13 00:03:30 -07:00
|
|
|
func NewKeeper(cdc *wire.Codec, key, tkey sdk.StoreKey, ck types.CoinKeeper,
|
2018-09-04 23:41:17 -07:00
|
|
|
sk types.StakeKeeper, codespace sdk.CodespaceType) Keeper {
|
2018-09-04 13:19:37 -07:00
|
|
|
|
|
|
|
keeper := Keeper{
|
|
|
|
storeKey: key,
|
2018-09-13 00:03:30 -07:00
|
|
|
storeTKey: tkey,
|
2018-09-04 13:19:37 -07:00
|
|
|
cdc: cdc,
|
|
|
|
coinKeeper: ck,
|
|
|
|
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) {
|
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) {
|
|
|
|
store := ctx.KVStore(k.storeKey)
|
|
|
|
|
|
|
|
b := store.Get(ProposerKey)
|
|
|
|
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-13 00:03:30 -07:00
|
|
|
store := ctx.KVStore(k.storeKey)
|
2018-09-13 23:35:02 -07:00
|
|
|
b := k.cdc.MustMarshalBinary(consAddr)
|
2018-09-13 00:03:30 -07:00
|
|
|
store.Set(ProposerKey, b)
|
2018-09-04 13:19:37 -07:00
|
|
|
}
|