-
Notifications
You must be signed in to change notification settings - Fork 0
/
ante.go
145 lines (128 loc) · 6.53 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package app
import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
iidante "github.com/furya-official/fury-blockchain/x/iid/ante"
iidkeeper "github.com/furya-official/fury-blockchain/x/iid/keeper"
projectante "github.com/furya-official/fury-blockchain/x/project/ante"
projectkeeper "github.com/furya-official/fury-blockchain/x/project/keeper"
projecttypes "github.com/furya-official/fury-blockchain/x/project/types"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
txsigning "github.com/cosmos/cosmos-sdk/types/tx/signing"
authante "github.com/cosmos/cosmos-sdk/x/auth/ante"
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
// issuerante "github.com/allinbits/cosmos-cash/v3/x/issuer/ante"
// issuerkeeper "github.com/allinbits/cosmos-cash/v3/x/issuer/keeper"
// vcskeeper "github.com/allinbits/cosmos-cash/v3/x/verifiable-credential/keeper"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
)
// NewAnteHandler returns an AnteHandler that checks and increments sequence
// numbers, checks signatures & account numbers, and deducts fees from the first
// signer.
// func FuryAnteHandler(
// ak authante.AccountKeeper,
// bankKeeper authtypes.BankKeeper,
// feeGrantKeeper authante.FeegrantKeeper,
// ik issuerkeeper.Keeper,
// dk didkeeper.Keeper,
// vcsk vcskeeper.Keeper,
// sigGasConsumer authante.SignatureVerificationGasConsumer,
// signModeHandler signing.SignModeHandler,
// ) sdk.AnteHandler {
// return sdk.ChainAnteDecorators(
// authante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first
// authante.NewRejectExtensionOptionsDecorator(),
// authante.NewMempoolFeeDecorator(),
// authante.NewValidateBasicDecorator(),
// authante.TxTimeoutHeightDecorator{},
// authante.NewValidateMemoDecorator(ak),
// authante.NewConsumeGasForTxSizeDecorator(ak),
// authante.NewSetPubKeyDecorator(ak), // SetPubKeyDecorator must be called before all signature verification decorators
// authante.NewValidateSigCountDecorator(ak),
// authante.NewDeductFeeDecorator(ak, bankKeeper, feeGrantKeeper),
// authante.NewSigGasConsumeDecorator(ak, sigGasConsumer),
// authante.NewSigVerificationDecorator(ak, signModeHandler),
// authante.NewIncrementSequenceDecorator(ak),
// issuerante.NewCheckUserCredentialsDecorator(ak, ik, dk, vcsk),
// )
// }
type HandlerOptions struct {
AccountKeeper projectante.AccountKeeper
BankKeeper bankkeeper.Keeper
FeegrantKeeper authante.FeegrantKeeper
IidKeeper iidkeeper.Keeper
ProjectKeeper projectkeeper.Keeper
wasmConfig wasmtypes.WasmConfig
txCounterStoreKey sdk.StoreKey
SignModeHandler authsigning.SignModeHandler
SigGasConsumer func(meter sdk.GasMeter, sig txsigning.SignatureV2, params authtypes.Params) error
}
func checkForCreateProjectMessages(tx sdk.Tx) bool {
for _, msg := range tx.GetMsgs() {
if _, ok := msg.(*projecttypes.MsgCreateProject); ok {
return true
}
}
return false
}
func FuryAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
if options.AccountKeeper == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "account keeper is required for ante builder")
}
if options.BankKeeper == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "bank keeper is required for ante builder")
}
if options.SignModeHandler == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder")
}
// var sigGasConsumer = options.SigGasConsumer
// if sigGasConsumer == nil {
// sigGasConsumer = authante.DefaultSigVerificationGasConsumer
// }
handler := func(ctx sdk.Context, tx sdk.Tx, simulate bool) (newCtx sdk.Context, err error) {
var anteDecorators []sdk.AnteDecorator
if checkForCreateProjectMessages(tx) {
// Handles the custom AnteHandlers necessary for maintaining backwords capability with creating projects via cellnode.
// NOTE: PLEASE REMOVE THIS AT SOME POINT IN THE FUTURE DUE TO POSSIBLE SECURITY ISSUES AND POOR DESIGN.
// NOTE: REFER TO THIS FILE FOR MORE INFORMATION: app/ante.md
anteDecorators = []sdk.AnteDecorator{
projectante.NewSetUpContextDecorator(),
// furyante.NewCheckTxForIncompatibleMsgsDecorator(), // outermost AnteDecorator. SetUpContext must be called first
//ante.NewMempoolFeeDecorator(),
authante.NewValidateBasicDecorator(),
authante.NewValidateMemoDecorator(options.AccountKeeper),
authante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
projectante.NewSetPubKeyDecorator(options.ProjectKeeper, options.AccountKeeper), // SetPubKeyDecorator must be called before all signature verification decorators
authante.NewValidateSigCountDecorator(options.AccountKeeper),
projectante.NewDeductFeeDecorator(options.ProjectKeeper, options.AccountKeeper, options.BankKeeper, options.IidKeeper),
//fury.NewSigGasConsumeDecorator(ak, sigGasConsumer, pubKeyGetter),
projectante.NewSigVerificationDecorator(options.AccountKeeper, options.ProjectKeeper, options.SignModeHandler),
authante.NewIncrementSequenceDecorator(options.AccountKeeper), // innermost AnteDecorator
}
} else {
anteDecorators = []sdk.AnteDecorator{
authante.NewSetUpContextDecorator(),
// furyante.NewCheckTxForIncompatibleMsgsDecorator(),
wasmkeeper.NewLimitSimulationGasDecorator(options.wasmConfig.SimulationGasLimit), // after setup context to enforce limits early
wasmkeeper.NewCountTXDecorator(options.txCounterStoreKey),
authante.NewRejectExtensionOptionsDecorator(),
authante.NewMempoolFeeDecorator(),
authante.NewValidateBasicDecorator(),
authante.NewTxTimeoutHeightDecorator(),
authante.NewValidateMemoDecorator(options.AccountKeeper),
authante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
authante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper),
authante.NewSetPubKeyDecorator(options.AccountKeeper), // SetPubKeyDecorator must be called before all signature verification decorators
authante.NewValidateSigCountDecorator(options.AccountKeeper),
authante.NewSigGasConsumeDecorator(options.AccountKeeper, options.SigGasConsumer),
authante.NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler),
authante.NewIncrementSequenceDecorator(options.AccountKeeper),
iidante.NewIidResolutionDecorator(options.IidKeeper),
}
}
return sdk.ChainAnteDecorators(anteDecorators...)(ctx, tx, simulate)
}
return handler, nil
}