Merge branch 'main' into 124-propose-a-liquid-issuance-to-the-network-unsigned-transaction

Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
This commit is contained in:
Jürgen Eckel 2023-10-10 01:31:28 +02:00
commit 46ec3df289
No known key found for this signature in database
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
TxFeeChecker TxFeeChecker
MachineKeeper MachineKeeper
DaoKeeper DaoKeeper
}
// NewAnteHandler returns an AnteHandler that checks and increments sequence
@ -41,6 +42,9 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
if options.MachineKeeper == nil {
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{
ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first
@ -49,7 +53,7 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
ante.NewTxTimeoutHeightDecorator(),
ante.NewValidateMemoDecorator(options.AccountKeeper),
NewCheckMachineDecorator(options.MachineKeeper),
NewCheckMintAddressDecorator(),
NewCheckMintAddressDecorator(options.DaoKeeper),
NewCheckReissuanceDecorator(),
ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TxFeeChecker),

View File

@ -8,11 +8,13 @@ import (
)
type CheckMintAddressDecorator struct {
MintAddress string
dk DaoKeeper
}
func NewCheckMintAddressDecorator() CheckMintAddressDecorator {
return CheckMintAddressDecorator{}
func NewCheckMintAddressDecorator(dk DaoKeeper) CheckMintAddressDecorator {
return CheckMintAddressDecorator{
dk: dk,
}
}
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 {
cfg := config.GetConfig()
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"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
daotypes "github.com/planetmint/planetmint-go/x/dao/types"
)
type MachineKeeper interface {
@ -32,3 +33,7 @@ type BankKeeper interface {
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
}
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,
SigGasConsumer: ante.DefaultSigVerificationGasConsumer,
MachineKeeper: app.MachineKeeper,
DaoKeeper: app.DaoKeeper,
},
)
if err != nil {