-
Notifications
You must be signed in to change notification settings - Fork 0
/
ante.go
70 lines (61 loc) · 2.36 KB
/
ante.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package ante
import (
"fmt"
"github.com/furyaxyz/fuxchain/libs/cosmos-sdk/x/mint"
ethcmn "github.com/ethereum/go-ethereum/common"
ethermint "github.com/furyaxyz/fuxchain/app/types"
sdk "github.com/furyaxyz/fuxchain/libs/cosmos-sdk/types"
"github.com/furyaxyz/fuxchain/libs/cosmos-sdk/x/auth"
evmtypes "github.com/furyaxyz/fuxchain/x/evm/types"
"github.com/furyaxyz/fuxchain/x/gov/types"
"github.com/furyaxyz/fuxchain/x/params"
paramstypes "github.com/furyaxyz/fuxchain/x/params/types"
stakingkeeper "github.com/furyaxyz/fuxchain/x/staking/exported"
stakingtypes "github.com/furyaxyz/fuxchain/x/staking/types"
)
type AnteDecorator struct {
sk stakingkeeper.Keeper
ak auth.AccountKeeper
pk params.Keeper
}
func NewAnteDecorator(k stakingkeeper.Keeper, ak auth.AccountKeeper, pk params.Keeper) AnteDecorator {
return AnteDecorator{sk: k, ak: ak, pk: pk}
}
func (ad AnteDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) {
for _, m := range tx.GetMsgs() {
switch msg := m.(type) {
case types.MsgSubmitProposal:
switch proposalType := msg.Content.(type) {
case evmtypes.ManageContractByteCodeProposal:
if !ad.sk.IsValidator(ctx, msg.Proposer) {
return ctx, evmtypes.ErrCodeProposerMustBeValidator()
}
// check operation contract
contract := ad.ak.GetAccount(ctx, proposalType.Contract)
contractAcc, ok := contract.(*ethermint.EthAccount)
if !ok || !contractAcc.IsContract() {
return ctx, evmtypes.ErrNotContracAddress(fmt.Errorf(ethcmn.BytesToAddress(proposalType.Contract).String()))
}
//check substitute contract
substitute := ad.ak.GetAccount(ctx, proposalType.SubstituteContract)
substituteAcc, ok := substitute.(*ethermint.EthAccount)
if !ok || !substituteAcc.IsContract() {
return ctx, evmtypes.ErrNotContracAddress(fmt.Errorf(ethcmn.BytesToAddress(proposalType.SubstituteContract).String()))
}
case stakingtypes.ProposeValidatorProposal:
if !ad.sk.IsValidator(ctx, msg.Proposer) {
return ctx, stakingtypes.ErrCodeProposerMustBeValidator
}
case paramstypes.UpgradeProposal:
if err := ad.pk.CheckMsgSubmitProposal(ctx, msg); err != nil {
return ctx, err
}
case mint.ExtraProposal:
if !ad.sk.IsValidator(ctx, msg.Proposer) {
return ctx, mint.ErrProposerMustBeValidator
}
}
}
}
return next(ctx, tx, simulate)
}