working through compile errors

This commit is contained in:
rigelrozanski 2018-09-19 19:00:21 -04:00
parent 76882991a4
commit df9c8db5e7
13 changed files with 56 additions and 86 deletions

9
Gopkg.lock generated
View File

@ -414,14 +414,6 @@
revision = "a8328986c1608950fa5d3d1c0472cccc4f8fc02c"
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]]
digest = "1:53397098d6acb7613358683cc84ae59281a60c6033f0bff62fa8d3f279c6c430"
name = "github.com/tendermint/iavl"
@ -653,7 +645,6 @@
"github.com/stretchr/testify/assert",
"github.com/stretchr/testify/require",
"github.com/tendermint/go-amino",
"github.com/tendermint/go-wire",
"github.com/tendermint/iavl",
"github.com/tendermint/tendermint/abci/server",
"github.com/tendermint/tendermint/abci/types",

View File

@ -5,13 +5,14 @@ import (
"fmt"
"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/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 (
@ -20,7 +21,7 @@ var (
)
// command to withdraw rewards
func GetCmdWithdrawDelegationRewardsAll(cdc *wire.Codec) *cobra.Command {
func GetCmdWithdrawDelegationRewardsAll(cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "withdraw-rewards",
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.
func GetCmdSetWithdrawAddr(cdc *wire.Codec) *cobra.Command {
func GetCmdSetWithdrawAddr(cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "set-withdraw-addr [withdraw-addr]",
Short: "change the default withdraw address for rewards associated with an address",

View File

@ -1,8 +1,7 @@
package keeper
import (
wire "github.com/tendermint/go-wire"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/distribution/types"
"github.com/cosmos/cosmos-sdk/x/params"
@ -17,7 +16,7 @@ const (
type Keeper struct {
storeKey sdk.StoreKey
storeTKey sdk.StoreKey
cdc *wire.Codec
cdc *codec.Codec
ps params.Setter
coinKeeper types.CoinKeeper
stakeKeeper types.StakeKeeper
@ -26,7 +25,7 @@ type Keeper struct {
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 {
keeper := Keeper{

View File

@ -6,10 +6,10 @@ import (
// Register concrete types on codec codec
func RegisterCodec(cdc *codec.Codec) {
cdc.RegisterConcrete(MsgWithdrawDelegationRewardsAll{}, "cosmos-sdk/MsgWithdrawDelegationRewardsAll", nil)
cdc.RegisterConcrete(MsgWithdrawDelegationReward{}, "cosmos-sdk/MsgWithdrawDelegationReward", nil)
cdc.RegisterConcrete(MsgWithdrawDelegatorRewardsAll{}, "cosmos-sdk/MsgWithdrawDelegationRewardsAll", nil)
cdc.RegisterConcrete(MsgWithdrawDelegatorReward{}, "cosmos-sdk/MsgWithdrawDelegationReward", 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

View File

@ -13,9 +13,9 @@ type DecCoin struct {
}
func NewDecCoin(coin sdk.Coin) DecCoin {
return DecCoins{
return DecCoin{
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) {
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
@ -38,19 +38,20 @@ func (coin DecCoin) TruncateDecimal() sdk.Coin {
type DecCoins []DecCoin
func NewDecCoins(coins sdk.Coins) DecCoins {
dcs := make(DecCoins, len(coins))
for i, coin := range coins {
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 {
out := make(DecCoins, len(coins))
out := make(sdk.Coins, len(coins))
for i, coin := range coins {
out[i] = coin.TruncateDecimal()
}
return out
}
// Plus combines two sets of coins

View File

@ -33,7 +33,7 @@ type FeePool struct {
}
// 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)
return f
}

View File

@ -1,13 +1,11 @@
package types
import sdk "github.com/cosmos/cosmos-sdk/types"
// GenesisState - all distribution state that must be provided at genesis
type GenesisState struct {
FeePool FeePool `json:"fee_pool"`
ValidatorDistInfos []ValidatorDistInfo `json:"validator_dist_infos"`
DelegatorDistInfos []DelegatorDistInfo `json:"delegator_dist_infos"`
DelegatorDistInfos []sdk.AccAddress `json:"delegator_dist_infos"`
FeePool FeePool `json:"fee_pool"`
ValidatorDistInfos []ValidatorDistInfo `json:"validator_dist_infos"`
DelegatorDistInfos []DelegatorDistInfo `json:"delegator_dist_infos"`
DelegatorWithdrawInfos []DelegatorWithdrawInfo `json:"delegator_withdraw_infos"`
}
func NewGenesisState(feePool FeePool, vdis []ValidatorDistInfo, ddis []DelegatorDistInfo) GenesisState {

View File

@ -4,8 +4,8 @@ import sdk "github.com/cosmos/cosmos-sdk/types"
// expected stake keeper
type StakeKeeper interface {
IterateDelegations(ctx sdk.Context, delAddr sdk.AccAddress,
fn func(index int64, del types.Delegation) (stop bool))
IterateDelegations(ctx sdk.Context, delegator sdk.AccAddress,
fn func(index int64, delegation sdk.Delegation) (stop bool))
GetDelegation(ctx sdk.Context, delAddr sdk.AccAddress)
GetValidator(ctx sdk.Context, valAddr sdk.AccAddress)
GetPool(ctx sdk.Context)

View File

@ -10,7 +10,7 @@ const MsgType = "distr"
// Verify interface at compile time
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
type MsgWithdrawDelegationReward struct {
type MsgWithdrawDelegatorReward struct {
DelegatorAddr sdk.AccAddress `json:"delegator_addr"`
ValidatorAddr sdk.ValAddress `json:"validator_addr"`
}
func NewMsgWithdrawDelegationReward(delAddr sdk.AccAddress, valAddr sdk.ValAddress) MsgWithdrawDelegationReward {
return MsgWithdrawDelegationReward{
func NewMsgWithdrawDelegationReward(delAddr sdk.AccAddress, valAddr sdk.ValAddress) MsgWithdrawDelegatorReward {
return MsgWithdrawDelegatorReward{
DelegatorAddr: delAddr,
ValidatorAddr: valAddr,
}
}
func (msg MsgWithdrawDelegationReward) Type() string { return MsgType }
func (msg MsgWithdrawDelegationReward) Name() string { return "withdraw_delegation_reward" }
func (msg MsgWithdrawDelegatorReward) Type() string { return MsgType }
func (msg MsgWithdrawDelegatorReward) Name() string { return "withdraw_delegation_reward" }
// 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)}
}
// 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)
if err != nil {
panic(err)
@ -126,7 +126,7 @@ func (msg MsgWithdrawDelegationReward) GetSignBytes() []byte {
}
// quick validity check
func (msg MsgWithdrawDelegationReward) ValidateBasic() sdk.Error {
func (msg MsgWithdrawDelegatorReward) ValidateBasic() sdk.Error {
if msg.DelegatorAddr == nil {
return ErrNilDelegatorAddr(DefaultCodespace)
}

View File

@ -6,9 +6,9 @@ import sdk "github.com/cosmos/cosmos-sdk/types"
type ValidatorDistInfo struct {
OperatorAddr sdk.ValAddress `json:"operator_addr"`
GlobalWithdrawalHeight 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)
PoolCommission DecCoins `json:"pool_commission"` // commission collected by this validator (pending withdrawal)
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)
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
}
@ -20,15 +20,15 @@ func (vi ValidatorDistInfo) UpdateTotalDelAccum(height int64, totalDelShares sdk
}
// 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,
commissionRate sdk.Dec) (ValidatorDistInfo, FeePool) {
fp.UpdateTotalValAccum(height, totalBondedShares)
// update the validators pool
blocks = height - vi.GlobalWithdrawalHeight
vi.GlobalWithdrawalHeight = height
blocks = height - vi.FeePoolWithdrawalHeight
vi.FeePoolWithdrawalHeight = height
accum = sdk.NewDec(blocks).Mul(vdTokens)
withdrawalTokens := fp.Pool.Mul(accum).Quo(fp.TotalValAccum)
commission := withdrawalTokens.Mul(commissionRate)
@ -42,8 +42,8 @@ func (vi ValidatorDistInfo) TakeFeePoolRewards(fp FeePool, height int64, totalBo
}
// withdraw commission rewards
func (vi ValidatorDistInfo) WithdrawCommission(g Global, height int64,
totalBonded, vdTokens, commissionRate Dec) (vio ValidatorDistInfo, fpo FeePool, withdrawn DecCoins) {
func (vi ValidatorDistInfo) WithdrawCommission(fp FeePool, height int64,
totalBonded, vdTokens, commissionRate sdk.Dec) (vio ValidatorDistInfo, fpo FeePool, withdrawn DecCoins) {
fp = vi.TakeFeePoolRewards(fp, height, totalBonded, vdTokens, commissionRate)

View File

@ -34,7 +34,7 @@ func NewKeeper(cdc *codec.Codec, key, tkey sdk.StoreKey, ck bank.Keeper, codespa
// Set the validator hooks
func (k Keeper) WithHooks(sh sdk.StakingHooks) Keeper {
if k.stakingHooks != nil {
if k.hooks != nil {
panic("cannot set validator hooks twice")
}
k.hooks = sh

View File

@ -3,8 +3,6 @@ package keeper
import (
"fmt"
"github.com/tendermint/tendermint/crypto"
sdk "github.com/cosmos/cosmos-sdk/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
func (k Keeper) ValidatorByPubKey(ctx sdk.Context, pubkey crypto.PubKey) sdk.Validator {
val, found := k.GetValidatorByPubKey(ctx, pubkey)
func (k Keeper) ValidatorByConsAddr(ctx sdk.Context, addr sdk.ConsAddress) sdk.Validator {
val, found := k.GetValidatorByConsAddr(ctx, addr)
if !found {
return nil
}
@ -94,20 +92,3 @@ func (k Keeper) Delegation(ctx sdk.Context, addrDel sdk.AccAddress, addrVal sdk.
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()
}

View File

@ -6,7 +6,6 @@ import (
"fmt"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto"
sdk "github.com/cosmos/cosmos-sdk/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
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)
addr := store.Get(GetValidatorByPubKeyIndexKey(pubkey))
if addr == nil {
opAddr := store.Get(GetValidatorByConsAddrKey(consAddr))
if opAddr == nil {
return validator, false
}
return k.GetValidator(ctx, addr)
return k.GetValidator(ctx, opAddr)
}
// set the main record holding validator details
@ -78,8 +77,8 @@ func (k Keeper) SetValidator(ctx sdk.Context, validator types.Validator) {
// validator index
func (k Keeper) SetValidatorByConsAddr(ctx sdk.Context, validator types.Validator) {
store := ctx.KVStore(k.storeKey)
consAddr := sdk.consAddress{validator.Address()}
store.Set(GetValidatorByPubKeyIndexKey(consAddr), validator.OperatorAddr)
consAddr := sdk.ConsAddress{validator.OperatorAddr.Bytes()}
store.Set(GetValidatorByConsAddrKey(consAddr), validator.OperatorAddr)
}
// validator index
@ -671,7 +670,7 @@ func (k Keeper) RemoveValidator(ctx sdk.Context, address sdk.ValAddress) {
// call the hook if present
if k.hooks != nil {
k.hooks.OnValidatorRemoved(ctx, validator.OperatorAddr)
k.hooks.OnValidatorRemoved(ctx, address)
}
// 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)
pool := k.GetPool(ctx)
store.Delete(GetValidatorKey(address))
store.Delete(GetValidatorByPubKeyIndexKey(validator.ConsPubKey))
store.Delete(GetValidatorByConsAddrKey(sdk.ConsAddr{validator.ConsPubKey.Address()}))
store.Delete(GetValidatorsByPowerIndexKey(validator, pool))
// delete from the current and power weighted validator groups if the validator