refactor(staking): move delegation and validator interfaces to ./types (#18198)

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
This commit is contained in:
Marko 2023-11-30 22:18:42 +01:00 committed by GitHub
parent 3c8ddabcaa
commit a7ececc34d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
34 changed files with 232 additions and 218 deletions

View File

@ -75,7 +75,7 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []
/* Handle fee distribution state. */
// withdraw all validator commission
err := app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
err := app.StakingKeeper.IterateValidators(ctx, func(_ int64, val sdk.ValidatorI) (stop bool) {
valBz, err := app.StakingKeeper.ValidatorAddressCodec().StringToBytes(val.GetOperator())
if err != nil {
panic(err)
@ -121,7 +121,7 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []
ctx = ctx.WithBlockHeight(0)
// reinitialize all validators
err = app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
err = app.StakingKeeper.IterateValidators(ctx, func(_ int64, val sdk.ValidatorI) (stop bool) {
valBz, err := app.StakingKeeper.ValidatorAddressCodec().StringToBytes(val.GetOperator())
if err != nil {
panic(err)

View File

@ -277,7 +277,7 @@ func TestHandleNewValidator(t *testing.T) {
// validator should be bonded still, should not have been jailed or slashed
validator, _ := f.stakingKeeper.GetValidatorByConsAddr(f.ctx, sdk.GetConsAddress(valpubkey))
assert.Equal(t, stakingtypes.Bonded, validator.GetStatus())
assert.Equal(t, sdk.Bonded, validator.GetStatus())
bondPool := f.stakingKeeper.GetBondedPool(f.ctx)
expTokens := f.stakingKeeper.TokensFromConsensusPower(f.ctx, 100)
assert.Assert(t, expTokens.Equal(f.bankKeeper.GetBalance(f.ctx, bondPool.GetAddress(), bondDenom).Amount))
@ -335,7 +335,7 @@ func TestHandleAlreadyJailed(t *testing.T) {
// validator should have been jailed and slashed
validator, _ := f.stakingKeeper.GetValidatorByConsAddr(f.ctx, sdk.GetConsAddress(val))
assert.Equal(t, stakingtypes.Unbonding, validator.GetStatus())
assert.Equal(t, sdk.Unbonding, validator.GetStatus())
// validator should have been slashed
resultingTokens := amt.Sub(f.stakingKeeper.TokensFromConsensusPower(f.ctx, 1))

View File

@ -384,7 +384,7 @@ func TestSlashWithUnbondingDelegation(t *testing.T) {
// power decreased by 1 again, validator is out of stake
// validator should be in unbonding period
validator, _ = f.stakingKeeper.GetValidatorByConsAddr(f.sdkCtx, consAddr)
assert.Equal(t, validator.GetStatus(), types.Unbonding)
assert.Equal(t, validator.GetStatus(), sdk.Unbonding)
}
// tests Slash at a previous height with a redelegation
@ -514,14 +514,14 @@ func TestSlashWithRedelegation(t *testing.T) {
// read updated validator
// validator decreased to zero power, should be in unbonding period
validator, _ = f.stakingKeeper.GetValidatorByConsAddr(f.sdkCtx, consAddr)
assert.Equal(t, validator.GetStatus(), types.Unbonding)
assert.Equal(t, validator.GetStatus(), sdk.Unbonding)
// slash the validator again, by 100%
// no stake remains to be slashed
f.sdkCtx = f.sdkCtx.WithBlockHeight(12)
// validator still in unbonding period
validator, _ = f.stakingKeeper.GetValidatorByConsAddr(f.sdkCtx, consAddr)
assert.Equal(t, validator.GetStatus(), types.Unbonding)
assert.Equal(t, validator.GetStatus(), sdk.Unbonding)
_, err = f.stakingKeeper.Slash(f.sdkCtx, consAddr, 10, 10, math.LegacyOneDec())
assert.NilError(t, err)
@ -542,7 +542,7 @@ func TestSlashWithRedelegation(t *testing.T) {
// read updated validator
// power still zero, still in unbonding period
validator, _ = f.stakingKeeper.GetValidatorByConsAddr(f.sdkCtx, consAddr)
assert.Equal(t, validator.GetStatus(), types.Unbonding)
assert.Equal(t, validator.GetStatus(), sdk.Unbonding)
}
// tests Slash at a previous height with both an unbonding delegation and a redelegation

View File

@ -107,9 +107,9 @@ func TestUpdateBondedValidatorsDecreaseCliff(t *testing.T) {
nextCliffVal, _ = nextCliffVal.RemoveDelShares(math.LegacyNewDecFromInt(shares))
_ = keeper.TestingUpdateValidator(f.stakingKeeper, f.sdkCtx, nextCliffVal, true)
expectedValStatus := map[int]types.BondStatus{
9: types.Bonded, 8: types.Bonded, 7: types.Bonded, 5: types.Bonded, 4: types.Bonded,
0: types.Unbonding, 1: types.Unbonding, 2: types.Unbonding, 3: types.Unbonding, 6: types.Unbonding,
expectedValStatus := map[int]sdk.BondStatus{
9: sdk.Bonded, 8: sdk.Bonded, 7: sdk.Bonded, 5: sdk.Bonded, 4: sdk.Bonded,
0: sdk.Unbonding, 1: sdk.Unbonding, 2: sdk.Unbonding, 3: sdk.Unbonding, 6: sdk.Unbonding,
}
// require all the validators have their respective statuses
@ -121,7 +121,7 @@ func TestUpdateBondedValidatorsDecreaseCliff(t *testing.T) {
assert.Equal(
t, status, val.GetStatus(),
fmt.Sprintf("expected validator at index %v to have status: %s", valIdx, status),
fmt.Sprintf("expected validator at index %v to have status: %x", valIdx, status),
)
}
}
@ -155,7 +155,7 @@ func TestSlashToZeroPowerRemoved(t *testing.T) {
applyValidatorSetUpdates(t, f.sdkCtx, f.stakingKeeper, -1)
// validator should be unbonding
validator, _ = f.stakingKeeper.GetValidator(f.sdkCtx, addrVals[0])
assert.Equal(t, validator.GetStatus(), types.Unbonding)
assert.Equal(t, validator.GetStatus(), sdk.Unbonding)
}
// test how the validators are sorted, tests GetBondedValidatorsByPower

View File

@ -1,7 +1,11 @@
package types
import (
sdkmath "cosmossdk.io/math"
cmtprotocrypto "github.com/cometbft/cometbft/proto/tendermint/crypto"
"cosmossdk.io/math"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
)
// Delay, in blocks, between when validator updates are returned to the
@ -21,18 +25,79 @@ var (
DefaultBondDenom = "stake"
// DefaultPowerReduction is the default amount of staking tokens required for 1 unit of consensus-engine power
DefaultPowerReduction = sdkmath.NewIntFromUint64(1000000)
DefaultPowerReduction = math.NewIntFromUint64(1000000)
// PubKeyEd25519Type is ed25519 for type the consensus params validator pub_key_types params
PubKeyEd25519Type = "ed25519"
)
// TokensToConsensusPower - convert input tokens to potential consensus-engine power
func TokensToConsensusPower(tokens, powerReduction sdkmath.Int) int64 {
func TokensToConsensusPower(tokens, powerReduction math.Int) int64 {
return (tokens.Quo(powerReduction)).Int64()
}
// TokensFromConsensusPower - convert input power to tokens
func TokensFromConsensusPower(power int64, powerReduction sdkmath.Int) sdkmath.Int {
return sdkmath.NewInt(power).Mul(powerReduction)
func TokensFromConsensusPower(power int64, powerReduction math.Int) math.Int {
return math.NewInt(power).Mul(powerReduction)
}
// ______________________________________________________________________
// Delegation & Validator Interfaces are moved here to avoid direct dependency on the staking module in expected keeper interfaces
// BondStatus is the status of a validator.
type BondStatus int32
const (
// UNSPECIFIED defines an invalid validator status.
Unspecified BondStatus = 0
// UNBONDED defines a validator that is not bonded.
Unbonded BondStatus = 1
// UNBONDING defines a validator that is unbonding.
Unbonding BondStatus = 2
// BONDED defines a validator that is bonded.
Bonded BondStatus = 3
)
// BondStatus_name is the string representation of BondStatus.
var bondStatus_name = map[int32]string{
0: "BOND_STATUS_UNSPECIFIED",
1: "BOND_STATUS_UNBONDED",
2: "BOND_STATUS_UNBONDING",
3: "BOND_STATUS_BONDED",
}
func (x BondStatus) String() string {
return bondStatus_name[int32(x)]
}
// DelegationI delegation bond for a delegated proof of stake system
type DelegationI interface {
GetDelegatorAddr() string // delegator string for the bond
GetValidatorAddr() string // validator operator address
GetShares() math.LegacyDec // amount of validator's shares held in this delegation
}
// ValidatorI expected validator functions
type ValidatorI interface {
IsJailed() bool // whether the validator is jailed
GetMoniker() string // moniker of the validator
GetStatus() BondStatus // status of the validator
IsBonded() bool // check if has a bonded status
IsUnbonded() bool // check if has status unbonded
IsUnbonding() bool // check if has status unbonding
GetOperator() string // operator address to receive/return validators coins
ConsPubKey() (cryptotypes.PubKey, error) // validation consensus pubkey (cryptotypes.PubKey)
TmConsPublicKey() (cmtprotocrypto.PublicKey, error) // validation consensus pubkey (CometBFT)
GetConsAddr() ([]byte, error) // validation consensus address
GetTokens() math.Int // validation tokens
GetBondedTokens() math.Int // validator bonded tokens
GetConsensusPower(math.Int) int64 // validation power in CometBFT
GetCommission() math.LegacyDec // validator commission rate
GetMinSelfDelegation() math.Int // validator minimum self delegation
GetDelegatorShares() math.LegacyDec // total outstanding delegator shares
TokensFromShares(math.LegacyDec) math.LegacyDec // token worth of provided delegator shares
TokensFromSharesTruncated(math.LegacyDec) math.LegacyDec // token worth of provided delegator shares, truncated
TokensFromSharesRoundUp(math.LegacyDec) math.LegacyDec // token worth of provided delegator shares, rounded up
SharesFromTokens(amt math.Int) (math.LegacyDec, error) // shares worth of delegator's bond
SharesFromTokensTruncated(amt math.Int) (math.LegacyDec, error) // truncated shares worth of delegator's bond
}

View File

@ -8,7 +8,6 @@ import (
"cosmossdk.io/core/comet"
"cosmossdk.io/math"
"cosmossdk.io/x/distribution/types"
stakingtypes "cosmossdk.io/x/staking/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
@ -88,7 +87,7 @@ func (k Keeper) AllocateTokens(ctx context.Context, totalPreviousPower int64, bo
// AllocateTokensToValidator allocate tokens to a particular validator,
// splitting according to commission.
func (k Keeper) AllocateTokensToValidator(ctx context.Context, val stakingtypes.ValidatorI, tokens sdk.DecCoins) error {
func (k Keeper) AllocateTokensToValidator(ctx context.Context, val sdk.ValidatorI, tokens sdk.DecCoins) error {
// split tokens between validator and delegators according to commission
commission := tokens.MulDec(val.GetCommission())
shared := tokens.Sub(commission)

View File

@ -8,7 +8,6 @@ import (
"cosmossdk.io/collections"
"cosmossdk.io/math"
"cosmossdk.io/x/distribution/types"
stakingtypes "cosmossdk.io/x/staking/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
@ -47,7 +46,7 @@ func (k Keeper) initializeDelegation(ctx context.Context, val sdk.ValAddress, de
}
// calculate the rewards accrued by a delegation between two periods
func (k Keeper) calculateDelegationRewardsBetween(ctx context.Context, val stakingtypes.ValidatorI,
func (k Keeper) calculateDelegationRewardsBetween(ctx context.Context, val sdk.ValidatorI,
startingPeriod, endingPeriod uint64, stake math.LegacyDec,
) (sdk.DecCoins, error) {
// sanity check
@ -86,7 +85,7 @@ func (k Keeper) calculateDelegationRewardsBetween(ctx context.Context, val staki
}
// calculate the total rewards accrued by a delegation
func (k Keeper) CalculateDelegationRewards(ctx context.Context, val stakingtypes.ValidatorI, del stakingtypes.DelegationI, endingPeriod uint64) (rewards sdk.DecCoins, err error) {
func (k Keeper) CalculateDelegationRewards(ctx context.Context, val sdk.ValidatorI, del sdk.DelegationI, endingPeriod uint64) (rewards sdk.DecCoins, err error) {
addrCodec := k.authKeeper.AddressCodec()
delAddr, err := addrCodec.StringToBytes(del.GetDelegatorAddr())
if err != nil {
@ -196,7 +195,7 @@ func (k Keeper) CalculateDelegationRewards(ctx context.Context, val stakingtypes
return rewards, nil
}
func (k Keeper) withdrawDelegationRewards(ctx context.Context, val stakingtypes.ValidatorI, del stakingtypes.DelegationI) (sdk.Coins, error) {
func (k Keeper) withdrawDelegationRewards(ctx context.Context, val sdk.ValidatorI, del sdk.DelegationI) (sdk.Coins, error) {
addrCodec := k.authKeeper.AddressCodec()
delAddr, err := addrCodec.StringToBytes(del.GetDelegatorAddr())
if err != nil {

View File

@ -9,7 +9,6 @@ import (
"cosmossdk.io/collections"
"cosmossdk.io/errors"
"cosmossdk.io/x/distribution/types"
stakingtypes "cosmossdk.io/x/staking/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/query"
@ -267,7 +266,7 @@ func (k Querier) DelegationTotalRewards(ctx context.Context, req *types.QueryDel
err = k.stakingKeeper.IterateDelegations(
ctx, delAdr,
func(_ int64, del stakingtypes.DelegationI) (stop bool) {
func(_ int64, del sdk.DelegationI) (stop bool) {
valAddr, err := k.stakingKeeper.ValidatorAddressCodec().StringToBytes(del.GetValidatorAddr())
if err != nil {
panic(err)
@ -318,7 +317,7 @@ func (k Querier) DelegatorValidators(ctx context.Context, req *types.QueryDelega
err = k.stakingKeeper.IterateDelegations(
ctx, delAdr,
func(_ int64, del stakingtypes.DelegationI) (stop bool) {
func(_ int64, del sdk.DelegationI) (stop bool) {
validators = append(validators, del.GetValidatorAddr())
return false
},

View File

@ -5,7 +5,6 @@ import (
"cosmossdk.io/collections"
"cosmossdk.io/x/distribution/types"
stakingtypes "cosmossdk.io/x/staking/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
@ -90,7 +89,7 @@ func CanWithdrawInvariant(k Keeper) sdk.Invariant {
}
// iterate over all validators
err = k.stakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
err = k.stakingKeeper.IterateValidators(ctx, func(_ int64, val sdk.ValidatorI) (stop bool) {
valBz, err1 := k.stakingKeeper.ValidatorAddressCodec().StringToBytes(val.GetOperator())
if err != nil {
panic(err1)
@ -132,7 +131,7 @@ func CanWithdrawInvariant(k Keeper) sdk.Invariant {
func ReferenceCountInvariant(k Keeper) sdk.Invariant {
return func(ctx sdk.Context) (string, bool) {
valCount := uint64(0)
err := k.stakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
err := k.stakingKeeper.IterateValidators(ctx, func(_ int64, val sdk.ValidatorI) (stop bool) {
valCount++
return false
})

View File

@ -9,13 +9,12 @@ import (
"cosmossdk.io/collections"
"cosmossdk.io/math"
"cosmossdk.io/x/distribution/types"
stakingtypes "cosmossdk.io/x/staking/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// initialize rewards for a new validator
func (k Keeper) initializeValidator(ctx context.Context, val stakingtypes.ValidatorI) error {
func (k Keeper) initializeValidator(ctx context.Context, val sdk.ValidatorI) error {
valBz, err := k.stakingKeeper.ValidatorAddressCodec().StringToBytes(val.GetOperator())
if err != nil {
return err
@ -44,7 +43,7 @@ func (k Keeper) initializeValidator(ctx context.Context, val stakingtypes.Valida
}
// increment validator period, returning the period just ended
func (k Keeper) IncrementValidatorPeriod(ctx context.Context, val stakingtypes.ValidatorI) (uint64, error) {
func (k Keeper) IncrementValidatorPeriod(ctx context.Context, val sdk.ValidatorI) (uint64, error) {
valBz, err := k.stakingKeeper.ValidatorAddressCodec().StringToBytes(val.GetOperator())
if err != nil {
return 0, err

View File

@ -345,10 +345,10 @@ func (mr *MockStakingKeeperMockRecorder) ConsensusAddressCodec() *gomock.Call {
}
// Delegation mocks base method.
func (m *MockStakingKeeper) Delegation(arg0 context.Context, arg1 types0.AccAddress, arg2 types0.ValAddress) (types.DelegationI, error) {
func (m *MockStakingKeeper) Delegation(arg0 context.Context, arg1 types0.AccAddress, arg2 types0.ValAddress) (types0.DelegationI, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Delegation", arg0, arg1, arg2)
ret0, _ := ret[0].(types.DelegationI)
ret0, _ := ret[0].(types0.DelegationI)
ret1, _ := ret[1].(error)
return ret0, ret1
}
@ -405,7 +405,7 @@ func (mr *MockStakingKeeperMockRecorder) GetAllValidators(ctx interface{}) *gomo
}
// IterateDelegations mocks base method.
func (m *MockStakingKeeper) IterateDelegations(ctx context.Context, delegator types0.AccAddress, fn func(int64, types.DelegationI) bool) error {
func (m *MockStakingKeeper) IterateDelegations(ctx context.Context, delegator types0.AccAddress, fn func(int64, types0.DelegationI) bool) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "IterateDelegations", ctx, delegator, fn)
ret0, _ := ret[0].(error)
@ -419,7 +419,7 @@ func (mr *MockStakingKeeperMockRecorder) IterateDelegations(ctx, delegator, fn i
}
// IterateValidators mocks base method.
func (m *MockStakingKeeper) IterateValidators(arg0 context.Context, arg1 func(int64, types.ValidatorI) bool) error {
func (m *MockStakingKeeper) IterateValidators(arg0 context.Context, arg1 func(int64, types0.ValidatorI) bool) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "IterateValidators", arg0, arg1)
ret0, _ := ret[0].(error)
@ -433,10 +433,10 @@ func (mr *MockStakingKeeperMockRecorder) IterateValidators(arg0, arg1 interface{
}
// Validator mocks base method.
func (m *MockStakingKeeper) Validator(arg0 context.Context, arg1 types0.ValAddress) (types.ValidatorI, error) {
func (m *MockStakingKeeper) Validator(arg0 context.Context, arg1 types0.ValAddress) (types0.ValidatorI, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Validator", arg0, arg1)
ret0, _ := ret[0].(types.ValidatorI)
ret0, _ := ret[0].(types0.ValidatorI)
ret1, _ := ret[1].(error)
return ret0, ret1
}
@ -462,10 +462,10 @@ func (mr *MockStakingKeeperMockRecorder) ValidatorAddressCodec() *gomock.Call {
}
// ValidatorByConsAddr mocks base method.
func (m *MockStakingKeeper) ValidatorByConsAddr(arg0 context.Context, arg1 types0.ConsAddress) (types.ValidatorI, error) {
func (m *MockStakingKeeper) ValidatorByConsAddr(arg0 context.Context, arg1 types0.ConsAddress) (types0.ValidatorI, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ValidatorByConsAddr", arg0, arg1)
ret0, _ := ret[0].(types.ValidatorI)
ret0, _ := ret[0].(types0.ValidatorI)
ret1, _ := ret[1].(error)
return ret0, ret1
}

View File

@ -48,17 +48,17 @@ type StakingKeeper interface {
// iterate through validators by operator address, execute func for each validator
IterateValidators(context.Context,
func(index int64, validator stakingtypes.ValidatorI) (stop bool)) error
func(index int64, validator sdk.ValidatorI) (stop bool)) error
Validator(context.Context, sdk.ValAddress) (stakingtypes.ValidatorI, error) // get a particular validator by operator address
ValidatorByConsAddr(context.Context, sdk.ConsAddress) (stakingtypes.ValidatorI, error) // get a particular validator by consensus address
Validator(context.Context, sdk.ValAddress) (sdk.ValidatorI, error) // get a particular validator by operator address
ValidatorByConsAddr(context.Context, sdk.ConsAddress) (sdk.ValidatorI, error) // get a particular validator by consensus address
// Delegation allows for getting a particular delegation for a given validator
// and delegator outside the scope of the staking module.
Delegation(context.Context, sdk.AccAddress, sdk.ValAddress) (stakingtypes.DelegationI, error)
Delegation(context.Context, sdk.AccAddress, sdk.ValAddress) (sdk.DelegationI, error)
IterateDelegations(ctx context.Context, delegator sdk.AccAddress,
fn func(index int64, delegation stakingtypes.DelegationI) (stop bool)) error
fn func(index int64, delegation sdk.DelegationI) (stop bool)) error
GetAllSDKDelegations(ctx context.Context) ([]stakingtypes.Delegation, error)
GetAllValidators(ctx context.Context) ([]stakingtypes.Validator, error)

View File

@ -12,9 +12,8 @@ import (
stakingv1beta1 "cosmossdk.io/api/cosmos/staking/v1beta1"
address "cosmossdk.io/core/address"
math "cosmossdk.io/math"
types "cosmossdk.io/x/staking/types"
types0 "github.com/cosmos/cosmos-sdk/crypto/types"
types1 "github.com/cosmos/cosmos-sdk/types"
types "github.com/cosmos/cosmos-sdk/crypto/types"
types0 "github.com/cosmos/cosmos-sdk/types"
gomock "github.com/golang/mock/gomock"
)
@ -56,10 +55,10 @@ func (mr *MockStakingKeeperMockRecorder) ConsensusAddressCodec() *gomock.Call {
}
// ValidatorByConsAddr mocks base method.
func (m *MockStakingKeeper) ValidatorByConsAddr(arg0 context.Context, arg1 types1.ConsAddress) (types.ValidatorI, error) {
func (m *MockStakingKeeper) ValidatorByConsAddr(arg0 context.Context, arg1 types0.ConsAddress) (types0.ValidatorI, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ValidatorByConsAddr", arg0, arg1)
ret0, _ := ret[0].(types.ValidatorI)
ret0, _ := ret[0].(types0.ValidatorI)
ret1, _ := ret[1].(error)
return ret0, ret1
}
@ -94,10 +93,10 @@ func (m *MockSlashingKeeper) EXPECT() *MockSlashingKeeperMockRecorder {
}
// GetPubkey mocks base method.
func (m *MockSlashingKeeper) GetPubkey(arg0 context.Context, arg1 types0.Address) (types0.PubKey, error) {
func (m *MockSlashingKeeper) GetPubkey(arg0 context.Context, arg1 types.Address) (types.PubKey, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetPubkey", arg0, arg1)
ret0, _ := ret[0].(types0.PubKey)
ret0, _ := ret[0].(types.PubKey)
ret1, _ := ret[1].(error)
return ret0, ret1
}
@ -109,7 +108,7 @@ func (mr *MockSlashingKeeperMockRecorder) GetPubkey(arg0, arg1 interface{}) *gom
}
// HasValidatorSigningInfo mocks base method.
func (m *MockSlashingKeeper) HasValidatorSigningInfo(arg0 context.Context, arg1 types1.ConsAddress) bool {
func (m *MockSlashingKeeper) HasValidatorSigningInfo(arg0 context.Context, arg1 types0.ConsAddress) bool {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "HasValidatorSigningInfo", arg0, arg1)
ret0, _ := ret[0].(bool)
@ -123,7 +122,7 @@ func (mr *MockSlashingKeeperMockRecorder) HasValidatorSigningInfo(arg0, arg1 int
}
// IsTombstoned mocks base method.
func (m *MockSlashingKeeper) IsTombstoned(arg0 context.Context, arg1 types1.ConsAddress) bool {
func (m *MockSlashingKeeper) IsTombstoned(arg0 context.Context, arg1 types0.ConsAddress) bool {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "IsTombstoned", arg0, arg1)
ret0, _ := ret[0].(bool)
@ -137,7 +136,7 @@ func (mr *MockSlashingKeeperMockRecorder) IsTombstoned(arg0, arg1 interface{}) *
}
// Jail mocks base method.
func (m *MockSlashingKeeper) Jail(arg0 context.Context, arg1 types1.ConsAddress) error {
func (m *MockSlashingKeeper) Jail(arg0 context.Context, arg1 types0.ConsAddress) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Jail", arg0, arg1)
ret0, _ := ret[0].(error)
@ -151,7 +150,7 @@ func (mr *MockSlashingKeeperMockRecorder) Jail(arg0, arg1 interface{}) *gomock.C
}
// JailUntil mocks base method.
func (m *MockSlashingKeeper) JailUntil(arg0 context.Context, arg1 types1.ConsAddress, arg2 time.Time) error {
func (m *MockSlashingKeeper) JailUntil(arg0 context.Context, arg1 types0.ConsAddress, arg2 time.Time) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "JailUntil", arg0, arg1, arg2)
ret0, _ := ret[0].(error)
@ -165,7 +164,7 @@ func (mr *MockSlashingKeeperMockRecorder) JailUntil(arg0, arg1, arg2 interface{}
}
// Slash mocks base method.
func (m *MockSlashingKeeper) Slash(arg0 context.Context, arg1 types1.ConsAddress, arg2 math.LegacyDec, arg3, arg4 int64) error {
func (m *MockSlashingKeeper) Slash(arg0 context.Context, arg1 types0.ConsAddress, arg2 math.LegacyDec, arg3, arg4 int64) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Slash", arg0, arg1, arg2, arg3, arg4)
ret0, _ := ret[0].(error)
@ -194,7 +193,7 @@ func (mr *MockSlashingKeeperMockRecorder) SlashFractionDoubleSign(arg0 interface
}
// SlashWithInfractionReason mocks base method.
func (m *MockSlashingKeeper) SlashWithInfractionReason(arg0 context.Context, arg1 types1.ConsAddress, arg2 math.LegacyDec, arg3, arg4 int64, arg5 stakingv1beta1.Infraction) error {
func (m *MockSlashingKeeper) SlashWithInfractionReason(arg0 context.Context, arg1 types0.ConsAddress, arg2 math.LegacyDec, arg3, arg4 int64, arg5 stakingv1beta1.Infraction) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SlashWithInfractionReason", arg0, arg1, arg2, arg3, arg4, arg5)
ret0, _ := ret[0].(error)
@ -208,7 +207,7 @@ func (mr *MockSlashingKeeperMockRecorder) SlashWithInfractionReason(arg0, arg1,
}
// Tombstone mocks base method.
func (m *MockSlashingKeeper) Tombstone(arg0 context.Context, arg1 types1.ConsAddress) error {
func (m *MockSlashingKeeper) Tombstone(arg0 context.Context, arg1 types0.ConsAddress) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Tombstone", arg0, arg1)
ret0, _ := ret[0].(error)
@ -245,7 +244,7 @@ func (m *MockAccountKeeper) EXPECT() *MockAccountKeeperMockRecorder {
}
// SetAccount mocks base method.
func (m *MockAccountKeeper) SetAccount(ctx context.Context, acc types1.AccountI) {
func (m *MockAccountKeeper) SetAccount(ctx context.Context, acc types0.AccountI) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "SetAccount", ctx, acc)
}
@ -280,10 +279,10 @@ func (m *MockBankKeeper) EXPECT() *MockBankKeeperMockRecorder {
}
// GetAllBalances mocks base method.
func (m *MockBankKeeper) GetAllBalances(ctx types1.Context, addr types1.AccAddress) types1.Coins {
func (m *MockBankKeeper) GetAllBalances(ctx types0.Context, addr types0.AccAddress) types0.Coins {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetAllBalances", ctx, addr)
ret0, _ := ret[0].(types1.Coins)
ret0, _ := ret[0].(types0.Coins)
return ret0
}
@ -294,7 +293,7 @@ func (mr *MockBankKeeperMockRecorder) GetAllBalances(ctx, addr interface{}) *gom
}
// MintCoins mocks base method.
func (m *MockBankKeeper) MintCoins(ctx types1.Context, moduleName string, amt types1.Coins) error {
func (m *MockBankKeeper) MintCoins(ctx types0.Context, moduleName string, amt types0.Coins) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "MintCoins", ctx, moduleName, amt)
ret0, _ := ret[0].(error)
@ -308,7 +307,7 @@ func (mr *MockBankKeeperMockRecorder) MintCoins(ctx, moduleName, amt interface{}
}
// SendCoinsFromModuleToAccount mocks base method.
func (m *MockBankKeeper) SendCoinsFromModuleToAccount(ctx types1.Context, senderModule string, recipientAddr types1.AccAddress, amt types1.Coins) error {
func (m *MockBankKeeper) SendCoinsFromModuleToAccount(ctx types0.Context, senderModule string, recipientAddr types0.AccAddress, amt types0.Coins) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SendCoinsFromModuleToAccount", ctx, senderModule, recipientAddr, amt)
ret0, _ := ret[0].(error)

View File

@ -7,7 +7,6 @@ import (
st "cosmossdk.io/api/cosmos/staking/v1beta1"
"cosmossdk.io/core/address"
"cosmossdk.io/math"
stakingtypes "cosmossdk.io/x/staking/types"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
@ -18,7 +17,7 @@ type (
// evidence module.
StakingKeeper interface {
ConsensusAddressCodec() address.Codec
ValidatorByConsAddr(context.Context, sdk.ConsAddress) (stakingtypes.ValidatorI, error)
ValidatorByConsAddr(context.Context, sdk.ConsAddress) (sdk.ValidatorI, error)
}
// SlashingKeeper defines the slashing module interface contract needed by the

View File

@ -6,7 +6,6 @@ import (
"cosmossdk.io/collections"
"cosmossdk.io/math"
v1 "cosmossdk.io/x/gov/types/v1"
stakingtypes "cosmossdk.io/x/staking/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
@ -26,7 +25,7 @@ func (keeper Keeper) Tally(ctx context.Context, proposal v1.Proposal) (passes, b
currValidators := make(map[string]v1.ValidatorGovInfo)
// fetch all the bonded validators, insert them into currValidators
err = keeper.sk.IterateBondedValidatorsByPower(ctx, func(index int64, validator stakingtypes.ValidatorI) (stop bool) {
err = keeper.sk.IterateBondedValidatorsByPower(ctx, func(index int64, validator sdk.ValidatorI) (stop bool) {
valBz, err := keeper.sk.ValidatorAddressCodec().StringToBytes(validator.GetOperator())
if err != nil {
return false
@ -63,7 +62,7 @@ func (keeper Keeper) Tally(ctx context.Context, proposal v1.Proposal) (passes, b
}
// iterate over all delegations from voter, deduct from any delegated-to validators
err = keeper.sk.IterateDelegations(ctx, voter, func(index int64, delegation stakingtypes.DelegationI) (stop bool) {
err = keeper.sk.IterateDelegations(ctx, voter, func(index int64, delegation sdk.DelegationI) (stop bool) {
valAddrStr := delegation.GetValidatorAddr()
if val, ok := currValidators[valAddrStr]; ok {

View File

@ -43,7 +43,7 @@ func TestTally(t *testing.T) {
s.mocks.stakingKeeper.EXPECT().
IterateDelegations(s.ctx, voter, gomock.Any()).
DoAndReturn(
func(ctx context.Context, voter sdk.AccAddress, fn func(index int64, d stakingtypes.DelegationI) bool) error {
func(ctx context.Context, voter sdk.AccAddress, fn func(index int64, d sdk.DelegationI) bool) error {
for i, d := range delegations {
fn(int64(i), d)
}
@ -382,7 +382,7 @@ func TestTally(t *testing.T) {
mocks.stakingKeeper.EXPECT().
IterateBondedValidatorsByPower(ctx, gomock.Any()).
DoAndReturn(
func(ctx context.Context, fn func(index int64, validator stakingtypes.ValidatorI) bool) error {
func(ctx context.Context, fn func(index int64, validator sdk.ValidatorI) bool) error {
for i := int64(0); i < int64(numVals); i++ {
fn(i, stakingtypes.Validator{
OperatorAddress: valAddrs[i].String(),

View File

@ -12,8 +12,7 @@ import (
math "cosmossdk.io/math"
keeper "cosmossdk.io/x/bank/keeper"
types "cosmossdk.io/x/bank/types"
types0 "cosmossdk.io/x/staking/types"
types1 "github.com/cosmos/cosmos-sdk/types"
types0 "github.com/cosmos/cosmos-sdk/types"
query "github.com/cosmos/cosmos-sdk/types/query"
gomock "github.com/golang/mock/gomock"
)
@ -56,10 +55,10 @@ func (mr *MockAccountKeeperMockRecorder) AddressCodec() *gomock.Call {
}
// GetAccount mocks base method.
func (m *MockAccountKeeper) GetAccount(ctx context.Context, addr types1.AccAddress) types1.AccountI {
func (m *MockAccountKeeper) GetAccount(ctx context.Context, addr types0.AccAddress) types0.AccountI {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetAccount", ctx, addr)
ret0, _ := ret[0].(types1.AccountI)
ret0, _ := ret[0].(types0.AccountI)
return ret0
}
@ -70,10 +69,10 @@ func (mr *MockAccountKeeperMockRecorder) GetAccount(ctx, addr interface{}) *gomo
}
// GetModuleAccount mocks base method.
func (m *MockAccountKeeper) GetModuleAccount(ctx context.Context, name string) types1.ModuleAccountI {
func (m *MockAccountKeeper) GetModuleAccount(ctx context.Context, name string) types0.ModuleAccountI {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetModuleAccount", ctx, name)
ret0, _ := ret[0].(types1.ModuleAccountI)
ret0, _ := ret[0].(types0.ModuleAccountI)
return ret0
}
@ -84,10 +83,10 @@ func (mr *MockAccountKeeperMockRecorder) GetModuleAccount(ctx, name interface{})
}
// GetModuleAddress mocks base method.
func (m *MockAccountKeeper) GetModuleAddress(name string) types1.AccAddress {
func (m *MockAccountKeeper) GetModuleAddress(name string) types0.AccAddress {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetModuleAddress", name)
ret0, _ := ret[0].(types1.AccAddress)
ret0, _ := ret[0].(types0.AccAddress)
return ret0
}
@ -98,7 +97,7 @@ func (mr *MockAccountKeeperMockRecorder) GetModuleAddress(name interface{}) *gom
}
// IterateAccounts mocks base method.
func (m *MockAccountKeeper) IterateAccounts(ctx context.Context, cb func(types1.AccountI) bool) {
func (m *MockAccountKeeper) IterateAccounts(ctx context.Context, cb func(types0.AccountI) bool) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "IterateAccounts", ctx, cb)
}
@ -110,7 +109,7 @@ func (mr *MockAccountKeeperMockRecorder) IterateAccounts(ctx, cb interface{}) *g
}
// SetModuleAccount mocks base method.
func (m *MockAccountKeeper) SetModuleAccount(arg0 context.Context, arg1 types1.ModuleAccountI) {
func (m *MockAccountKeeper) SetModuleAccount(arg0 context.Context, arg1 types0.ModuleAccountI) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "SetModuleAccount", arg0, arg1)
}
@ -187,7 +186,7 @@ func (mr *MockBankKeeperMockRecorder) Balance(arg0, arg1 interface{}) *gomock.Ca
}
// BlockedAddr mocks base method.
func (m *MockBankKeeper) BlockedAddr(addr types1.AccAddress) bool {
func (m *MockBankKeeper) BlockedAddr(addr types0.AccAddress) bool {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "BlockedAddr", addr)
ret0, _ := ret[0].(bool)
@ -201,7 +200,7 @@ func (mr *MockBankKeeperMockRecorder) BlockedAddr(addr interface{}) *gomock.Call
}
// BurnCoins mocks base method.
func (m *MockBankKeeper) BurnCoins(ctx context.Context, address []byte, amt types1.Coins) error {
func (m *MockBankKeeper) BurnCoins(ctx context.Context, address []byte, amt types0.Coins) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "BurnCoins", ctx, address, amt)
ret0, _ := ret[0].(error)
@ -227,7 +226,7 @@ func (mr *MockBankKeeperMockRecorder) ClearSendRestriction() *gomock.Call {
}
// DelegateCoins mocks base method.
func (m *MockBankKeeper) DelegateCoins(ctx context.Context, delegatorAddr, moduleAccAddr types1.AccAddress, amt types1.Coins) error {
func (m *MockBankKeeper) DelegateCoins(ctx context.Context, delegatorAddr, moduleAccAddr types0.AccAddress, amt types0.Coins) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "DelegateCoins", ctx, delegatorAddr, moduleAccAddr, amt)
ret0, _ := ret[0].(error)
@ -241,7 +240,7 @@ func (mr *MockBankKeeperMockRecorder) DelegateCoins(ctx, delegatorAddr, moduleAc
}
// DelegateCoinsFromAccountToModule mocks base method.
func (m *MockBankKeeper) DelegateCoinsFromAccountToModule(ctx context.Context, senderAddr types1.AccAddress, recipientModule string, amt types1.Coins) error {
func (m *MockBankKeeper) DelegateCoinsFromAccountToModule(ctx context.Context, senderAddr types0.AccAddress, recipientModule string, amt types0.Coins) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "DelegateCoinsFromAccountToModule", ctx, senderAddr, recipientModule, amt)
ret0, _ := ret[0].(error)
@ -360,10 +359,10 @@ func (mr *MockBankKeeperMockRecorder) GetAccountsBalances(ctx interface{}) *gomo
}
// GetAllBalances mocks base method.
func (m *MockBankKeeper) GetAllBalances(ctx context.Context, addr types1.AccAddress) types1.Coins {
func (m *MockBankKeeper) GetAllBalances(ctx context.Context, addr types0.AccAddress) types0.Coins {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetAllBalances", ctx, addr)
ret0, _ := ret[0].(types1.Coins)
ret0, _ := ret[0].(types0.Coins)
return ret0
}
@ -416,10 +415,10 @@ func (mr *MockBankKeeperMockRecorder) GetAuthority() *gomock.Call {
}
// GetBalance mocks base method.
func (m *MockBankKeeper) GetBalance(ctx context.Context, addr types1.AccAddress, denom string) types1.Coin {
func (m *MockBankKeeper) GetBalance(ctx context.Context, addr types0.AccAddress, denom string) types0.Coin {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetBalance", ctx, addr, denom)
ret0, _ := ret[0].(types1.Coin)
ret0, _ := ret[0].(types0.Coin)
return ret0
}
@ -459,10 +458,10 @@ func (mr *MockBankKeeperMockRecorder) GetDenomMetaData(ctx, denom interface{}) *
}
// GetPaginatedTotalSupply mocks base method.
func (m *MockBankKeeper) GetPaginatedTotalSupply(ctx context.Context, pagination *query.PageRequest) (types1.Coins, *query.PageResponse, error) {
func (m *MockBankKeeper) GetPaginatedTotalSupply(ctx context.Context, pagination *query.PageRequest) (types0.Coins, *query.PageResponse, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetPaginatedTotalSupply", ctx, pagination)
ret0, _ := ret[0].(types1.Coins)
ret0, _ := ret[0].(types0.Coins)
ret1, _ := ret[1].(*query.PageResponse)
ret2, _ := ret[2].(error)
return ret0, ret1, ret2
@ -504,10 +503,10 @@ func (mr *MockBankKeeperMockRecorder) GetSendEnabledEntry(ctx, denom interface{}
}
// GetSupply mocks base method.
func (m *MockBankKeeper) GetSupply(ctx context.Context, denom string) types1.Coin {
func (m *MockBankKeeper) GetSupply(ctx context.Context, denom string) types0.Coin {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetSupply", ctx, denom)
ret0, _ := ret[0].(types1.Coin)
ret0, _ := ret[0].(types0.Coin)
return ret0
}
@ -518,7 +517,7 @@ func (mr *MockBankKeeperMockRecorder) GetSupply(ctx, denom interface{}) *gomock.
}
// HasBalance mocks base method.
func (m *MockBankKeeper) HasBalance(ctx context.Context, addr types1.AccAddress, amt types1.Coin) bool {
func (m *MockBankKeeper) HasBalance(ctx context.Context, addr types0.AccAddress, amt types0.Coin) bool {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "HasBalance", ctx, addr, amt)
ret0, _ := ret[0].(bool)
@ -586,7 +585,7 @@ func (mr *MockBankKeeperMockRecorder) InputOutputCoins(ctx, input, outputs inter
}
// IsSendEnabledCoin mocks base method.
func (m *MockBankKeeper) IsSendEnabledCoin(ctx context.Context, coin types1.Coin) bool {
func (m *MockBankKeeper) IsSendEnabledCoin(ctx context.Context, coin types0.Coin) bool {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "IsSendEnabledCoin", ctx, coin)
ret0, _ := ret[0].(bool)
@ -600,7 +599,7 @@ func (mr *MockBankKeeperMockRecorder) IsSendEnabledCoin(ctx, coin interface{}) *
}
// IsSendEnabledCoins mocks base method.
func (m *MockBankKeeper) IsSendEnabledCoins(ctx context.Context, coins ...types1.Coin) error {
func (m *MockBankKeeper) IsSendEnabledCoins(ctx context.Context, coins ...types0.Coin) error {
m.ctrl.T.Helper()
varargs := []interface{}{ctx}
for _, a := range coins {
@ -633,7 +632,7 @@ func (mr *MockBankKeeperMockRecorder) IsSendEnabledDenom(ctx, denom interface{})
}
// IterateAccountBalances mocks base method.
func (m *MockBankKeeper) IterateAccountBalances(ctx context.Context, addr types1.AccAddress, cb func(types1.Coin) bool) {
func (m *MockBankKeeper) IterateAccountBalances(ctx context.Context, addr types0.AccAddress, cb func(types0.Coin) bool) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "IterateAccountBalances", ctx, addr, cb)
}
@ -645,7 +644,7 @@ func (mr *MockBankKeeperMockRecorder) IterateAccountBalances(ctx, addr, cb inter
}
// IterateAllBalances mocks base method.
func (m *MockBankKeeper) IterateAllBalances(ctx context.Context, cb func(types1.AccAddress, types1.Coin) bool) {
func (m *MockBankKeeper) IterateAllBalances(ctx context.Context, cb func(types0.AccAddress, types0.Coin) bool) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "IterateAllBalances", ctx, cb)
}
@ -681,7 +680,7 @@ func (mr *MockBankKeeperMockRecorder) IterateSendEnabledEntries(ctx, cb interfac
}
// IterateTotalSupply mocks base method.
func (m *MockBankKeeper) IterateTotalSupply(ctx context.Context, cb func(types1.Coin) bool) {
func (m *MockBankKeeper) IterateTotalSupply(ctx context.Context, cb func(types0.Coin) bool) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "IterateTotalSupply", ctx, cb)
}
@ -693,10 +692,10 @@ func (mr *MockBankKeeperMockRecorder) IterateTotalSupply(ctx, cb interface{}) *g
}
// LockedCoins mocks base method.
func (m *MockBankKeeper) LockedCoins(ctx context.Context, addr types1.AccAddress) types1.Coins {
func (m *MockBankKeeper) LockedCoins(ctx context.Context, addr types0.AccAddress) types0.Coins {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "LockedCoins", ctx, addr)
ret0, _ := ret[0].(types1.Coins)
ret0, _ := ret[0].(types0.Coins)
return ret0
}
@ -707,7 +706,7 @@ func (mr *MockBankKeeperMockRecorder) LockedCoins(ctx, addr interface{}) *gomock
}
// MintCoins mocks base method.
func (m *MockBankKeeper) MintCoins(ctx context.Context, moduleName string, amt types1.Coins) error {
func (m *MockBankKeeper) MintCoins(ctx context.Context, moduleName string, amt types0.Coins) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "MintCoins", ctx, moduleName, amt)
ret0, _ := ret[0].(error)
@ -748,7 +747,7 @@ func (mr *MockBankKeeperMockRecorder) PrependSendRestriction(restriction interfa
}
// SendCoins mocks base method.
func (m *MockBankKeeper) SendCoins(ctx context.Context, fromAddr, toAddr types1.AccAddress, amt types1.Coins) error {
func (m *MockBankKeeper) SendCoins(ctx context.Context, fromAddr, toAddr types0.AccAddress, amt types0.Coins) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SendCoins", ctx, fromAddr, toAddr, amt)
ret0, _ := ret[0].(error)
@ -762,7 +761,7 @@ func (mr *MockBankKeeperMockRecorder) SendCoins(ctx, fromAddr, toAddr, amt inter
}
// SendCoinsFromAccountToModule mocks base method.
func (m *MockBankKeeper) SendCoinsFromAccountToModule(ctx context.Context, senderAddr types1.AccAddress, recipientModule string, amt types1.Coins) error {
func (m *MockBankKeeper) SendCoinsFromAccountToModule(ctx context.Context, senderAddr types0.AccAddress, recipientModule string, amt types0.Coins) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SendCoinsFromAccountToModule", ctx, senderAddr, recipientModule, amt)
ret0, _ := ret[0].(error)
@ -776,7 +775,7 @@ func (mr *MockBankKeeperMockRecorder) SendCoinsFromAccountToModule(ctx, senderAd
}
// SendCoinsFromModuleToAccount mocks base method.
func (m *MockBankKeeper) SendCoinsFromModuleToAccount(ctx context.Context, senderModule string, recipientAddr types1.AccAddress, amt types1.Coins) error {
func (m *MockBankKeeper) SendCoinsFromModuleToAccount(ctx context.Context, senderModule string, recipientAddr types0.AccAddress, amt types0.Coins) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SendCoinsFromModuleToAccount", ctx, senderModule, recipientAddr, amt)
ret0, _ := ret[0].(error)
@ -790,7 +789,7 @@ func (mr *MockBankKeeperMockRecorder) SendCoinsFromModuleToAccount(ctx, senderMo
}
// SendCoinsFromModuleToModule mocks base method.
func (m *MockBankKeeper) SendCoinsFromModuleToModule(ctx context.Context, senderModule, recipientModule string, amt types1.Coins) error {
func (m *MockBankKeeper) SendCoinsFromModuleToModule(ctx context.Context, senderModule, recipientModule string, amt types0.Coins) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SendCoinsFromModuleToModule", ctx, senderModule, recipientModule, amt)
ret0, _ := ret[0].(error)
@ -899,10 +898,10 @@ func (mr *MockBankKeeperMockRecorder) SpendableBalances(arg0, arg1 interface{})
}
// SpendableCoin mocks base method.
func (m *MockBankKeeper) SpendableCoin(ctx context.Context, addr types1.AccAddress, denom string) types1.Coin {
func (m *MockBankKeeper) SpendableCoin(ctx context.Context, addr types0.AccAddress, denom string) types0.Coin {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SpendableCoin", ctx, addr, denom)
ret0, _ := ret[0].(types1.Coin)
ret0, _ := ret[0].(types0.Coin)
return ret0
}
@ -913,10 +912,10 @@ func (mr *MockBankKeeperMockRecorder) SpendableCoin(ctx, addr, denom interface{}
}
// SpendableCoins mocks base method.
func (m *MockBankKeeper) SpendableCoins(ctx context.Context, addr types1.AccAddress) types1.Coins {
func (m *MockBankKeeper) SpendableCoins(ctx context.Context, addr types0.AccAddress) types0.Coins {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SpendableCoins", ctx, addr)
ret0, _ := ret[0].(types1.Coins)
ret0, _ := ret[0].(types0.Coins)
return ret0
}
@ -957,7 +956,7 @@ func (mr *MockBankKeeperMockRecorder) TotalSupply(arg0, arg1 interface{}) *gomoc
}
// UndelegateCoins mocks base method.
func (m *MockBankKeeper) UndelegateCoins(ctx context.Context, moduleAccAddr, delegatorAddr types1.AccAddress, amt types1.Coins) error {
func (m *MockBankKeeper) UndelegateCoins(ctx context.Context, moduleAccAddr, delegatorAddr types0.AccAddress, amt types0.Coins) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "UndelegateCoins", ctx, moduleAccAddr, delegatorAddr, amt)
ret0, _ := ret[0].(error)
@ -971,7 +970,7 @@ func (mr *MockBankKeeperMockRecorder) UndelegateCoins(ctx, moduleAccAddr, delega
}
// UndelegateCoinsFromModuleToAccount mocks base method.
func (m *MockBankKeeper) UndelegateCoinsFromModuleToAccount(ctx context.Context, senderModule string, recipientAddr types1.AccAddress, amt types1.Coins) error {
func (m *MockBankKeeper) UndelegateCoinsFromModuleToAccount(ctx context.Context, senderModule string, recipientAddr types0.AccAddress, amt types0.Coins) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "UndelegateCoinsFromModuleToAccount", ctx, senderModule, recipientAddr, amt)
ret0, _ := ret[0].(error)
@ -985,7 +984,7 @@ func (mr *MockBankKeeperMockRecorder) UndelegateCoinsFromModuleToAccount(ctx, se
}
// ValidateBalance mocks base method.
func (m *MockBankKeeper) ValidateBalance(ctx context.Context, addr types1.AccAddress) error {
func (m *MockBankKeeper) ValidateBalance(ctx context.Context, addr types0.AccAddress) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ValidateBalance", ctx, addr)
ret0, _ := ret[0].(error)
@ -1036,7 +1035,7 @@ func (m *MockPoolKeeper) EXPECT() *MockPoolKeeperMockRecorder {
}
// FundCommunityPool mocks base method.
func (m *MockPoolKeeper) FundCommunityPool(ctx context.Context, amount types1.Coins, sender types1.AccAddress) error {
func (m *MockPoolKeeper) FundCommunityPool(ctx context.Context, amount types0.Coins, sender types0.AccAddress) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "FundCommunityPool", ctx, amount, sender)
ret0, _ := ret[0].(error)
@ -1102,7 +1101,7 @@ func (mr *MockStakingKeeperMockRecorder) IterateBondedValidatorsByPower(arg0, ar
}
// IterateDelegations mocks base method.
func (m *MockStakingKeeper) IterateDelegations(ctx context.Context, delegator types1.AccAddress, fn func(int64, types0.DelegationI) bool) error {
func (m *MockStakingKeeper) IterateDelegations(ctx context.Context, delegator types0.AccAddress, fn func(int64, types0.DelegationI) bool) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "IterateDelegations", ctx, delegator, fn)
ret0, _ := ret[0].(error)

View File

@ -5,7 +5,6 @@ import (
addresscodec "cosmossdk.io/core/address"
"cosmossdk.io/math"
stakingtypes "cosmossdk.io/x/staking/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
@ -15,13 +14,13 @@ type StakingKeeper interface {
ValidatorAddressCodec() addresscodec.Codec
// iterate through bonded validators by operator address, execute func for each validator
IterateBondedValidatorsByPower(
context.Context, func(index int64, validator stakingtypes.ValidatorI) (stop bool),
context.Context, func(index int64, validator sdk.ValidatorI) (stop bool),
) error
TotalBondedTokens(context.Context) (math.Int, error) // total bonded tokens within the validator set
IterateDelegations(
ctx context.Context, delegator sdk.AccAddress,
fn func(index int64, delegation stakingtypes.DelegationI) (stop bool),
fn func(index int64, delegation sdk.DelegationI) (stop bool),
) error
}

View File

@ -15,7 +15,6 @@ import (
"cosmossdk.io/x/slashing/testutil"
stakingkeeper "cosmossdk.io/x/staking/keeper"
stakingtestutil "cosmossdk.io/x/staking/testutil"
stakingtypes "cosmossdk.io/x/staking/types"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
@ -120,5 +119,5 @@ func TestBeginBlocker(t *testing.T) {
// validator should be jailed
validator, err := stakingKeeper.GetValidatorByConsAddr(ctx, sdk.GetConsAddress(pk))
require.NoError(t, err)
require.Equal(t, stakingtypes.Unbonding, validator.GetStatus())
require.Equal(t, sdk.Unbonding, validator.GetStatus())
}

View File

@ -4,7 +4,6 @@ import (
"context"
"cosmossdk.io/x/slashing/types"
stakingtypes "cosmossdk.io/x/staking/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
@ -13,7 +12,7 @@ import (
// pubkey map.
func (keeper Keeper) InitGenesis(ctx context.Context, stakingKeeper types.StakingKeeper, data *types.GenesisState) {
err := stakingKeeper.IterateValidators(ctx,
func(index int64, validator stakingtypes.ValidatorI) bool {
func(index int64, validator sdk.ValidatorI) bool {
consPk, err := validator.ConsPubKey()
if err != nil {
panic(err)

View File

@ -196,10 +196,10 @@ func (mr *MockStakingKeeperMockRecorder) ConsensusAddressCodec() *gomock.Call {
}
// Delegation mocks base method.
func (m *MockStakingKeeper) Delegation(arg0 context.Context, arg1 types0.AccAddress, arg2 types0.ValAddress) (types.DelegationI, error) {
func (m *MockStakingKeeper) Delegation(arg0 context.Context, arg1 types0.AccAddress, arg2 types0.ValAddress) (types0.DelegationI, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Delegation", arg0, arg1, arg2)
ret0, _ := ret[0].(types.DelegationI)
ret0, _ := ret[0].(types0.DelegationI)
ret1, _ := ret[1].(error)
return ret0, ret1
}
@ -241,7 +241,7 @@ func (mr *MockStakingKeeperMockRecorder) IsValidatorJailed(ctx, addr interface{}
}
// IterateValidators mocks base method.
func (m *MockStakingKeeper) IterateValidators(arg0 context.Context, arg1 func(int64, types.ValidatorI) bool) error {
func (m *MockStakingKeeper) IterateValidators(arg0 context.Context, arg1 func(int64, types0.ValidatorI) bool) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "IterateValidators", arg0, arg1)
ret0, _ := ret[0].(error)
@ -328,10 +328,10 @@ func (mr *MockStakingKeeperMockRecorder) Unjail(arg0, arg1 interface{}) *gomock.
}
// Validator mocks base method.
func (m *MockStakingKeeper) Validator(arg0 context.Context, arg1 types0.ValAddress) (types.ValidatorI, error) {
func (m *MockStakingKeeper) Validator(arg0 context.Context, arg1 types0.ValAddress) (types0.ValidatorI, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Validator", arg0, arg1)
ret0, _ := ret[0].(types.ValidatorI)
ret0, _ := ret[0].(types0.ValidatorI)
ret1, _ := ret[1].(error)
return ret0, ret1
}
@ -357,10 +357,10 @@ func (mr *MockStakingKeeperMockRecorder) ValidatorAddressCodec() *gomock.Call {
}
// ValidatorByConsAddr mocks base method.
func (m *MockStakingKeeper) ValidatorByConsAddr(arg0 context.Context, arg1 types0.ConsAddress) (types.ValidatorI, error) {
func (m *MockStakingKeeper) ValidatorByConsAddr(arg0 context.Context, arg1 types0.ConsAddress) (types0.ValidatorI, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ValidatorByConsAddr", arg0, arg1)
ret0, _ := ret[0].(types.ValidatorI)
ret0, _ := ret[0].(types0.ValidatorI)
ret1, _ := ret[1].(error)
return ret0, ret1
}

View File

@ -32,10 +32,10 @@ type StakingKeeper interface {
ConsensusAddressCodec() address.Codec
// iterate through validators by operator address, execute func for each validator
IterateValidators(context.Context,
func(index int64, validator stakingtypes.ValidatorI) (stop bool)) error
func(index int64, validator sdk.ValidatorI) (stop bool)) error
Validator(context.Context, sdk.ValAddress) (stakingtypes.ValidatorI, error) // get a particular validator by operator address
ValidatorByConsAddr(context.Context, sdk.ConsAddress) (stakingtypes.ValidatorI, error) // get a particular validator by consensus address
Validator(context.Context, sdk.ValAddress) (sdk.ValidatorI, error) // get a particular validator by operator address
ValidatorByConsAddr(context.Context, sdk.ConsAddress) (sdk.ValidatorI, error) // get a particular validator by consensus address
// slash the validator and delegators of the validator, specifying offense height, offense power, and slash fraction
Slash(context.Context, sdk.ConsAddress, int64, int64, math.LegacyDec) (math.Int, error)
@ -45,7 +45,7 @@ type StakingKeeper interface {
// Delegation allows for getting a particular delegation for a given validator
// and delegator outside the scope of the staking module.
Delegation(context.Context, sdk.AccAddress, sdk.ValAddress) (stakingtypes.DelegationI, error)
Delegation(context.Context, sdk.AccAddress, sdk.ValAddress) (sdk.DelegationI, error)
GetAllValidators(ctx context.Context) ([]stakingtypes.Validator, error)
// MaxValidators returns the maximum amount of bonded validators

View File

@ -31,4 +31,6 @@ Ref: https://keepachangelog.com/en/1.0.0/
### API Breaking Changes
* [#18198](https://github.com/cosmos/cosmos-sdk/pull/18198): `Validator` and `Delegator` interfaces were moved to `github.com/cosmos/cosmos-sdk/types` to avoid interface dependency on staking in other modules.
### Bug Fixes

View File

@ -13,7 +13,7 @@ import (
// Validator Set
// IterateValidators iterates through the validator set and perform the provided function
func (k Keeper) IterateValidators(ctx context.Context, fn func(index int64, validator types.ValidatorI) (stop bool)) error {
func (k Keeper) IterateValidators(ctx context.Context, fn func(index int64, validator sdk.ValidatorI) (stop bool)) error {
store := k.storeService.OpenKVStore(ctx)
iterator, err := store.Iterator(types.ValidatorsKey, storetypes.PrefixEndBytes(types.ValidatorsKey))
if err != nil {
@ -40,7 +40,7 @@ func (k Keeper) IterateValidators(ctx context.Context, fn func(index int64, vali
}
// IterateBondedValidatorsByPower iterates through the bonded validator set and perform the provided function
func (k Keeper) IterateBondedValidatorsByPower(ctx context.Context, fn func(index int64, validator types.ValidatorI) (stop bool)) error {
func (k Keeper) IterateBondedValidatorsByPower(ctx context.Context, fn func(index int64, validator sdk.ValidatorI) (stop bool)) error {
store := k.storeService.OpenKVStore(ctx)
maxValidators, err := k.MaxValidators(ctx)
if err != nil {
@ -71,12 +71,12 @@ func (k Keeper) IterateBondedValidatorsByPower(ctx context.Context, fn func(inde
}
// Validator gets the Validator interface for a particular address
func (k Keeper) Validator(ctx context.Context, address sdk.ValAddress) (types.ValidatorI, error) {
func (k Keeper) Validator(ctx context.Context, address sdk.ValAddress) (sdk.ValidatorI, error) {
return k.GetValidator(ctx, address)
}
// ValidatorByConsAddr gets the validator interface for a particular pubkey
func (k Keeper) ValidatorByConsAddr(ctx context.Context, addr sdk.ConsAddress) (types.ValidatorI, error) {
func (k Keeper) ValidatorByConsAddr(ctx context.Context, addr sdk.ConsAddress) (sdk.ValidatorI, error) {
return k.GetValidatorByConsAddr(ctx, addr)
}
@ -88,13 +88,13 @@ func (k Keeper) GetValidatorSet() types.ValidatorSet {
}
// Delegation gets the delegation interface for a particular set of delegator and validator addresses
func (k Keeper) Delegation(ctx context.Context, addrDel sdk.AccAddress, addrVal sdk.ValAddress) (types.DelegationI, error) {
func (k Keeper) Delegation(ctx context.Context, addrDel sdk.AccAddress, addrVal sdk.ValAddress) (sdk.DelegationI, error) {
return k.Delegations.Get(ctx, collections.Join(addrDel, addrVal))
}
// IterateDelegations iterates through all of the delegations from a delegator
func (k Keeper) IterateDelegations(ctx context.Context, delAddr sdk.AccAddress,
fn func(index int64, del types.DelegationI) (stop bool),
fn func(index int64, del sdk.DelegationI) (stop bool),
) error {
var i int64
rng := collections.NewPrefixedPairRange[sdk.AccAddress, sdk.ValAddress](delAddr)

View File

@ -1077,7 +1077,7 @@ func (k Keeper) BeginRedelegation(
return time.Time{}, types.ErrTinyRedelegationAmount
}
sharesCreated, err := k.Delegate(ctx, delAddr, returnAmount, srcValidator.GetStatus(), dstValidator, false)
sharesCreated, err := k.Delegate(ctx, delAddr, returnAmount, types.BondStatus(srcValidator.GetStatus()), dstValidator, false)
if err != nil {
return time.Time{}, err
}

View File

@ -72,14 +72,14 @@ func (k Keeper) InitGenesis(ctx context.Context, data *types.GenesisState) (res
}
switch validator.GetStatus() {
case types.Bonded:
case sdk.Bonded:
bondedTokens = bondedTokens.Add(validator.GetTokens())
case types.Unbonding, types.Unbonded:
case sdk.Unbonding, sdk.Unbonded:
notBondedTokens = notBondedTokens.Add(validator.GetTokens())
default:
panic("invalid validator status")
panic(fmt.Sprintf("invalid validator status: %v", validator.GetStatus()))
}
}

View File

@ -58,11 +58,11 @@ func ModuleAccountInvariants(k *Keeper) sdk.Invariant {
panic(err)
}
err = k.IterateValidators(ctx, func(_ int64, validator types.ValidatorI) bool {
err = k.IterateValidators(ctx, func(_ int64, validator sdk.ValidatorI) bool {
switch validator.GetStatus() {
case types.Bonded:
case sdk.Bonded:
bonded = bonded.Add(validator.GetTokens())
case types.Unbonding, types.Unbonded:
case sdk.Unbonding, sdk.Unbonded:
notBonded = notBonded.Add(validator.GetTokens())
default:
panic("invalid validator status")

View File

@ -645,8 +645,8 @@ func (k msgServer) RotateConsPubKey(ctx context.Context, msg *types.MsgRotateCon
return nil, types.ErrNoValidatorFound
}
if status := validator2.GetStatus(); status != types.Bonded {
return nil, errorsmod.Wrapf(sdkerrors.ErrInvalidType, "validator status is not bonded, got %s", status.String())
if status := validator2.GetStatus(); status != sdk.Bonded {
return nil, errorsmod.Wrapf(sdkerrors.ErrInvalidType, "validator status is not bonded, got %x", status)
}
// Check if the validator is exceeding parameter MaxConsPubKeyRotations within the

View File

@ -182,11 +182,11 @@ func (k Keeper) Slash(ctx context.Context, consAddr sdk.ConsAddress, infractionH
}
switch validator.GetStatus() {
case types.Bonded:
case sdk.Bonded:
if err := k.burnBondedTokens(ctx, tokensToBurn); err != nil {
return math.NewInt(0), err
}
case types.Unbonding, types.Unbonded:
case sdk.Unbonding, sdk.Unbonded:
if err := k.burnNotBondedTokens(ctx, tokensToBurn); err != nil {
return math.NewInt(0), err
}

View File

@ -307,10 +307,10 @@ func (m *MockValidatorSet) EXPECT() *MockValidatorSetMockRecorder {
}
// Delegation mocks base method.
func (m *MockValidatorSet) Delegation(arg0 context.Context, arg1 types0.AccAddress, arg2 types0.ValAddress) (types.DelegationI, error) {
func (m *MockValidatorSet) Delegation(arg0 context.Context, arg1 types0.AccAddress, arg2 types0.ValAddress) (types0.DelegationI, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Delegation", arg0, arg1, arg2)
ret0, _ := ret[0].(types.DelegationI)
ret0, _ := ret[0].(types0.DelegationI)
ret1, _ := ret[1].(error)
return ret0, ret1
}
@ -337,7 +337,7 @@ func (mr *MockValidatorSetMockRecorder) GetPubKeyByConsAddr(arg0, arg1 interface
}
// IterateBondedValidatorsByPower mocks base method.
func (m *MockValidatorSet) IterateBondedValidatorsByPower(arg0 context.Context, arg1 func(int64, types.ValidatorI) bool) error {
func (m *MockValidatorSet) IterateBondedValidatorsByPower(arg0 context.Context, arg1 func(int64, types0.ValidatorI) bool) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "IterateBondedValidatorsByPower", arg0, arg1)
ret0, _ := ret[0].(error)
@ -351,7 +351,7 @@ func (mr *MockValidatorSetMockRecorder) IterateBondedValidatorsByPower(arg0, arg
}
// IterateValidators mocks base method.
func (m *MockValidatorSet) IterateValidators(arg0 context.Context, arg1 func(int64, types.ValidatorI) bool) error {
func (m *MockValidatorSet) IterateValidators(arg0 context.Context, arg1 func(int64, types0.ValidatorI) bool) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "IterateValidators", arg0, arg1)
ret0, _ := ret[0].(error)
@ -468,10 +468,10 @@ func (mr *MockValidatorSetMockRecorder) Unjail(arg0, arg1 interface{}) *gomock.C
}
// Validator mocks base method.
func (m *MockValidatorSet) Validator(arg0 context.Context, arg1 types0.ValAddress) (types.ValidatorI, error) {
func (m *MockValidatorSet) Validator(arg0 context.Context, arg1 types0.ValAddress) (types0.ValidatorI, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Validator", arg0, arg1)
ret0, _ := ret[0].(types.ValidatorI)
ret0, _ := ret[0].(types0.ValidatorI)
ret1, _ := ret[1].(error)
return ret0, ret1
}
@ -483,10 +483,10 @@ func (mr *MockValidatorSetMockRecorder) Validator(arg0, arg1 interface{}) *gomoc
}
// ValidatorByConsAddr mocks base method.
func (m *MockValidatorSet) ValidatorByConsAddr(arg0 context.Context, arg1 types0.ConsAddress) (types.ValidatorI, error) {
func (m *MockValidatorSet) ValidatorByConsAddr(arg0 context.Context, arg1 types0.ConsAddress) (types0.ValidatorI, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ValidatorByConsAddr", arg0, arg1)
ret0, _ := ret[0].(types.ValidatorI)
ret0, _ := ret[0].(types0.ValidatorI)
ret1, _ := ret[1].(error)
return ret0, ret1
}
@ -535,7 +535,7 @@ func (mr *MockDelegationSetMockRecorder) GetValidatorSet() *gomock.Call {
}
// IterateDelegations mocks base method.
func (m *MockDelegationSet) IterateDelegations(ctx context.Context, delegator types0.AccAddress, fn func(int64, types.DelegationI) bool) error {
func (m *MockDelegationSet) IterateDelegations(ctx context.Context, delegator types0.AccAddress, fn func(int64, types0.DelegationI) bool) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "IterateDelegations", ctx, delegator, fn)
ret0, _ := ret[0].(error)

View File

@ -13,7 +13,7 @@ import (
)
// Implements Delegation interface
var _ DelegationI = Delegation{}
var _ sdk.DelegationI = Delegation{}
// NewDelegation creates a new delegation object
func NewDelegation(delegatorAddr, validatorAddr string, shares math.LegacyDec) Delegation {

View File

@ -47,16 +47,16 @@ type BankKeeper interface {
type ValidatorSet interface {
// iterate through validators by operator address, execute func for each validator
IterateValidators(context.Context,
func(index int64, validator ValidatorI) (stop bool)) error
func(index int64, validator sdk.ValidatorI) (stop bool)) error
// iterate through bonded validators by operator address, execute func for each validator
IterateBondedValidatorsByPower(context.Context,
func(index int64, validator ValidatorI) (stop bool)) error
func(index int64, validator sdk.ValidatorI) (stop bool)) error
Validator(context.Context, sdk.ValAddress) (ValidatorI, error) // get a particular validator by operator address
ValidatorByConsAddr(context.Context, sdk.ConsAddress) (ValidatorI, error) // get a particular validator by consensus address
TotalBondedTokens(context.Context) (math.Int, error) // total bonded tokens within the validator set
StakingTokenSupply(context.Context) (math.Int, error) // total staking token supply
Validator(context.Context, sdk.ValAddress) (sdk.ValidatorI, error) // get a particular validator by operator address
ValidatorByConsAddr(context.Context, sdk.ConsAddress) (sdk.ValidatorI, error) // get a particular validator by consensus address
TotalBondedTokens(context.Context) (math.Int, error) // total bonded tokens within the validator set
StakingTokenSupply(context.Context) (math.Int, error) // total staking token supply
// slash the validator and delegators of the validator, specifying offense height, offense power, and slash fraction
Slash(context.Context, sdk.ConsAddress, int64, int64, math.LegacyDec) (math.Int, error)
@ -66,7 +66,7 @@ type ValidatorSet interface {
// Delegation allows for getting a particular delegation for a given validator
// and delegator outside the scope of the staking module.
Delegation(context.Context, sdk.AccAddress, sdk.ValAddress) (DelegationI, error)
Delegation(context.Context, sdk.AccAddress, sdk.ValAddress) (sdk.DelegationI, error)
// MaxValidators returns the maximum amount of bonded validators
MaxValidators(context.Context) (uint32, error)
@ -83,7 +83,7 @@ type DelegationSet interface {
// iterate through all delegations from one delegator by validator-AccAddress,
// execute func for each validator
IterateDelegations(ctx context.Context, delegator sdk.AccAddress,
fn func(index int64, delegation DelegationI) (stop bool)) error
fn func(index int64, delegation sdk.DelegationI) (stop bool)) error
}
// Event Hooks

View File

@ -1,41 +0,0 @@
package types
import (
cmtprotocrypto "github.com/cometbft/cometbft/proto/tendermint/crypto"
"cosmossdk.io/math"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
)
// DelegationI delegation bond for a delegated proof of stake system
type DelegationI interface {
GetDelegatorAddr() string // delegator string for the bond
GetValidatorAddr() string // validator operator address
GetShares() math.LegacyDec // amount of validator's shares held in this delegation
}
// ValidatorI expected validator functions
type ValidatorI interface {
IsJailed() bool // whether the validator is jailed
GetMoniker() string // moniker of the validator
GetStatus() BondStatus // status of the validator
IsBonded() bool // check if has a bonded status
IsUnbonded() bool // check if has status unbonded
IsUnbonding() bool // check if has status unbonding
GetOperator() string // operator address to receive/return validators coins
ConsPubKey() (cryptotypes.PubKey, error) // validation consensus pubkey (cryptotypes.PubKey)
TmConsPublicKey() (cmtprotocrypto.PublicKey, error) // validation consensus pubkey (CometBFT)
GetConsAddr() ([]byte, error) // validation consensus address
GetTokens() math.Int // validation tokens
GetBondedTokens() math.Int // validator bonded tokens
GetConsensusPower(math.Int) int64 // validation power in CometBFT
GetCommission() math.LegacyDec // validator commission rate
GetMinSelfDelegation() math.Int // validator minimum self delegation
GetDelegatorShares() math.LegacyDec // total outstanding delegator shares
TokensFromShares(math.LegacyDec) math.LegacyDec // token worth of provided delegator shares
TokensFromSharesTruncated(math.LegacyDec) math.LegacyDec // token worth of provided delegator shares, truncated
TokensFromSharesRoundUp(math.LegacyDec) math.LegacyDec // token worth of provided delegator shares, rounded up
SharesFromTokens(amt math.Int) (math.LegacyDec, error) // shares worth of delegator's bond
SharesFromTokensTruncated(amt math.Int) (math.LegacyDec, error) // truncated shares worth of delegator's bond
}

View File

@ -38,7 +38,7 @@ var (
BondStatusBonded = BondStatus_name[int32(Bonded)]
)
var _ ValidatorI = Validator{}
var _ sdk.ValidatorI = Validator{}
// NewValidator constructs a new Validator
func NewValidator(operator string, pubKey cryptotypes.PubKey, description Description) (Validator, error) {
@ -78,7 +78,7 @@ func (v Validators) String() (out string) {
}
// ToSDKValidators - convenience function convert []Validator to []sdk.ValidatorI
func (v Validators) ToSDKValidators() (validators []ValidatorI) {
func (v Validators) ToSDKValidators() (validators []sdk.ValidatorI) {
for _, val := range v.Validators {
validators = append(validators, val)
}
@ -173,17 +173,17 @@ func UnmarshalValidator(cdc codec.BinaryCodec, value []byte) (v Validator, err e
// IsBonded checks if the validator status equals Bonded
func (v Validator) IsBonded() bool {
return v.GetStatus() == Bonded
return v.GetStatus() == sdk.Bonded
}
// IsUnbonded checks if the validator status equals Unbonded
func (v Validator) IsUnbonded() bool {
return v.GetStatus() == Unbonded
return v.GetStatus() == sdk.Unbonded
}
// IsUnbonding checks if the validator status equals Unbonding
func (v Validator) IsUnbonding() bool {
return v.GetStatus() == Unbonding
return v.GetStatus() == sdk.Unbonding
}
// constant used in flags to indicate that description field should not be updated
@ -456,9 +456,9 @@ func (v *Validator) Equal(v2 *Validator) bool {
v.UnbondingTime.Equal(v2.UnbondingTime)
}
func (v Validator) IsJailed() bool { return v.Jailed }
func (v Validator) GetMoniker() string { return v.Description.Moniker }
func (v Validator) GetStatus() BondStatus { return v.Status }
func (v Validator) IsJailed() bool { return v.Jailed }
func (v Validator) GetMoniker() string { return v.Description.Moniker }
func (v Validator) GetStatus() sdk.BondStatus { return sdk.BondStatus(v.Status) }
func (v Validator) GetOperator() string {
return v.OperatorAddress
}