-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into 92-implement-pop-result-handler
Signed-off-by: Jürgen Eckel <[email protected]>
- Loading branch information
Showing
110 changed files
with
7,810 additions
and
628 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
--- | ||
run: | ||
timeout: 5m | ||
linters: | ||
enable: | ||
- errcheck | ||
- forbidigo | ||
- gosimple | ||
- govet | ||
- ineffassign | ||
- revive | ||
- staticcheck | ||
- unused | ||
issues: | ||
exclude-rules: | ||
- path: codec\.go | ||
linters: | ||
- nosnakecase | ||
- path: app\/simulation_test\.go | ||
linters: | ||
- nosnakecase | ||
- path: testutil\/rest\.go | ||
linters: | ||
- nosnakecase |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package ante | ||
|
||
import ( | ||
errorsmod "cosmossdk.io/errors" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
assettypes "github.com/planetmint/planetmint-go/x/asset/types" | ||
daotypes "github.com/planetmint/planetmint-go/x/dao/types" | ||
machinetypes "github.com/planetmint/planetmint-go/x/machine/types" | ||
) | ||
|
||
type CheckMachineDecorator struct { | ||
mk MachineKeeper | ||
} | ||
|
||
func NewCheckMachineDecorator(mk MachineKeeper) CheckMachineDecorator { | ||
return CheckMachineDecorator{ | ||
mk: mk, | ||
} | ||
} | ||
|
||
func (cm CheckMachineDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { | ||
for _, msg := range tx.GetMsgs() { | ||
switch sdk.MsgTypeURL(msg) { | ||
case "/planetmintgo.asset.MsgNotarizeAsset": | ||
notarizeMsg, ok := msg.(*assettypes.MsgNotarizeAsset) | ||
if ok { | ||
_, found := cm.mk.GetMachineIndexByAddress(ctx, notarizeMsg.GetCreator()) | ||
if !found { | ||
return ctx, errorsmod.Wrapf(machinetypes.ErrMachineNotFound, "error during CheckTx or ReCheckTx") | ||
} | ||
} | ||
case "/planetmintgo.machine.MsgAttestMachine": | ||
attestMsg, ok := msg.(*machinetypes.MsgAttestMachine) | ||
if ok { | ||
if attestMsg.GetCreator() != attestMsg.Machine.GetAddress() { | ||
return ctx, errorsmod.Wrapf(machinetypes.ErrMachineIsNotCreator, "error during CheckTx or ReCheckTx") | ||
} | ||
_, activated, found := cm.mk.GetTrustAnchor(ctx, attestMsg.Machine.MachineId) | ||
if !found { | ||
return ctx, errorsmod.Wrapf(machinetypes.ErrTrustAnchorNotFound, "error during CheckTx or ReCheckTx") | ||
} | ||
if activated { | ||
return ctx, errorsmod.Wrapf(machinetypes.ErrTrustAnchorAlreadyInUse, "error during CheckTx or ReCheckTx") | ||
} | ||
} | ||
case "planetmintgo.dao.MsgReportPoPResult": | ||
popMsg, ok := msg.(*daotypes.MsgReportPopResult) | ||
if ok { | ||
_, found := cm.mk.GetMachineIndexByAddress(ctx, popMsg.GetCreator()) | ||
if !found { | ||
return ctx, errorsmod.Wrapf(machinetypes.ErrMachineNotFound, "error during CheckTx or ReCheckTx") | ||
} | ||
} | ||
default: | ||
continue | ||
} | ||
} | ||
|
||
return next(ctx, tx, simulate) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package ante | ||
|
||
import ( | ||
errorsmod "cosmossdk.io/errors" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/planetmint/planetmint-go/config" | ||
daotypes "github.com/planetmint/planetmint-go/x/dao/types" | ||
) | ||
|
||
type CheckMintAddressDecorator struct { | ||
dk DaoKeeper | ||
} | ||
|
||
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) { | ||
for _, msg := range tx.GetMsgs() { | ||
if sdk.MsgTypeURL(msg) == "/planetmintgo.dao.MsgMintToken" { | ||
mintMsg, ok := msg.(*daotypes.MsgMintToken) | ||
if ok { | ||
cfg := config.GetConfig() | ||
if mintMsg.Creator != cfg.MintAddress { | ||
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()) | ||
} | ||
} | ||
} | ||
} | ||
|
||
return next(ctx, tx, simulate) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package ante | ||
|
||
import ( | ||
errorsmod "cosmossdk.io/errors" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/planetmint/planetmint-go/config" | ||
"github.com/planetmint/planetmint-go/x/dao" | ||
daotypes "github.com/planetmint/planetmint-go/x/dao/types" | ||
) | ||
|
||
type CheckReissuanceDecorator struct{} | ||
|
||
func NewCheckReissuanceDecorator() CheckReissuanceDecorator { | ||
return CheckReissuanceDecorator{} | ||
} | ||
|
||
func (cmad CheckReissuanceDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { | ||
logger := ctx.Logger() | ||
for _, msg := range tx.GetMsgs() { | ||
if sdk.MsgTypeURL(msg) == "/planetmintgo.dao.MsgReissueRDDLProposal" { | ||
MsgProposal, ok := msg.(*daotypes.MsgReissueRDDLProposal) | ||
if ok { | ||
logger.Debug("REISSUE: receive Proposal") | ||
conf := config.GetConfig() | ||
isValid := dao.IsValidReissuanceCommand(MsgProposal.GetTx(), conf.ReissuanceAsset, MsgProposal.GetBlockHeight()) | ||
if !isValid { | ||
logger.Debug("REISSUE: Invalid Proposal") | ||
return ctx, errorsmod.Wrapf(daotypes.ErrReissuanceProposal, "error during CheckTx or ReCheckTx") | ||
} | ||
} | ||
} | ||
} | ||
|
||
return next(ctx, tx, simulate) | ||
} |
Oops, something went wrong.