@@ -2,21 +2,41 @@ package host
2
2
3
3
import (
4
4
"encoding/hex"
5
+ "fmt"
5
6
"strconv"
6
7
7
8
abcitypes "github.com/cometbft/cometbft/abci/types"
8
9
ophosttypes "github.com/initia-labs/OPinit/x/ophost/types"
9
10
)
10
11
12
+ func missingAttrsError (missingAttrs map [string ]struct {}) error {
13
+ if len (missingAttrs ) != 0 {
14
+ missingAttrStr := ""
15
+ for attr := range missingAttrs {
16
+ missingAttrStr += attr + " "
17
+ }
18
+ return fmt .Errorf ("missing attributes: %s" , missingAttrs )
19
+ }
20
+ return nil
21
+ }
22
+
11
23
func ParseMsgRecordBatch (eventAttrs []abcitypes.EventAttribute ) (
12
24
submitter string , err error ,
13
25
) {
26
+ missingAttrs := map [string ]struct {}{
27
+ ophosttypes .AttributeKeySubmitter : {},
28
+ }
29
+
14
30
for _ , attr := range eventAttrs {
15
31
switch attr .Key {
16
32
case ophosttypes .AttributeKeySubmitter :
17
33
submitter = attr .Value
34
+ default :
35
+ continue
18
36
}
37
+ delete (missingAttrs , attr .Key )
19
38
}
39
+ err = missingAttrsError (missingAttrs )
20
40
return
21
41
}
22
42
@@ -25,6 +45,14 @@ func ParseMsgUpdateBatchInfo(eventAttrs []abcitypes.EventAttribute) (
25
45
outputIndex uint64 ,
26
46
l2BlockNumber int64 ,
27
47
err error ) {
48
+ missingAttrs := map [string ]struct {}{
49
+ ophosttypes .AttributeKeyBridgeId : {},
50
+ ophosttypes .AttributeKeyBatchChainType : {},
51
+ ophosttypes .AttributeKeyBatchSubmitter : {},
52
+ ophosttypes .AttributeKeyFinalizedOutputIndex : {},
53
+ ophosttypes .AttributeKeyFinalizedL2BlockNumber : {},
54
+ }
55
+
28
56
for _ , attr := range eventAttrs {
29
57
switch attr .Key {
30
58
case ophosttypes .AttributeKeyBridgeId :
@@ -46,15 +74,29 @@ func ParseMsgUpdateBatchInfo(eventAttrs []abcitypes.EventAttribute) (
46
74
if err != nil {
47
75
return
48
76
}
77
+ default :
78
+ continue
49
79
}
80
+ delete (missingAttrs , attr .Key )
50
81
}
82
+ err = missingAttrsError (missingAttrs )
51
83
return
52
84
}
53
85
54
86
func ParseMsgInitiateDeposit (eventAttrs []abcitypes.EventAttribute ) (
55
87
bridgeId , l1Sequence uint64 ,
56
88
from , to , l1Denom , l2Denom , amount string ,
57
89
data []byte , err error ) {
90
+ missingAttrs := map [string ]struct {}{
91
+ ophosttypes .AttributeKeyBridgeId : {},
92
+ ophosttypes .AttributeKeyL1Sequence : {},
93
+ ophosttypes .AttributeKeyFrom : {},
94
+ ophosttypes .AttributeKeyTo : {},
95
+ ophosttypes .AttributeKeyL1Denom : {},
96
+ ophosttypes .AttributeKeyL2Denom : {},
97
+ ophosttypes .AttributeKeyAmount : {},
98
+ ophosttypes .AttributeKeyData : {},
99
+ }
58
100
59
101
for _ , attr := range eventAttrs {
60
102
switch attr .Key {
@@ -83,8 +125,12 @@ func ParseMsgInitiateDeposit(eventAttrs []abcitypes.EventAttribute) (
83
125
if err != nil {
84
126
return
85
127
}
128
+ default :
129
+ continue
86
130
}
131
+ delete (missingAttrs , attr .Key )
87
132
}
133
+ err = missingAttrsError (missingAttrs )
88
134
return
89
135
}
90
136
@@ -95,6 +141,14 @@ func ParseMsgProposeOutput(eventAttrs []abcitypes.EventAttribute) (
95
141
proposer string ,
96
142
outputRoot []byte ,
97
143
err error ) {
144
+ missingAttrs := map [string ]struct {}{
145
+ ophosttypes .AttributeKeyProposer : {},
146
+ ophosttypes .AttributeKeyBridgeId : {},
147
+ ophosttypes .AttributeKeyOutputIndex : {},
148
+ ophosttypes .AttributeKeyL2BlockNumber : {},
149
+ ophosttypes .AttributeKeyOutputRoot : {},
150
+ }
151
+
98
152
for _ , attr := range eventAttrs {
99
153
switch attr .Key {
100
154
case ophosttypes .AttributeKeyProposer :
@@ -119,15 +173,30 @@ func ParseMsgProposeOutput(eventAttrs []abcitypes.EventAttribute) (
119
173
if err != nil {
120
174
return
121
175
}
176
+ default :
177
+ continue
122
178
}
179
+ delete (missingAttrs , attr .Key )
123
180
}
181
+ err = missingAttrsError (missingAttrs )
124
182
return
125
183
}
126
184
127
185
func ParseMsgFinalizeWithdrawal (eventAttrs []abcitypes.EventAttribute ) (
128
186
bridgeId , outputIndex , l2Sequence uint64 ,
129
187
from , to , l1Denom , l2Denom , amount string ,
130
188
err error ) {
189
+ missingAttrs := map [string ]struct {}{
190
+ ophosttypes .AttributeKeyBridgeId : {},
191
+ ophosttypes .AttributeKeyOutputIndex : {},
192
+ ophosttypes .AttributeKeyL2Sequence : {},
193
+ ophosttypes .AttributeKeyFrom : {},
194
+ ophosttypes .AttributeKeyTo : {},
195
+ ophosttypes .AttributeKeyL1Denom : {},
196
+ ophosttypes .AttributeKeyL2Denom : {},
197
+ ophosttypes .AttributeKeyAmount : {},
198
+ }
199
+
131
200
for _ , attr := range eventAttrs {
132
201
switch attr .Key {
133
202
case ophosttypes .AttributeKeyBridgeId :
@@ -155,7 +224,11 @@ func ParseMsgFinalizeWithdrawal(eventAttrs []abcitypes.EventAttribute) (
155
224
l2Denom = attr .Value
156
225
case ophosttypes .AttributeKeyAmount :
157
226
amount = attr .Value
227
+ default :
228
+ continue
158
229
}
230
+ delete (missingAttrs , attr .Key )
159
231
}
232
+ err = missingAttrsError (missingAttrs )
160
233
return
161
234
}
0 commit comments