aliases, errors

This commit is contained in:
rigelrozanski 2018-09-19 00:42:05 -04:00
parent 73c5fdf1f9
commit de4071f693
6 changed files with 123 additions and 9 deletions

View File

@ -11,9 +11,9 @@ import (
"github.com/cosmos/cosmos-sdk/server/config"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
distr "github.com/cosmos/cosmos-sdk/x/distribution"
"github.com/cosmos/cosmos-sdk/x/gov"
"github.com/cosmos/cosmos-sdk/x/stake"
distr "github.com/cosmos/cosmos-sdk/x/stake"
stakeTypes "github.com/cosmos/cosmos-sdk/x/stake/types"
"github.com/spf13/pflag"

74
x/distribution/alias.go Normal file
View File

@ -0,0 +1,74 @@
// nolint
package stake
import (
"github.com/cosmos/cosmos-sdk/x/distribution/keeper"
"github.com/cosmos/cosmos-sdk/x/distribution/querier"
"github.com/cosmos/cosmos-sdk/x/distribution/tags"
"github.com/cosmos/cosmos-sdk/x/distribution/types"
)
type (
Keeper = keeper.Keeper
DelegatorWithdrawInfo = types.DelegatorWithdrawInfo
DelegatorDistInfo = types.DelegatorDistInfo
ValidatorDistInfo = types.ValidatorDistInfo
TotalAccum = types.TotalAccum
FeePool = types.FeePool
MsgSetWithdrawAddress = types.MsgSetWithdrawAddress
MsgWithdrawDelegatorRewardsAll = types.MsgWithdrawDelegatorRewardsAll
MsgWithdrawDelegationReward = types.MsgWithdrawDelegationReward
MsgWithdrawValidatorRewardsAll = types.MsgWithdrawValidatorRewardsAll
GenesisState = types.GenesisState
)
var (
NewKeeper = keeper.NewKeeper
NewQuerier = querier.NewQuerier
GetValidatorDistInfoKey = keeper.GetValidatorDistInfoKey
GetDelegationDistInfoKey = keeper.GetDelegationDistInfoKey
GetDelegationDistInfosKey = keeper.GetDelegationDistInfosKey
GetDelegatorWithdrawAddrKey = keeper.GetDelegatorWithdrawAddrKey
FeePoolKey = keeper.FeePoolKey
ValidatorDistInfoKey = keeper.ValidatorDistInfoKey
DelegatorDistInfoKey = keeper.DelegatorDistInfoKey
DelegatorWithdrawInfoKey = keeper.DelegatorWithdrawInfoKey
ProposerKey = keeper.ProposerKey
InitialFeePool = types.InitialFeePool
NewGenesisState = types.NewGenesisState
DefaultGenesisState = types.DefaultGenesisState
RegisterCodec = types.RegisterCodec
NewMsgSetWithdrawAddress = types.NewMsgSetWithdrawAddress
NewMsgWithdrawDelegatorRewardsAll = types.NewMsgWithdrawDelegatorRewardsAll
NewMsgWithdrawDelegationReward = types.NewMsgWithdrawDelegationReward
NewMsgWithdrawValidatorRewardsAll = types.NewMsgWithdrawValidatorRewardsAll
)
const (
DefaultCodespace = types.DefaultCodespace
CodeInvalidInput = types.CodeInvalidInput
)
var (
ErrNilDelegatorAddr = types.ErrNilDelegatorAddr
ErrNilWithdrawAddr = types.ErrNilWithdrawAddr
ErrNilValidatorAddr = types.ErrNilValidatorAddr
)
var (
ActionModifyWithdrawAddress = tags.ActionModifyWithdrawAddress
ActionWithdrawDelegatorRewardsAll = tags.ActionWithdrawDelegatorRewardsAll
ActionWithdrawDelegatorReward = tags.ActionWithdrawDelegatorReward
ActionWithdrawValidatorRewardsAll = tags.ActionWithdrawValidatorRewardsAll
TagAction = tags.Action
TagValidator = tags.SrcValidator
TagDelegator = tags.Delegator
)

View File

@ -5,12 +5,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/stake/types"
)
// InitGenesis sets the pool and parameters for the provided keeper and
// initializes the IntraTxCounter. For each validator in data, it sets that
// validator in the keeper along with manually setting the indexes. In
// addition, it also sets any delegations found in data. Finally, it updates
// the bonded validators.
// Returns final validator set after applying all declaration and delegations
// InitGenesis sets distribution information for genesis
func InitGenesis(ctx sdk.Context, keeper Keeper, data types.GenesisState) {
keeper.SetFeePool(ctx, data.FeePool)

View File

@ -30,7 +30,7 @@ func (k Keeper) AllocateFees(ctx sdk.Context) {
proposerDist.Pool = proposerDist.Pool.Add(proposerReward.Sub(commission))
// allocate community funding
communityTax := sdk.NewDecWithPrec(1, 2) // XXX TODO get from global params store
communityTax := k.GetCommunityTax(ctx)
communityFunding := feesCollectedDec.Mul(communityTax)
feePool := k.GetFeePool(ctx)
feePool.CommunityFund = feePool.CommunityFund.Add(communityFunding)

View File

@ -5,6 +5,12 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/distribution/types"
"github.com/cosmos/cosmos-sdk/x/params"
)
// nolint
const (
ParamStoreKeyCommunityTax = "distr/community-tax"
)
// keeper of the stake store
@ -12,6 +18,7 @@ type Keeper struct {
storeKey sdk.StoreKey
storeTKey sdk.StoreKey
cdc *wire.Codec
ps params.Setter
coinKeeper types.CoinKeeper
stakeKeeper types.StakeKeeper
@ -19,7 +26,7 @@ type Keeper struct {
codespace sdk.CodespaceType
}
func NewKeeper(cdc *wire.Codec, key, tkey sdk.StoreKey, ck types.CoinKeeper,
func NewKeeper(cdc *wire.Codec, key, tkey sdk.StoreKey, ps params.Setter, ck types.CoinKeeper,
sk types.StakeKeeper, codespace sdk.CodespaceType) Keeper {
keeper := Keeper{
@ -75,3 +82,18 @@ func (k Keeper) SetProposerConsAddr(ctx sdk.Context, consAddr sdk.ConsAddress) {
b := k.cdc.MustMarshalBinary(consAddr)
store.Set(ProposerKey, b)
}
//______________________________________________________________________
// 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
keeper.ps.Get(ctx, ParamStoreKeyCommunityTax, &communityTax)
return communityTax
}
// nolint: errcheck
func (k Keeper) setCommunityTax(ctx sdk.Context, communityTax sdk.Dec) {
keeper.ps.Set(ctx, ParamStoreKeyCommunityTax, &communityTax)
}

View File

@ -0,0 +1,23 @@
// nolint
package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
)
type CodeType = sdk.CodeType
const (
DefaultCodespace sdk.CodespaceType = 6
CodeInvalidInput CodeType = 103
)
func ErrNilDelegatorAddr(codespace sdk.CodespaceType) sdk.Error {
return sdk.NewError(codespace, CodeInvalidInput, "delegator address is nil")
}
func ErrNilWithdrawAddr(codespace sdk.CodespaceType) sdk.Error {
return sdk.NewError(codespace, CodeInvalidInput, "withdraw address is nil")
}
func ErrNilValidatorAddr(codespace sdk.CodespaceType) sdk.Error {
return sdk.NewError(codespace, CodeInvalidInput, "validator address is nil")
}