diff --git a/CHANGELOG.md b/CHANGELOG.md index b45d148567ef..414d99aae4da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -217,6 +217,7 @@ functionality that requires an online connection. * (client) [\#5895](https://github.com/cosmos/cosmos-sdk/issues/5895) show config options in the config command's help screen. * (types/rest) [\#5900](https://github.com/cosmos/cosmos-sdk/pull/5900) Add Check*Error function family to spare developers from replicating tons of boilerplate code. * (x/evidence) [\#5952](https://github.com/cosmos/cosmos-sdk/pull/5952) Tendermint Consensus parameters can now be changed via parameter change proposals through `x/gov`. +* (x/auth/ante) [\#6040](https://github.com/cosmos/cosmos-sdk/pull/6040) `AccountKeeper` interface used for `NewAnteHandler` and handler's decorators to add support of using custom `AccountKeeper` implementations. ## [v0.38.3] - 2020-04-09 diff --git a/x/auth/ante/ante.go b/x/auth/ante/ante.go index d48cf54228dc..ab9e804b958f 100644 --- a/x/auth/ante/ante.go +++ b/x/auth/ante/ante.go @@ -2,7 +2,6 @@ package ante import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/auth/keeper" "github.com/cosmos/cosmos-sdk/x/auth/types" ibcante "github.com/cosmos/cosmos-sdk/x/ibc/ante" ibckeeper "github.com/cosmos/cosmos-sdk/x/ibc/keeper" @@ -12,7 +11,7 @@ import ( // numbers, checks signatures & account numbers, and deducts fees from the first // signer. func NewAnteHandler( - ak keeper.AccountKeeper, bankKeeper types.BankKeeper, ibcKeeper ibckeeper.Keeper, + ak AccountKeeper, bankKeeper types.BankKeeper, ibcKeeper ibckeeper.Keeper, sigGasConsumer SignatureVerificationGasConsumer, ) sdk.AnteHandler { return sdk.ChainAnteDecorators( diff --git a/x/auth/ante/basic.go b/x/auth/ante/basic.go index 57eceaea68f7..51b203797550 100644 --- a/x/auth/ante/basic.go +++ b/x/auth/ante/basic.go @@ -8,7 +8,6 @@ import ( "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/multisig" - "github.com/cosmos/cosmos-sdk/x/auth/keeper" "github.com/cosmos/cosmos-sdk/x/auth/types" ) @@ -48,10 +47,10 @@ type TxWithMemo interface { // If memo is too large decorator returns with error, otherwise call next AnteHandler // CONTRACT: Tx must implement TxWithMemo interface type ValidateMemoDecorator struct { - ak keeper.AccountKeeper + ak AccountKeeper } -func NewValidateMemoDecorator(ak keeper.AccountKeeper) ValidateMemoDecorator { +func NewValidateMemoDecorator(ak AccountKeeper) ValidateMemoDecorator { return ValidateMemoDecorator{ ak: ak, } @@ -86,10 +85,10 @@ func (vmd ValidateMemoDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate // CONTRACT: To use this decorator, signatures of transaction must be represented // as types.StdSignature otherwise simulate mode will incorrectly estimate gas cost. type ConsumeTxSizeGasDecorator struct { - ak keeper.AccountKeeper + ak AccountKeeper } -func NewConsumeGasForTxSizeDecorator(ak keeper.AccountKeeper) ConsumeTxSizeGasDecorator { +func NewConsumeGasForTxSizeDecorator(ak AccountKeeper) ConsumeTxSizeGasDecorator { return ConsumeTxSizeGasDecorator{ ak: ak, } diff --git a/x/auth/ante/expected_keepers.go b/x/auth/ante/expected_keepers.go new file mode 100644 index 000000000000..ed93b907b9c8 --- /dev/null +++ b/x/auth/ante/expected_keepers.go @@ -0,0 +1,16 @@ +package ante + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/auth/exported" + "github.com/cosmos/cosmos-sdk/x/auth/types" +) + +// AccountKeeper defines the contract needed for AccountKeeper related APIs. +// Interface provides support to use non-sdk AccountKeeper for AnteHandler's decorators. +type AccountKeeper interface { + GetParams(ctx sdk.Context) (params types.Params) + GetAccount(ctx sdk.Context, addr sdk.AccAddress) exported.Account + SetAccount(ctx sdk.Context, acc exported.Account) + GetModuleAddress(moduleName string) sdk.AccAddress +} diff --git a/x/auth/ante/fee.go b/x/auth/ante/fee.go index d15c89332653..5b1044c58664 100644 --- a/x/auth/ante/fee.go +++ b/x/auth/ante/fee.go @@ -6,7 +6,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/auth/exported" - "github.com/cosmos/cosmos-sdk/x/auth/keeper" "github.com/cosmos/cosmos-sdk/x/auth/types" ) @@ -72,11 +71,11 @@ func (mfd MempoolFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate b // Call next AnteHandler if fees successfully deducted // CONTRACT: Tx must implement FeeTx interface to use DeductFeeDecorator type DeductFeeDecorator struct { - ak keeper.AccountKeeper + ak AccountKeeper bankKeeper types.BankKeeper } -func NewDeductFeeDecorator(ak keeper.AccountKeeper, bk types.BankKeeper) DeductFeeDecorator { +func NewDeductFeeDecorator(ak AccountKeeper, bk types.BankKeeper) DeductFeeDecorator { return DeductFeeDecorator{ ak: ak, bankKeeper: bk, diff --git a/x/auth/ante/sigverify.go b/x/auth/ante/sigverify.go index c40712bb0838..93ae0f3b4ae4 100644 --- a/x/auth/ante/sigverify.go +++ b/x/auth/ante/sigverify.go @@ -13,7 +13,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/auth/exported" - "github.com/cosmos/cosmos-sdk/x/auth/keeper" "github.com/cosmos/cosmos-sdk/x/auth/types" ) @@ -49,10 +48,10 @@ type SigVerifiableTx interface { // PubKeys must be set in context for all signers before any other sigverify decorators run // CONTRACT: Tx must implement SigVerifiableTx interface type SetPubKeyDecorator struct { - ak keeper.AccountKeeper + ak AccountKeeper } -func NewSetPubKeyDecorator(ak keeper.AccountKeeper) SetPubKeyDecorator { +func NewSetPubKeyDecorator(ak AccountKeeper) SetPubKeyDecorator { return SetPubKeyDecorator{ ak: ak, } @@ -104,11 +103,11 @@ func (spkd SetPubKeyDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate b // CONTRACT: Pubkeys are set in context for all signers before this decorator runs // CONTRACT: Tx must implement SigVerifiableTx interface type SigGasConsumeDecorator struct { - ak keeper.AccountKeeper + ak AccountKeeper sigGasConsumer SignatureVerificationGasConsumer } -func NewSigGasConsumeDecorator(ak keeper.AccountKeeper, sigGasConsumer SignatureVerificationGasConsumer) SigGasConsumeDecorator { +func NewSigGasConsumeDecorator(ak AccountKeeper, sigGasConsumer SignatureVerificationGasConsumer) SigGasConsumeDecorator { return SigGasConsumeDecorator{ ak: ak, sigGasConsumer: sigGasConsumer, @@ -159,10 +158,10 @@ func (sgcd SigGasConsumeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simula // CONTRACT: Pubkeys are set in context for all signers before this decorator runs // CONTRACT: Tx must implement SigVerifiableTx interface type SigVerificationDecorator struct { - ak keeper.AccountKeeper + ak AccountKeeper } -func NewSigVerificationDecorator(ak keeper.AccountKeeper) SigVerificationDecorator { +func NewSigVerificationDecorator(ak AccountKeeper) SigVerificationDecorator { return SigVerificationDecorator{ ak: ak, } @@ -226,10 +225,10 @@ func (svd SigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simul // a reliable way unless sequence numbers are managed and tracked manually by a // client. It is recommended to instead use multiple messages in a tx. type IncrementSequenceDecorator struct { - ak keeper.AccountKeeper + ak AccountKeeper } -func NewIncrementSequenceDecorator(ak keeper.AccountKeeper) IncrementSequenceDecorator { +func NewIncrementSequenceDecorator(ak AccountKeeper) IncrementSequenceDecorator { return IncrementSequenceDecorator{ ak: ak, } @@ -264,10 +263,10 @@ func (isd IncrementSequenceDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, sim // Use this decorator to set parameterized limit on number of signatures in tx // CONTRACT: Tx must implement SigVerifiableTx interface type ValidateSigCountDecorator struct { - ak keeper.AccountKeeper + ak AccountKeeper } -func NewValidateSigCountDecorator(ak keeper.AccountKeeper) ValidateSigCountDecorator { +func NewValidateSigCountDecorator(ak AccountKeeper) ValidateSigCountDecorator { return ValidateSigCountDecorator{ ak: ak, } @@ -340,7 +339,7 @@ func ConsumeMultisignatureVerificationGas( // GetSignerAcc returns an account for a given address that is expected to sign // a transaction. -func GetSignerAcc(ctx sdk.Context, ak keeper.AccountKeeper, addr sdk.AccAddress) (exported.Account, error) { +func GetSignerAcc(ctx sdk.Context, ak AccountKeeper, addr sdk.AccAddress) (exported.Account, error) { if acc := ak.GetAccount(ctx, addr); acc != nil { return acc, nil }