9
9
"filippo.io/age"
10
10
11
11
abci "github.com/cometbft/cometbft/abci/types"
12
+ "github.com/cosmos/cosmos-sdk/baseapp"
12
13
sdk "github.com/cosmos/cosmos-sdk/types"
13
14
"github.com/cosmos/cosmos-sdk/x/auth/signing"
14
15
)
@@ -17,6 +18,41 @@ type BlockList struct {
17
18
Addresses []string `mapstructure:"addresses"`
18
19
}
19
20
21
+ var _ baseapp.TxSelector = & ExtTxSelector {}
22
+
23
+ // ExtTxSelector extends a baseapp.TxSelector with extra tx validation method
24
+ type ExtTxSelector struct {
25
+ baseapp.TxSelector
26
+ TxDecoder sdk.TxDecoder
27
+ ValidateTx func (sdk.Tx ) error
28
+ }
29
+
30
+ func NewExtTxSelector (parent baseapp.TxSelector , txDecoder sdk.TxDecoder , validateTx func (sdk.Tx ) error ) * ExtTxSelector {
31
+ return & ExtTxSelector {
32
+ TxSelector : parent ,
33
+ TxDecoder : txDecoder ,
34
+ ValidateTx : validateTx ,
35
+ }
36
+ }
37
+
38
+ func (ts * ExtTxSelector ) SelectTxForProposal (maxTxBytes , maxBlockGas uint64 , memTx sdk.Tx , txBz []byte ) bool {
39
+ var err error
40
+ if memTx == nil {
41
+ memTx , err = ts .TxDecoder (txBz )
42
+ if err != nil {
43
+ return false
44
+ }
45
+ }
46
+
47
+ if err := ts .ValidateTx (memTx ); err != nil {
48
+ return false
49
+ }
50
+
51
+ // don't pass `memTx` to parent selector so it don't check tx gas wanted against block gas limit,
52
+ // it conflicts with the max-tx-gas-wanted logic.
53
+ return ts .TxSelector .SelectTxForProposal (maxTxBytes , maxBlockGas , nil , txBz )
54
+ }
55
+
20
56
type ProposalHandler struct {
21
57
TxDecoder sdk.TxDecoder
22
58
Identity age.Identity
@@ -77,12 +113,7 @@ func (h *ProposalHandler) SetBlockList(blob []byte) error {
77
113
return nil
78
114
}
79
115
80
- func (h * ProposalHandler ) ValidateTransaction (txBz []byte ) error {
81
- tx , err := h .TxDecoder (txBz )
82
- if err != nil {
83
- return err
84
- }
85
-
116
+ func (h * ProposalHandler ) ValidateTransaction (tx sdk.Tx ) error {
86
117
sigTx , ok := tx .(signing.SigVerifiableTx )
87
118
if ! ok {
88
119
return fmt .Errorf ("tx of type %T does not implement SigVerifiableTx" , tx )
@@ -96,24 +127,15 @@ func (h *ProposalHandler) ValidateTransaction(txBz []byte) error {
96
127
return nil
97
128
}
98
129
99
- func (h * ProposalHandler ) PrepareProposalHandler () sdk.PrepareProposalHandler {
100
- return func (ctx sdk.Context , req abci.RequestPrepareProposal ) abci.ResponsePrepareProposal {
101
- txs := make ([][]byte , 0 , len (req .Txs ))
102
- for _ , txBz := range req .Txs {
103
- if err := h .ValidateTransaction (txBz ); err != nil {
104
- continue
105
- }
106
- txs = append (txs , txBz )
107
- }
108
-
109
- return abci.ResponsePrepareProposal {Txs : txs }
110
- }
111
- }
112
-
113
130
func (h * ProposalHandler ) ProcessProposalHandler () sdk.ProcessProposalHandler {
114
131
return func (ctx sdk.Context , req abci.RequestProcessProposal ) abci.ResponseProcessProposal {
115
132
for _ , txBz := range req .Txs {
116
- if err := h .ValidateTransaction (txBz ); err != nil {
133
+ memTx , err := h .TxDecoder (txBz )
134
+ if err != nil {
135
+ return abci.ResponseProcessProposal {Status : abci .ResponseProcessProposal_REJECT }
136
+ }
137
+
138
+ if err := h .ValidateTransaction (memTx ); err != nil {
117
139
return abci.ResponseProcessProposal {Status : abci .ResponseProcessProposal_REJECT }
118
140
}
119
141
}
0 commit comments