refactor: remove x/auth vesting dependency in x/bank (#10967)
This commit is contained in:
parent
285db0674a
commit
5b69911591
|
@ -11,7 +11,6 @@ import (
|
||||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||||
"github.com/cosmos/cosmos-sdk/types/query"
|
"github.com/cosmos/cosmos-sdk/types/query"
|
||||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||||
vestexported "github.com/cosmos/cosmos-sdk/x/auth/vesting/exported"
|
|
||||||
"github.com/cosmos/cosmos-sdk/x/bank/types"
|
"github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||||
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
|
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
|
||||||
)
|
)
|
||||||
|
@ -471,7 +470,7 @@ func (k BaseKeeper) trackDelegation(ctx sdk.Context, addr sdk.AccAddress, balanc
|
||||||
return sdkerrors.Wrapf(sdkerrors.ErrUnknownAddress, "account %s does not exist", addr)
|
return sdkerrors.Wrapf(sdkerrors.ErrUnknownAddress, "account %s does not exist", addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
vacc, ok := acc.(vestexported.VestingAccount)
|
vacc, ok := acc.(types.VestingAccount)
|
||||||
if ok {
|
if ok {
|
||||||
// TODO: return error on account.TrackDelegation
|
// TODO: return error on account.TrackDelegation
|
||||||
vacc.TrackDelegation(ctx.BlockHeader().Time, balance, amt)
|
vacc.TrackDelegation(ctx.BlockHeader().Time, balance, amt)
|
||||||
|
@ -488,7 +487,7 @@ func (k BaseKeeper) trackUndelegation(ctx sdk.Context, addr sdk.AccAddress, amt
|
||||||
return sdkerrors.Wrapf(sdkerrors.ErrUnknownAddress, "account %s does not exist", addr)
|
return sdkerrors.Wrapf(sdkerrors.ErrUnknownAddress, "account %s does not exist", addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
vacc, ok := acc.(vestexported.VestingAccount)
|
vacc, ok := acc.(types.VestingAccount)
|
||||||
if ok {
|
if ok {
|
||||||
// TODO: return error on account.TrackUndelegation
|
// TODO: return error on account.TrackUndelegation
|
||||||
vacc.TrackUndelegation(amt)
|
vacc.TrackUndelegation(amt)
|
||||||
|
|
|
@ -15,7 +15,6 @@ import (
|
||||||
"github.com/cosmos/cosmos-sdk/types/query"
|
"github.com/cosmos/cosmos-sdk/types/query"
|
||||||
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
|
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
|
||||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/auth/vesting/exported"
|
|
||||||
vesting "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
|
vesting "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/bank/keeper"
|
"github.com/cosmos/cosmos-sdk/x/bank/keeper"
|
||||||
"github.com/cosmos/cosmos-sdk/x/bank/testutil"
|
"github.com/cosmos/cosmos-sdk/x/bank/testutil"
|
||||||
|
@ -888,7 +887,7 @@ func (suite *IntegrationTestSuite) TestDelegateCoins() {
|
||||||
|
|
||||||
// require that delegated vesting amount is equal to what was delegated with DelegateCoins
|
// require that delegated vesting amount is equal to what was delegated with DelegateCoins
|
||||||
acc = app.AccountKeeper.GetAccount(ctx, addr1)
|
acc = app.AccountKeeper.GetAccount(ctx, addr1)
|
||||||
vestingAcc, ok := acc.(exported.VestingAccount)
|
vestingAcc, ok := acc.(types.VestingAccount)
|
||||||
suite.Require().True(ok)
|
suite.Require().True(ok)
|
||||||
suite.Require().Equal(delCoins, vestingAcc.GetDelegatedVesting())
|
suite.Require().Equal(delCoins, vestingAcc.GetDelegatedVesting())
|
||||||
}
|
}
|
||||||
|
@ -968,7 +967,7 @@ func (suite *IntegrationTestSuite) TestUndelegateCoins() {
|
||||||
|
|
||||||
// require that delegated vesting amount is completely empty, since they were completely undelegated
|
// require that delegated vesting amount is completely empty, since they were completely undelegated
|
||||||
acc = app.AccountKeeper.GetAccount(ctx, addr1)
|
acc = app.AccountKeeper.GetAccount(ctx, addr1)
|
||||||
vestingAcc, ok := acc.(exported.VestingAccount)
|
vestingAcc, ok := acc.(types.VestingAccount)
|
||||||
suite.Require().True(ok)
|
suite.Require().True(ok)
|
||||||
suite.Require().Empty(vestingAcc.GetDelegatedVesting())
|
suite.Require().Empty(vestingAcc.GetDelegatedVesting())
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,6 @@ import (
|
||||||
storetypes "github.com/cosmos/cosmos-sdk/store/types"
|
storetypes "github.com/cosmos/cosmos-sdk/store/types"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||||
vestexported "github.com/cosmos/cosmos-sdk/x/auth/vesting/exported"
|
|
||||||
"github.com/cosmos/cosmos-sdk/x/bank/types"
|
"github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -170,7 +169,7 @@ func (k BaseViewKeeper) IterateAllBalances(ctx sdk.Context, cb func(sdk.AccAddre
|
||||||
func (k BaseViewKeeper) LockedCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins {
|
func (k BaseViewKeeper) LockedCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins {
|
||||||
acc := k.ak.GetAccount(ctx, addr)
|
acc := k.ak.GetAccount(ctx, addr)
|
||||||
if acc != nil {
|
if acc != nil {
|
||||||
vacc, ok := acc.(vestexported.VestingAccount)
|
vacc, ok := acc.(types.VestingAccount)
|
||||||
if ok {
|
if ok {
|
||||||
return vacc.LockedCoins(ctx.BlockTime())
|
return vacc.LockedCoins(ctx.BlockTime())
|
||||||
}
|
}
|
||||||
|
@ -220,7 +219,7 @@ func (k BaseViewKeeper) ValidateBalance(ctx sdk.Context, addr sdk.AccAddress) er
|
||||||
return fmt.Errorf("account balance of %s is invalid", balances)
|
return fmt.Errorf("account balance of %s is invalid", balances)
|
||||||
}
|
}
|
||||||
|
|
||||||
vacc, ok := acc.(vestexported.VestingAccount)
|
vacc, ok := acc.(types.VestingAccount)
|
||||||
if ok {
|
if ok {
|
||||||
ogv := vacc.GetOriginalVesting()
|
ogv := vacc.GetOriginalVesting()
|
||||||
if ogv.IsAnyGT(balances) {
|
if ogv.IsAnyGT(balances) {
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
package types
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
// VestingAccount defines an interface used for account vesting.
|
||||||
|
type VestingAccount interface {
|
||||||
|
// LockedCoins returns the set of coins that are not spendable (i.e. locked),
|
||||||
|
// defined as the vesting coins that are not delegated.
|
||||||
|
//
|
||||||
|
// To get spendable coins of a vesting account, first the total balance must
|
||||||
|
// be retrieved and the locked tokens can be subtracted from the total balance.
|
||||||
|
// Note, the spendable balance can be negative.
|
||||||
|
LockedCoins(blockTime time.Time) sdk.Coins
|
||||||
|
|
||||||
|
// TrackDelegation performs internal vesting accounting necessary when
|
||||||
|
// delegating from a vesting account. It accepts the current block time, the
|
||||||
|
// delegation amount and balance of all coins whose denomination exists in
|
||||||
|
// the account's original vesting balance.
|
||||||
|
TrackDelegation(blockTime time.Time, balance, amount sdk.Coins)
|
||||||
|
|
||||||
|
// TrackUndelegation performs internal vesting accounting necessary when a
|
||||||
|
// vesting account performs an undelegation.
|
||||||
|
TrackUndelegation(amount sdk.Coins)
|
||||||
|
|
||||||
|
GetOriginalVesting() sdk.Coins
|
||||||
|
GetDelegatedFree() sdk.Coins
|
||||||
|
GetDelegatedVesting() sdk.Coins
|
||||||
|
}
|
Loading…
Reference in New Issue