working through compile errors
This commit is contained in:
parent
76882991a4
commit
df9c8db5e7
|
@ -414,14 +414,6 @@
|
||||||
revision = "a8328986c1608950fa5d3d1c0472cccc4f8fc02c"
|
revision = "a8328986c1608950fa5d3d1c0472cccc4f8fc02c"
|
||||||
version = "v0.12.0-rc0"
|
version = "v0.12.0-rc0"
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
digest = "1:2c971a45c89ca2ccc735af50919cdee05fbdc54d4bf50625073693300e31ead8"
|
|
||||||
name = "github.com/tendermint/go-wire"
|
|
||||||
packages = ["."]
|
|
||||||
pruneopts = "UT"
|
|
||||||
revision = "faa6e731944e2b7b6a46ad202902851e8ce85bee"
|
|
||||||
version = "v0.12.0"
|
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
digest = "1:53397098d6acb7613358683cc84ae59281a60c6033f0bff62fa8d3f279c6c430"
|
digest = "1:53397098d6acb7613358683cc84ae59281a60c6033f0bff62fa8d3f279c6c430"
|
||||||
name = "github.com/tendermint/iavl"
|
name = "github.com/tendermint/iavl"
|
||||||
|
@ -653,7 +645,6 @@
|
||||||
"github.com/stretchr/testify/assert",
|
"github.com/stretchr/testify/assert",
|
||||||
"github.com/stretchr/testify/require",
|
"github.com/stretchr/testify/require",
|
||||||
"github.com/tendermint/go-amino",
|
"github.com/tendermint/go-amino",
|
||||||
"github.com/tendermint/go-wire",
|
|
||||||
"github.com/tendermint/iavl",
|
"github.com/tendermint/iavl",
|
||||||
"github.com/tendermint/tendermint/abci/server",
|
"github.com/tendermint/tendermint/abci/server",
|
||||||
"github.com/tendermint/tendermint/abci/types",
|
"github.com/tendermint/tendermint/abci/types",
|
||||||
|
|
|
@ -5,13 +5,14 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/client/context"
|
|
||||||
"github.com/cosmos/cosmos-sdk/client/utils"
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
||||||
distr "github.com/cosmos/cosmos-sdk/x/distribution"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
wire "github.com/tendermint/go-wire"
|
|
||||||
|
"github.com/cosmos/cosmos-sdk/client/context"
|
||||||
|
"github.com/cosmos/cosmos-sdk/client/utils"
|
||||||
|
"github.com/cosmos/cosmos-sdk/codec"
|
||||||
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
distr "github.com/cosmos/cosmos-sdk/x/distribution"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -20,7 +21,7 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
// command to withdraw rewards
|
// command to withdraw rewards
|
||||||
func GetCmdWithdrawDelegationRewardsAll(cdc *wire.Codec) *cobra.Command {
|
func GetCmdWithdrawDelegationRewardsAll(cdc *codec.Codec) *cobra.Command {
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "withdraw-rewards",
|
Use: "withdraw-rewards",
|
||||||
Short: "withdraw rewards for either: all-delegations, a delegation, or a validator",
|
Short: "withdraw rewards for either: all-delegations, a delegation, or a validator",
|
||||||
|
@ -80,7 +81,7 @@ func GetCmdWithdrawDelegationRewardsAll(cdc *wire.Codec) *cobra.Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetCmdDelegate implements the delegate command.
|
// GetCmdDelegate implements the delegate command.
|
||||||
func GetCmdSetWithdrawAddr(cdc *wire.Codec) *cobra.Command {
|
func GetCmdSetWithdrawAddr(cdc *codec.Codec) *cobra.Command {
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "set-withdraw-addr [withdraw-addr]",
|
Use: "set-withdraw-addr [withdraw-addr]",
|
||||||
Short: "change the default withdraw address for rewards associated with an address",
|
Short: "change the default withdraw address for rewards associated with an address",
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
package keeper
|
package keeper
|
||||||
|
|
||||||
import (
|
import (
|
||||||
wire "github.com/tendermint/go-wire"
|
"github.com/cosmos/cosmos-sdk/codec"
|
||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/distribution/types"
|
"github.com/cosmos/cosmos-sdk/x/distribution/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/params"
|
"github.com/cosmos/cosmos-sdk/x/params"
|
||||||
|
@ -17,7 +16,7 @@ const (
|
||||||
type Keeper struct {
|
type Keeper struct {
|
||||||
storeKey sdk.StoreKey
|
storeKey sdk.StoreKey
|
||||||
storeTKey sdk.StoreKey
|
storeTKey sdk.StoreKey
|
||||||
cdc *wire.Codec
|
cdc *codec.Codec
|
||||||
ps params.Setter
|
ps params.Setter
|
||||||
coinKeeper types.CoinKeeper
|
coinKeeper types.CoinKeeper
|
||||||
stakeKeeper types.StakeKeeper
|
stakeKeeper types.StakeKeeper
|
||||||
|
@ -26,7 +25,7 @@ type Keeper struct {
|
||||||
codespace sdk.CodespaceType
|
codespace sdk.CodespaceType
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewKeeper(cdc *wire.Codec, key, tkey sdk.StoreKey, ps params.Setter, ck types.CoinKeeper,
|
func NewKeeper(cdc *codec.Codec, key, tkey sdk.StoreKey, ps params.Setter, ck types.CoinKeeper,
|
||||||
sk types.StakeKeeper, codespace sdk.CodespaceType) Keeper {
|
sk types.StakeKeeper, codespace sdk.CodespaceType) Keeper {
|
||||||
|
|
||||||
keeper := Keeper{
|
keeper := Keeper{
|
||||||
|
|
|
@ -6,10 +6,10 @@ import (
|
||||||
|
|
||||||
// Register concrete types on codec codec
|
// Register concrete types on codec codec
|
||||||
func RegisterCodec(cdc *codec.Codec) {
|
func RegisterCodec(cdc *codec.Codec) {
|
||||||
cdc.RegisterConcrete(MsgWithdrawDelegationRewardsAll{}, "cosmos-sdk/MsgWithdrawDelegationRewardsAll", nil)
|
cdc.RegisterConcrete(MsgWithdrawDelegatorRewardsAll{}, "cosmos-sdk/MsgWithdrawDelegationRewardsAll", nil)
|
||||||
cdc.RegisterConcrete(MsgWithdrawDelegationReward{}, "cosmos-sdk/MsgWithdrawDelegationReward", nil)
|
cdc.RegisterConcrete(MsgWithdrawDelegatorReward{}, "cosmos-sdk/MsgWithdrawDelegationReward", nil)
|
||||||
cdc.RegisterConcrete(MsgWithdrawValidatorRewardsAll{}, "cosmos-sdk/MsgWithdrawValidatorRewardsAll", nil)
|
cdc.RegisterConcrete(MsgWithdrawValidatorRewardsAll{}, "cosmos-sdk/MsgWithdrawValidatorRewardsAll", nil)
|
||||||
cdc.RegisterConcrete(MsgModifyWithdrawAddress{}, "cosmos-sdk/MsgModifyWithdrawAddress", nil)
|
cdc.RegisterConcrete(MsgSetWithdrawAddress{}, "cosmos-sdk/MsgModifyWithdrawAddress", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// generic sealed codec to be used throughout sdk
|
// generic sealed codec to be used throughout sdk
|
||||||
|
|
|
@ -13,9 +13,9 @@ type DecCoin struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDecCoin(coin sdk.Coin) DecCoin {
|
func NewDecCoin(coin sdk.Coin) DecCoin {
|
||||||
return DecCoins{
|
return DecCoin{
|
||||||
Denom: coin.Denom,
|
Denom: coin.Denom,
|
||||||
Amount: sdk.NewDec(coin.Amount),
|
Amount: sdk.NewDecFromInt(coin.Amount),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ func (coin DecCoin) Plus(coinB DecCoin) DecCoin {
|
||||||
if !(coin.Denom == coinB.Denom) {
|
if !(coin.Denom == coinB.Denom) {
|
||||||
return coin
|
return coin
|
||||||
}
|
}
|
||||||
return Coin{coin.Denom, coin.Amount.Add(coinB.Amount)}
|
return DecCoin{coin.Denom, coin.Amount.Add(coinB.Amount)}
|
||||||
}
|
}
|
||||||
|
|
||||||
// return the decimal coins with trunctated decimals
|
// return the decimal coins with trunctated decimals
|
||||||
|
@ -38,19 +38,20 @@ func (coin DecCoin) TruncateDecimal() sdk.Coin {
|
||||||
type DecCoins []DecCoin
|
type DecCoins []DecCoin
|
||||||
|
|
||||||
func NewDecCoins(coins sdk.Coins) DecCoins {
|
func NewDecCoins(coins sdk.Coins) DecCoins {
|
||||||
|
|
||||||
dcs := make(DecCoins, len(coins))
|
dcs := make(DecCoins, len(coins))
|
||||||
for i, coin := range coins {
|
for i, coin := range coins {
|
||||||
dcs[i] = NewDecCoin(coin)
|
dcs[i] = NewDecCoin(coin)
|
||||||
}
|
}
|
||||||
|
return dcs
|
||||||
}
|
}
|
||||||
|
|
||||||
// return the decimal coins with trunctated decimals
|
// return the coins with trunctated decimals
|
||||||
func (coins DecCoins) TruncateDecimal() sdk.Coins {
|
func (coins DecCoins) TruncateDecimal() sdk.Coins {
|
||||||
out := make(DecCoins, len(coins))
|
out := make(sdk.Coins, len(coins))
|
||||||
for i, coin := range coins {
|
for i, coin := range coins {
|
||||||
out[i] = coin.TruncateDecimal()
|
out[i] = coin.TruncateDecimal()
|
||||||
}
|
}
|
||||||
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
// Plus combines two sets of coins
|
// Plus combines two sets of coins
|
||||||
|
|
|
@ -33,7 +33,7 @@ type FeePool struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// update total validator accumulation factor
|
// update total validator accumulation factor
|
||||||
func (f FeePool) UpdateTotalValAccum(height int64, totalBondedTokens Dec) FeePool {
|
func (f FeePool) UpdateTotalValAccum(height int64, totalBondedTokens sdk.Dec) FeePool {
|
||||||
f.ValAccum = f.ValAccum.Update(height, totalBondedTokens)
|
f.ValAccum = f.ValAccum.Update(height, totalBondedTokens)
|
||||||
return f
|
return f
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
package types
|
package types
|
||||||
|
|
||||||
import sdk "github.com/cosmos/cosmos-sdk/types"
|
|
||||||
|
|
||||||
// GenesisState - all distribution state that must be provided at genesis
|
// GenesisState - all distribution state that must be provided at genesis
|
||||||
type GenesisState struct {
|
type GenesisState struct {
|
||||||
FeePool FeePool `json:"fee_pool"`
|
FeePool FeePool `json:"fee_pool"`
|
||||||
ValidatorDistInfos []ValidatorDistInfo `json:"validator_dist_infos"`
|
ValidatorDistInfos []ValidatorDistInfo `json:"validator_dist_infos"`
|
||||||
DelegatorDistInfos []DelegatorDistInfo `json:"delegator_dist_infos"`
|
DelegatorDistInfos []DelegatorDistInfo `json:"delegator_dist_infos"`
|
||||||
DelegatorDistInfos []sdk.AccAddress `json:"delegator_dist_infos"`
|
DelegatorWithdrawInfos []DelegatorWithdrawInfo `json:"delegator_withdraw_infos"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGenesisState(feePool FeePool, vdis []ValidatorDistInfo, ddis []DelegatorDistInfo) GenesisState {
|
func NewGenesisState(feePool FeePool, vdis []ValidatorDistInfo, ddis []DelegatorDistInfo) GenesisState {
|
||||||
|
|
|
@ -4,8 +4,8 @@ import sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
|
||||||
// expected stake keeper
|
// expected stake keeper
|
||||||
type StakeKeeper interface {
|
type StakeKeeper interface {
|
||||||
IterateDelegations(ctx sdk.Context, delAddr sdk.AccAddress,
|
IterateDelegations(ctx sdk.Context, delegator sdk.AccAddress,
|
||||||
fn func(index int64, del types.Delegation) (stop bool))
|
fn func(index int64, delegation sdk.Delegation) (stop bool))
|
||||||
GetDelegation(ctx sdk.Context, delAddr sdk.AccAddress)
|
GetDelegation(ctx sdk.Context, delAddr sdk.AccAddress)
|
||||||
GetValidator(ctx sdk.Context, valAddr sdk.AccAddress)
|
GetValidator(ctx sdk.Context, valAddr sdk.AccAddress)
|
||||||
GetPool(ctx sdk.Context)
|
GetPool(ctx sdk.Context)
|
||||||
|
|
|
@ -10,7 +10,7 @@ const MsgType = "distr"
|
||||||
|
|
||||||
// Verify interface at compile time
|
// Verify interface at compile time
|
||||||
var _, _ sdk.Msg = &MsgSetWithdrawAddress{}, &MsgWithdrawDelegatorRewardsAll{}
|
var _, _ sdk.Msg = &MsgSetWithdrawAddress{}, &MsgWithdrawDelegatorRewardsAll{}
|
||||||
var _, _ sdk.Msg = &MsgWithdrawDelegationReward{}, &MsgWithdrawValidatorRewardsAll{}
|
var _, _ sdk.Msg = &MsgWithdrawDelegatorReward{}, &MsgWithdrawValidatorRewardsAll{}
|
||||||
|
|
||||||
//______________________________________________________________________
|
//______________________________________________________________________
|
||||||
|
|
||||||
|
@ -96,28 +96,28 @@ func (msg MsgWithdrawDelegatorRewardsAll) ValidateBasic() sdk.Error {
|
||||||
//______________________________________________________________________
|
//______________________________________________________________________
|
||||||
|
|
||||||
// msg struct for delegation withdraw from a single validator
|
// msg struct for delegation withdraw from a single validator
|
||||||
type MsgWithdrawDelegationReward struct {
|
type MsgWithdrawDelegatorReward struct {
|
||||||
DelegatorAddr sdk.AccAddress `json:"delegator_addr"`
|
DelegatorAddr sdk.AccAddress `json:"delegator_addr"`
|
||||||
ValidatorAddr sdk.ValAddress `json:"validator_addr"`
|
ValidatorAddr sdk.ValAddress `json:"validator_addr"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMsgWithdrawDelegationReward(delAddr sdk.AccAddress, valAddr sdk.ValAddress) MsgWithdrawDelegationReward {
|
func NewMsgWithdrawDelegationReward(delAddr sdk.AccAddress, valAddr sdk.ValAddress) MsgWithdrawDelegatorReward {
|
||||||
return MsgWithdrawDelegationReward{
|
return MsgWithdrawDelegatorReward{
|
||||||
DelegatorAddr: delAddr,
|
DelegatorAddr: delAddr,
|
||||||
ValidatorAddr: valAddr,
|
ValidatorAddr: valAddr,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (msg MsgWithdrawDelegationReward) Type() string { return MsgType }
|
func (msg MsgWithdrawDelegatorReward) Type() string { return MsgType }
|
||||||
func (msg MsgWithdrawDelegationReward) Name() string { return "withdraw_delegation_reward" }
|
func (msg MsgWithdrawDelegatorReward) Name() string { return "withdraw_delegation_reward" }
|
||||||
|
|
||||||
// Return address that must sign over msg.GetSignBytes()
|
// Return address that must sign over msg.GetSignBytes()
|
||||||
func (msg MsgWithdrawDelegationReward) GetSigners() []sdk.AccAddress {
|
func (msg MsgWithdrawDelegatorReward) GetSigners() []sdk.AccAddress {
|
||||||
return []sdk.AccAddress{sdk.AccAddress(msg.DelegatorAddr)}
|
return []sdk.AccAddress{sdk.AccAddress(msg.DelegatorAddr)}
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the bytes for the message signer to sign on
|
// get the bytes for the message signer to sign on
|
||||||
func (msg MsgWithdrawDelegationReward) GetSignBytes() []byte {
|
func (msg MsgWithdrawDelegatorReward) GetSignBytes() []byte {
|
||||||
b, err := MsgCdc.MarshalJSON(msg)
|
b, err := MsgCdc.MarshalJSON(msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -126,7 +126,7 @@ func (msg MsgWithdrawDelegationReward) GetSignBytes() []byte {
|
||||||
}
|
}
|
||||||
|
|
||||||
// quick validity check
|
// quick validity check
|
||||||
func (msg MsgWithdrawDelegationReward) ValidateBasic() sdk.Error {
|
func (msg MsgWithdrawDelegatorReward) ValidateBasic() sdk.Error {
|
||||||
if msg.DelegatorAddr == nil {
|
if msg.DelegatorAddr == nil {
|
||||||
return ErrNilDelegatorAddr(DefaultCodespace)
|
return ErrNilDelegatorAddr(DefaultCodespace)
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,9 +6,9 @@ import sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
type ValidatorDistInfo struct {
|
type ValidatorDistInfo struct {
|
||||||
OperatorAddr sdk.ValAddress `json:"operator_addr"`
|
OperatorAddr sdk.ValAddress `json:"operator_addr"`
|
||||||
|
|
||||||
GlobalWithdrawalHeight int64 `json:"global_withdrawal_height"` // last height this validator withdrew from the global pool
|
FeePoolWithdrawalHeight int64 `json:"global_withdrawal_height"` // last height this validator withdrew from the global pool
|
||||||
Pool DecCoins `json:"pool"` // rewards owed to delegators, commission has already been charged (includes proposer reward)
|
Pool DecCoins `json:"pool"` // rewards owed to delegators, commission has already been charged (includes proposer reward)
|
||||||
PoolCommission DecCoins `json:"pool_commission"` // commission collected by this validator (pending withdrawal)
|
PoolCommission DecCoins `json:"pool_commission"` // commission collected by this validator (pending withdrawal)
|
||||||
|
|
||||||
DelAccum TotalAccum `json:"del_accum"` // total proposer pool accumulation factor held by delegators
|
DelAccum TotalAccum `json:"del_accum"` // total proposer pool accumulation factor held by delegators
|
||||||
}
|
}
|
||||||
|
@ -20,15 +20,15 @@ func (vi ValidatorDistInfo) UpdateTotalDelAccum(height int64, totalDelShares sdk
|
||||||
}
|
}
|
||||||
|
|
||||||
// XXX TODO Update dec logic
|
// XXX TODO Update dec logic
|
||||||
// move any available accumulated fees in the Global to the validator's pool
|
// move any available accumulated fees in the FeePool to the validator's pool
|
||||||
func (vi ValidatorDistInfo) TakeFeePoolRewards(fp FeePool, height int64, totalBonded, vdTokens,
|
func (vi ValidatorDistInfo) TakeFeePoolRewards(fp FeePool, height int64, totalBonded, vdTokens,
|
||||||
commissionRate sdk.Dec) (ValidatorDistInfo, FeePool) {
|
commissionRate sdk.Dec) (ValidatorDistInfo, FeePool) {
|
||||||
|
|
||||||
fp.UpdateTotalValAccum(height, totalBondedShares)
|
fp.UpdateTotalValAccum(height, totalBondedShares)
|
||||||
|
|
||||||
// update the validators pool
|
// update the validators pool
|
||||||
blocks = height - vi.GlobalWithdrawalHeight
|
blocks = height - vi.FeePoolWithdrawalHeight
|
||||||
vi.GlobalWithdrawalHeight = height
|
vi.FeePoolWithdrawalHeight = height
|
||||||
accum = sdk.NewDec(blocks).Mul(vdTokens)
|
accum = sdk.NewDec(blocks).Mul(vdTokens)
|
||||||
withdrawalTokens := fp.Pool.Mul(accum).Quo(fp.TotalValAccum)
|
withdrawalTokens := fp.Pool.Mul(accum).Quo(fp.TotalValAccum)
|
||||||
commission := withdrawalTokens.Mul(commissionRate)
|
commission := withdrawalTokens.Mul(commissionRate)
|
||||||
|
@ -42,8 +42,8 @@ func (vi ValidatorDistInfo) TakeFeePoolRewards(fp FeePool, height int64, totalBo
|
||||||
}
|
}
|
||||||
|
|
||||||
// withdraw commission rewards
|
// withdraw commission rewards
|
||||||
func (vi ValidatorDistInfo) WithdrawCommission(g Global, height int64,
|
func (vi ValidatorDistInfo) WithdrawCommission(fp FeePool, height int64,
|
||||||
totalBonded, vdTokens, commissionRate Dec) (vio ValidatorDistInfo, fpo FeePool, withdrawn DecCoins) {
|
totalBonded, vdTokens, commissionRate sdk.Dec) (vio ValidatorDistInfo, fpo FeePool, withdrawn DecCoins) {
|
||||||
|
|
||||||
fp = vi.TakeFeePoolRewards(fp, height, totalBonded, vdTokens, commissionRate)
|
fp = vi.TakeFeePoolRewards(fp, height, totalBonded, vdTokens, commissionRate)
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ func NewKeeper(cdc *codec.Codec, key, tkey sdk.StoreKey, ck bank.Keeper, codespa
|
||||||
|
|
||||||
// Set the validator hooks
|
// Set the validator hooks
|
||||||
func (k Keeper) WithHooks(sh sdk.StakingHooks) Keeper {
|
func (k Keeper) WithHooks(sh sdk.StakingHooks) Keeper {
|
||||||
if k.stakingHooks != nil {
|
if k.hooks != nil {
|
||||||
panic("cannot set validator hooks twice")
|
panic("cannot set validator hooks twice")
|
||||||
}
|
}
|
||||||
k.hooks = sh
|
k.hooks = sh
|
||||||
|
|
|
@ -3,8 +3,6 @@ package keeper
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/crypto"
|
|
||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/stake/types"
|
"github.com/cosmos/cosmos-sdk/x/stake/types"
|
||||||
)
|
)
|
||||||
|
@ -60,8 +58,8 @@ func (k Keeper) Validator(ctx sdk.Context, address sdk.ValAddress) sdk.Validator
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the sdk.validator for a particular pubkey
|
// get the sdk.validator for a particular pubkey
|
||||||
func (k Keeper) ValidatorByPubKey(ctx sdk.Context, pubkey crypto.PubKey) sdk.Validator {
|
func (k Keeper) ValidatorByConsAddr(ctx sdk.Context, addr sdk.ConsAddress) sdk.Validator {
|
||||||
val, found := k.GetValidatorByPubKey(ctx, pubkey)
|
val, found := k.GetValidatorByConsAddr(ctx, addr)
|
||||||
if !found {
|
if !found {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -94,20 +92,3 @@ func (k Keeper) Delegation(ctx sdk.Context, addrDel sdk.AccAddress, addrVal sdk.
|
||||||
|
|
||||||
return bond
|
return bond
|
||||||
}
|
}
|
||||||
|
|
||||||
// iterate through the active validator set and perform the provided function
|
|
||||||
func (k Keeper) IterateDelegations(ctx sdk.Context, delAddr sdk.AccAddress, fn func(index int64, delegation sdk.Delegation) (stop bool)) {
|
|
||||||
store := ctx.KVStore(k.storeKey)
|
|
||||||
key := GetDelegationsKey(delAddr)
|
|
||||||
iterator := sdk.KVStorePrefixIterator(store, key)
|
|
||||||
i := int64(0)
|
|
||||||
for ; iterator.Valid(); iterator.Next() {
|
|
||||||
delegation := types.MustUnmarshalDelegation(k.cdc, iterator.Key(), iterator.Value())
|
|
||||||
stop := fn(i, delegation) // XXX is this safe will the fields be able to get written to?
|
|
||||||
if stop {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
i++
|
|
||||||
}
|
|
||||||
iterator.Close()
|
|
||||||
}
|
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
abci "github.com/tendermint/tendermint/abci/types"
|
abci "github.com/tendermint/tendermint/abci/types"
|
||||||
"github.com/tendermint/tendermint/crypto"
|
|
||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/stake/types"
|
"github.com/cosmos/cosmos-sdk/x/stake/types"
|
||||||
|
@ -59,13 +58,13 @@ func (k Keeper) GetValidator(ctx sdk.Context, addr sdk.ValAddress) (validator ty
|
||||||
}
|
}
|
||||||
|
|
||||||
// get a single validator by pubkey
|
// get a single validator by pubkey
|
||||||
func (k Keeper) GetValidatorByPubKey(ctx sdk.Context, pubkey crypto.PubKey) (validator types.Validator, found bool) {
|
func (k Keeper) GetValidatorByConsAddr(ctx sdk.Context, consAddr sdk.ConsAddress) (validator types.Validator, found bool) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
addr := store.Get(GetValidatorByPubKeyIndexKey(pubkey))
|
opAddr := store.Get(GetValidatorByConsAddrKey(consAddr))
|
||||||
if addr == nil {
|
if opAddr == nil {
|
||||||
return validator, false
|
return validator, false
|
||||||
}
|
}
|
||||||
return k.GetValidator(ctx, addr)
|
return k.GetValidator(ctx, opAddr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// set the main record holding validator details
|
// set the main record holding validator details
|
||||||
|
@ -78,8 +77,8 @@ func (k Keeper) SetValidator(ctx sdk.Context, validator types.Validator) {
|
||||||
// validator index
|
// validator index
|
||||||
func (k Keeper) SetValidatorByConsAddr(ctx sdk.Context, validator types.Validator) {
|
func (k Keeper) SetValidatorByConsAddr(ctx sdk.Context, validator types.Validator) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
consAddr := sdk.consAddress{validator.Address()}
|
consAddr := sdk.ConsAddress{validator.OperatorAddr.Bytes()}
|
||||||
store.Set(GetValidatorByPubKeyIndexKey(consAddr), validator.OperatorAddr)
|
store.Set(GetValidatorByConsAddrKey(consAddr), validator.OperatorAddr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// validator index
|
// validator index
|
||||||
|
@ -671,7 +670,7 @@ func (k Keeper) RemoveValidator(ctx sdk.Context, address sdk.ValAddress) {
|
||||||
|
|
||||||
// call the hook if present
|
// call the hook if present
|
||||||
if k.hooks != nil {
|
if k.hooks != nil {
|
||||||
k.hooks.OnValidatorRemoved(ctx, validator.OperatorAddr)
|
k.hooks.OnValidatorRemoved(ctx, address)
|
||||||
}
|
}
|
||||||
|
|
||||||
// first retrieve the old validator record
|
// first retrieve the old validator record
|
||||||
|
@ -684,7 +683,7 @@ func (k Keeper) RemoveValidator(ctx sdk.Context, address sdk.ValAddress) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
pool := k.GetPool(ctx)
|
pool := k.GetPool(ctx)
|
||||||
store.Delete(GetValidatorKey(address))
|
store.Delete(GetValidatorKey(address))
|
||||||
store.Delete(GetValidatorByPubKeyIndexKey(validator.ConsPubKey))
|
store.Delete(GetValidatorByConsAddrKey(sdk.ConsAddr{validator.ConsPubKey.Address()}))
|
||||||
store.Delete(GetValidatorsByPowerIndexKey(validator, pool))
|
store.Delete(GetValidatorsByPowerIndexKey(validator, pool))
|
||||||
|
|
||||||
// delete from the current and power weighted validator groups if the validator
|
// delete from the current and power weighted validator groups if the validator
|
||||||
|
|
Loading…
Reference in New Issue