add mint request check to ante handle (#130)

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
This commit is contained in:
Lorenz Herzberger 2023-10-09 13:09:01 +02:00 committed by GitHub
parent ec77832ca1
commit 9d2627f04f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 5 deletions

View File

@ -20,6 +20,7 @@ type HandlerOptions struct {
SigGasConsumer func(meter sdk.GasMeter, sig signing.SignatureV2, params authtypes.Params) error SigGasConsumer func(meter sdk.GasMeter, sig signing.SignatureV2, params authtypes.Params) error
TxFeeChecker TxFeeChecker TxFeeChecker TxFeeChecker
MachineKeeper MachineKeeper MachineKeeper MachineKeeper
DaoKeeper DaoKeeper
} }
// NewAnteHandler returns an AnteHandler that checks and increments sequence // NewAnteHandler returns an AnteHandler that checks and increments sequence
@ -41,6 +42,9 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
if options.MachineKeeper == nil { if options.MachineKeeper == nil {
return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "machine keeper is required for ante builder") return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "machine keeper is required for ante builder")
} }
if options.DaoKeeper == nil {
return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "dao keeper is required for ante builder")
}
anteDecorators := []sdk.AnteDecorator{ anteDecorators := []sdk.AnteDecorator{
ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first
@ -49,7 +53,7 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
ante.NewTxTimeoutHeightDecorator(), ante.NewTxTimeoutHeightDecorator(),
ante.NewValidateMemoDecorator(options.AccountKeeper), ante.NewValidateMemoDecorator(options.AccountKeeper),
NewCheckMachineDecorator(options.MachineKeeper), NewCheckMachineDecorator(options.MachineKeeper),
NewCheckMintAddressDecorator(), NewCheckMintAddressDecorator(options.DaoKeeper),
ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper), ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TxFeeChecker), NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TxFeeChecker),
ante.NewSetPubKeyDecorator(options.AccountKeeper), // SetPubKeyDecorator must be called before all signature verification decorators ante.NewSetPubKeyDecorator(options.AccountKeeper), // SetPubKeyDecorator must be called before all signature verification decorators

View File

@ -8,11 +8,13 @@ import (
) )
type CheckMintAddressDecorator struct { type CheckMintAddressDecorator struct {
MintAddress string dk DaoKeeper
} }
func NewCheckMintAddressDecorator() CheckMintAddressDecorator { func NewCheckMintAddressDecorator(dk DaoKeeper) CheckMintAddressDecorator {
return CheckMintAddressDecorator{} return CheckMintAddressDecorator{
dk: dk,
}
} }
func (cmad CheckMintAddressDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { func (cmad CheckMintAddressDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) {
@ -22,7 +24,11 @@ func (cmad CheckMintAddressDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, sim
if ok { if ok {
cfg := config.GetConfig() cfg := config.GetConfig()
if mintMsg.Creator != cfg.MintAddress { if mintMsg.Creator != cfg.MintAddress {
return ctx, errorsmod.Wrapf(daotypes.ErrInvalidMintAddress, "expected: %s; got: %s", cmad.MintAddress, mintMsg.Creator) return ctx, errorsmod.Wrapf(daotypes.ErrInvalidMintAddress, "expected: %s; got: %s", cfg.MintAddress, mintMsg.Creator)
}
_, found := cmad.dk.GetMintRequestByHash(ctx, mintMsg.GetMintRequest().GetLiquidTxHash())
if found {
return ctx, errorsmod.Wrapf(daotypes.ErrAlreadyMinted, "liquid tx hash %s has already been minted", mintMsg.GetMintRequest().GetLiquidTxHash())
} }
} }
} }

View File

@ -5,6 +5,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
daotypes "github.com/planetmint/planetmint-go/x/dao/types"
) )
type MachineKeeper interface { type MachineKeeper interface {
@ -32,3 +33,7 @@ type BankKeeper interface {
SendCoins(ctx sdk.Context, from, to sdk.AccAddress, amt sdk.Coins) error SendCoins(ctx sdk.Context, from, to sdk.AccAddress, amt sdk.Coins) error
SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error
} }
type DaoKeeper interface {
GetMintRequestByHash(ctx sdk.Context, hash string) (val daotypes.MintRequest, found bool)
}

View File

@ -775,6 +775,7 @@ func New(
FeegrantKeeper: app.FeeGrantKeeper, FeegrantKeeper: app.FeeGrantKeeper,
SigGasConsumer: ante.DefaultSigVerificationGasConsumer, SigGasConsumer: ante.DefaultSigVerificationGasConsumer,
MachineKeeper: app.MachineKeeper, MachineKeeper: app.MachineKeeper,
DaoKeeper: app.DaoKeeper,
}, },
) )
if err != nil { if err != nil {