@@ -132,10 +132,26 @@ func ParseBlock(b int64, client *pool.Client) (*model.Block, []*model.Tx, []mode
132
132
Height : b ,
133
133
CreateTime : time .Now ().Unix (),
134
134
}
135
+
136
+ blockResults , err := client .BlockResults (ctx , & b )
137
+
138
+ if err != nil {
139
+ time .Sleep (1 * time .Second )
140
+ blockResults , err = client .BlockResults (ctx , & b )
141
+ if err != nil {
142
+ return & blockDoc , nil , nil , utils .ConvertErr (b , "" , "ParseBlockResult" , err )
143
+ }
144
+ }
145
+
146
+ if len (resblock .Block .Txs ) != len (blockResults .TxsResults ) {
147
+ return nil , nil , nil , utils .ConvertErr (b , "" , "block.Txs length not equal blockResult" , nil )
148
+ }
149
+
135
150
txs := make ([]* model.Tx , 0 , len (resblock .Block .Txs ))
136
151
var docMsgs []model.TxMsg
137
- for _ , tx := range resblock .Block .Txs {
138
- tx , msgs , err := ParseTx (tx , resblock .Block , client )
152
+ for index , tx := range resblock .Block .Txs {
153
+ txResult := blockResults .TxsResults [index ]
154
+ tx , msgs , err := ParseTx (tx , txResult , resblock .Block , index )
139
155
if err != nil {
140
156
return & blockDoc , txs , docMsgs , err
141
157
}
@@ -148,7 +164,7 @@ func ParseBlock(b int64, client *pool.Client) (*model.Block, []*model.Tx, []mode
148
164
}
149
165
150
166
// parse iris tx from iris block result tx
151
- func ParseTx (txBytes types.Tx , block * types.Block , client * pool. Client ) (model.Tx , []model.TxMsg , error ) {
167
+ func ParseTx (txBytes types.Tx , txResult * aTypes. ResponseDeliverTx , block * types.Block , index int ) (model.Tx , []model.TxMsg , error ) {
152
168
153
169
var (
154
170
docMsgs []model.TxMsg
@@ -168,18 +184,6 @@ func ParseTx(txBytes types.Tx, block *types.Block, client *pool.Client) (model.T
168
184
}
169
185
fee := msgsdktypes .BuildFee (authTx .GetFee (), authTx .GetGas ())
170
186
memo := authTx .GetMemo ()
171
- ctx := context .Background ()
172
- res , err := client .Tx (ctx , txBytes .Hash (), false )
173
- if err != nil {
174
- time .Sleep (1 * time .Second )
175
- var err1 error
176
- client2 := pool .GetClient ()
177
- res , err1 = client2 .Tx (ctx , txBytes .Hash (), false )
178
- client2 .Release ()
179
- if err1 != nil {
180
- return docTx , docMsgs , utils .ConvertErr (block .Height , txHash , "TxResult" , err1 )
181
- }
182
- }
183
187
184
188
if len (fee .Amount ) > 0 {
185
189
actualFee = fee .Amount [0 ]
@@ -192,19 +196,19 @@ func ParseTx(txBytes types.Tx, block *types.Block, client *pool.Client) (model.T
192
196
Fee : fee ,
193
197
ActualFee : actualFee ,
194
198
Memo : memo ,
195
- TxIndex : res . Index ,
196
- TxId : buildTxId (height , res . Index ),
199
+ TxIndex : uint32 ( index ) ,
200
+ TxId : buildTxId (height , uint32 ( index ) ),
197
201
}
198
202
docTx .Status = utils .TxStatusSuccess
199
- if res . TxResult .Code != 0 {
203
+ if txResult .Code != 0 {
200
204
docTx .Status = utils .TxStatusFail
201
- docTx .Log = res . TxResult .Log
205
+ docTx .Log = txResult .Log
202
206
203
207
}
204
- docTx .Events = parseEvents (res . TxResult .Events )
208
+ docTx .Events = parseEvents (txResult .Events )
205
209
eventsIndexMap := make (map [int ]model.MsgEvent )
206
- if res . TxResult .Code == 0 {
207
- eventsIndexMap = splitEvents (res . TxResult .Log )
210
+ if txResult .Code == 0 {
211
+ eventsIndexMap = splitEvents (txResult .Log )
208
212
}
209
213
210
214
msgs := authTx .GetMsgs ()
@@ -245,12 +249,12 @@ func ParseTx(txBytes types.Tx, block *types.Block, client *pool.Client) (model.T
245
249
TxHash : docTx .TxHash ,
246
250
Type : msgDocInfo .DocTxMsg .Type ,
247
251
MsgIndex : i ,
248
- TxIndex : res . Index ,
252
+ TxIndex : uint32 ( index ) ,
249
253
TxStatus : docTx .Status ,
250
254
TxMemo : memo ,
251
255
TxLog : docTx .Log ,
252
- GasUsed : res . TxResult .GasUsed ,
253
- GasWanted : res . TxResult .GasWanted ,
256
+ GasUsed : txResult .GasUsed ,
257
+ GasWanted : txResult .GasWanted ,
254
258
}
255
259
docMsg .Msg = msgDocInfo .DocTxMsg
256
260
if val , ok := eventsIndexMap [i ]; ok {
0 commit comments