@@ -19,8 +19,8 @@ func (r *Reconciler1) GetStatements1(pos *types.AppPosition, trans *types.Transa
19
19
if ledger10 .AssetOfInterest (r .opts .AssetFilters , base .FAKE_ETH_ADDRESS ) {
20
20
var err error
21
21
reconciled := false
22
- stmt := r .getStatementFromTransaction (trans )
23
22
if ! r .opts .UseTraces {
23
+ stmt := r .getStatementFromTransaction (trans )
24
24
if reconciled , err = r .trialBalance (pos , trans , stmt ); err != nil {
25
25
return nil , err
26
26
} else {
@@ -31,14 +31,15 @@ func (r *Reconciler1) GetStatements1(pos *types.AppPosition, trans *types.Transa
31
31
}
32
32
33
33
if r .opts .UseTraces || ! reconciled {
34
- results = make ([]types.Statement , 0 , 20 ) /* reset this */
35
- if stmt , err := r .getStatementFromTraces (pos , trans , stmt ); err != nil {
34
+ if stmt , err := r .getStatementFromTraces (trans ); err != nil {
36
35
logger .Warn (colors .Yellow + "Statement at " , fmt .Sprintf ("%d.%d" , trans .BlockNumber , trans .TransactionIndex ), " does not reconcile." + colors .Off )
37
36
} else {
38
37
if _ , err = r .trialBalance (pos , trans , stmt ); err != nil {
39
38
return nil , err
40
39
} else {
41
- results = append (results , * stmt )
40
+ if stmt .IsMaterial () {
41
+ results = append (results , * stmt )
42
+ }
42
43
}
43
44
}
44
45
}
@@ -49,21 +50,24 @@ func (r *Reconciler1) GetStatements1(pos *types.AppPosition, trans *types.Transa
49
50
return nil , err
50
51
} else {
51
52
receiptStatements := make ([]types.Statement , 0 , len (statements ))
52
- for _ , s := range statements {
53
- reconciled , _ := r .trialBalance (pos , trans , & s )
54
- if reconciled {
55
- id := fmt .Sprintf (" %d.%d.%d" , s .BlockNumber , s .TransactionIndex , s .LogIndex )
56
- logger .Progress (true , colors .Green + "Transaction" , id , "reconciled " + colors .Off )
53
+ for _ , stmt := range statements {
54
+ if reconciled , err := r .trialBalance (pos , trans , & stmt ); err != nil {
55
+ // TODO: Silent fail?
56
+ continue
57
57
} else {
58
- if os .Getenv ("TEST_MODE" ) != "true" {
59
- id := fmt .Sprintf (" %d.%d.%d" , s .BlockNumber , s .TransactionIndex , s .LogIndex )
60
- logger .Warn ("Log statement at " , id , " does not reconcile." )
58
+ if reconciled {
59
+ id := fmt .Sprintf (" %d.%d.%d" , stmt .BlockNumber , stmt .TransactionIndex , stmt .LogIndex )
60
+ logger .Progress (true , colors .Green + "Transaction" , id , "reconciled " + colors .Off )
61
+ } else {
62
+ if os .Getenv ("TEST_MODE" ) != "true" {
63
+ id := fmt .Sprintf (" %d.%d.%d" , stmt .BlockNumber , stmt .TransactionIndex , stmt .LogIndex )
64
+ logger .Warn ("Log statement at " , id , " does not reconcile." )
65
+ }
66
+ }
67
+ // order matters
68
+ if stmt .IsMaterial () {
69
+ receiptStatements = append (receiptStatements , stmt )
61
70
}
62
- }
63
-
64
- // order matters
65
- if s .IsMaterial () {
66
- receiptStatements = append (receiptStatements , s )
67
71
}
68
72
}
69
73
results = append (results , receiptStatements ... )
@@ -126,40 +130,19 @@ func (r *Reconciler1) getStatementFromTransaction(trans *types.Transaction) *typ
126
130
return stmt
127
131
}
128
132
129
- func (r * Reconciler1 ) getStatementFromTraces (pos * types.AppPosition , trans * types.Transaction , s * types.Statement ) (* types.Statement , error ) {
130
-
131
- stmt := * s
132
- // clear all the internal accounting values. Keeps AmountIn, AmountOut and GasOut because
133
- // those are at the top level (both the transaction itself and trace '0' have them). We
134
- // skip trace '0' because it's the same as the transaction.
135
- // stmt.AmountIn.SetUint64(0)
136
- stmt .InternalIn .SetUint64 (0 )
137
- stmt .MinerBaseRewardIn .SetUint64 (0 )
138
- stmt .MinerNephewRewardIn .SetUint64 (0 )
139
- stmt .MinerTxFeeIn .SetUint64 (0 )
140
- stmt .MinerUncleRewardIn .SetUint64 (0 )
141
- stmt .CorrectingIn .SetUint64 (0 )
142
- stmt .PrefundIn .SetUint64 (0 )
143
- stmt .SelfDestructIn .SetUint64 (0 )
144
-
145
- // stmt.AmountOut.SetUint64(0)
146
- // stmt.GasOut.SetUint64(0)
147
- stmt .InternalOut .SetUint64 (0 )
148
- stmt .CorrectingOut .SetUint64 (0 )
149
- stmt .SelfDestructOut .SetUint64 (0 )
150
-
133
+ func (r * Reconciler1 ) getStatementFromTraces (trans * types.Transaction ) (* types.Statement , error ) {
151
134
if traces , err := r .opts .Connection .GetTracesByTransactionHash (trans .Hash .Hex (), trans ); err != nil {
152
135
return nil , err
153
136
154
137
} else {
155
- // These values accumulate...so we use += instead of =
138
+ stmt := r . getStatementFromTransaction ( trans )
156
139
for i , trace := range traces {
157
140
if i == 0 {
158
141
// the first trace is identical to the transaction itself, so we can skip it
159
142
continue
160
143
}
161
144
162
- if trace .Action .CallType == "delegatecall" && trace .Action .To != s .AccountedFor {
145
+ if trace .Action .CallType == "delegatecall" && trace .Action .To != stmt .AccountedFor {
163
146
// delegate calls are not included in the transaction's gas cost, so we skip them
164
147
continue
165
148
}
@@ -169,7 +152,7 @@ func (r *Reconciler1) getStatementFromTraces(pos *types.AppPosition, trans *type
169
152
}
170
153
171
154
// Do not collapse, more than one of these can be true at the same time
172
- if trace .Action .From == s .AccountedFor {
155
+ if trace .Action .From == stmt .AccountedFor {
173
156
stmt .InternalOut = plusEq (& stmt .InternalOut , & trace .Action .Value )
174
157
stmt .Sender = trace .Action .From
175
158
if trace .Action .To .IsZero () {
@@ -181,13 +164,13 @@ func (r *Reconciler1) getStatementFromTraces(pos *types.AppPosition, trans *type
181
164
}
182
165
}
183
166
184
- if trace .Action .To == s .AccountedFor {
167
+ if trace .Action .To == stmt .AccountedFor {
185
168
stmt .InternalIn = plusEq (& stmt .InternalIn , & trace .Action .Value )
186
169
stmt .Sender = trace .Action .From
187
170
stmt .Recipient = trace .Action .To
188
171
}
189
172
190
- if trace .Action .SelfDestructed == s .AccountedFor {
173
+ if trace .Action .SelfDestructed == stmt .AccountedFor {
191
174
stmt .SelfDestructOut = plusEq (& stmt .SelfDestructOut , & trace .Action .Balance )
192
175
stmt .Sender = trace .Action .SelfDestructed
193
176
if stmt .Sender .IsZero () {
@@ -196,7 +179,7 @@ func (r *Reconciler1) getStatementFromTraces(pos *types.AppPosition, trans *type
196
179
stmt .Recipient = trace .Action .RefundAddress
197
180
}
198
181
199
- if trace .Action .RefundAddress == s .AccountedFor {
182
+ if trace .Action .RefundAddress == stmt .AccountedFor {
200
183
stmt .SelfDestructIn = plusEq (& stmt .SelfDestructIn , & trace .Action .Balance )
201
184
stmt .Sender = trace .Action .SelfDestructed
202
185
if stmt .Sender .IsZero () {
@@ -205,90 +188,98 @@ func (r *Reconciler1) getStatementFromTraces(pos *types.AppPosition, trans *type
205
188
stmt .Recipient = trace .Action .RefundAddress
206
189
}
207
190
208
- if trace .Action .Address == s .AccountedFor && ! trace .Action .RefundAddress .IsZero () {
191
+ if trace .Action .Address == stmt .AccountedFor && ! trace .Action .RefundAddress .IsZero () {
209
192
stmt .SelfDestructOut = plusEq (& stmt .SelfDestructOut , & trace .Action .Balance )
210
193
// self destructed send
211
194
stmt .Sender = trace .Action .Address
212
195
stmt .Recipient = trace .Action .RefundAddress
213
196
}
214
197
215
198
if trace .Result != nil {
216
- if trace .Result .Address == s .AccountedFor {
199
+ if trace .Result .Address == stmt .AccountedFor {
217
200
stmt .InternalIn = plusEq (& stmt .InternalIn , & trace .Action .Value )
218
201
stmt .Sender = trace .Action .From
219
202
stmt .Recipient = trace .Result .Address
220
203
}
221
204
}
222
205
}
206
+ return stmt , nil
223
207
}
224
-
225
- return & stmt , nil
226
208
}
227
209
228
210
func (r * Reconciler1 ) getStatementsFromLogs (logs []types.Log ) ([]types.Statement , error ) {
229
- receiptStatements := make ([]types.Statement , 0 , 20 )
211
+ statements := make ([]types.Statement , 0 , 20 )
230
212
for _ , log := range logs {
231
- if log .Topics [0 ] != topics .TransferTopic {
213
+ pass1 := log .Topics [0 ] == topics .TransferTopic
214
+ if ! pass1 {
232
215
continue
233
216
}
234
- addrArray := []base.Address {r .opts .AccountFor }
235
- if r .opts .AppFilters .ApplyLogFilter (& log , addrArray ) && ledger10 .AssetOfInterest (r .opts .AssetFilters , log .Address ) {
236
- normalized , err := normalize .NormalizeKnownLogs (& log )
237
- if err != nil {
238
- continue
239
- } else if normalized .IsNFT () {
217
+
218
+ pass2 := r .opts .AppFilters .ApplyLogFilter (& log , []base.Address {r .opts .AccountFor })
219
+ if ! pass2 {
220
+ continue
221
+ }
222
+
223
+ pass3 := ledger10 .AssetOfInterest (r .opts .AssetFilters , log .Address )
224
+ if ! pass3 {
225
+ continue
226
+ }
227
+
228
+ normalized , err := normalize .NormalizeKnownLogs (& log )
229
+ if err != nil {
230
+ // TODO: silent fail?
231
+ continue
232
+
233
+ } else if normalized .IsNFT () {
234
+ continue
235
+
236
+ } else {
237
+ sender := base .HexToAddress (normalized .Topics [1 ].Hex ())
238
+ recipient := base .HexToAddress (normalized .Topics [2 ].Hex ())
239
+ isSender , isRecipient := r .opts .AccountFor == sender , r .opts .AccountFor == recipient
240
+ if ! isSender && ! isRecipient {
240
241
continue
241
- } else {
242
- sender := base .HexToAddress (normalized .Topics [1 ].Hex ())
243
- recipient := base .HexToAddress (normalized .Topics [2 ].Hex ())
244
- isSender , isRecipient := r .opts .AccountFor == sender , r .opts .AccountFor == recipient
245
- if ! isSender && ! isRecipient {
246
- continue
247
- }
242
+ }
248
243
249
- sym := normalized .Address .DefaultSymbol ()
250
- decimals := base .Value (18 )
251
- name := r .names [normalized .Address ]
252
- if name .Address == normalized .Address {
253
- if name .Symbol != "" {
254
- sym = name .Symbol
255
- }
256
- if name .Decimals != 0 {
257
- decimals = base .Value (name .Decimals )
258
- }
259
- }
244
+ var amountIn , amountOut base.Wei
245
+ amount , _ := new (base.Wei ).SetString (strings .ReplaceAll (normalized .Data , "0x" , "" ), 16 )
246
+ if amount == nil {
247
+ amount = base .ZeroWei
248
+ }
249
+ if r .opts .AccountFor == sender {
250
+ amountOut = * amount
251
+ }
252
+ if r .opts .AccountFor == recipient {
253
+ amountIn = * amount
254
+ }
255
+ stmt := & types.Statement {
256
+ AccountedFor : r .opts .AccountFor ,
257
+ Sender : sender ,
258
+ Recipient : recipient ,
259
+ BlockNumber : normalized .BlockNumber ,
260
+ TransactionIndex : normalized .TransactionIndex ,
261
+ LogIndex : normalized .LogIndex ,
262
+ TransactionHash : normalized .TransactionHash ,
263
+ Timestamp : normalized .Timestamp ,
264
+ Asset : normalized .Address ,
265
+ PriceSource : "not-priced" ,
266
+ AmountIn : amountIn ,
267
+ AmountOut : amountOut ,
268
+ }
260
269
261
- var amountIn , amountOut base.Wei
262
- amount , _ := new (base.Wei ).SetString (strings .ReplaceAll (normalized .Data , "0x" , "" ), 16 )
263
- if amount == nil {
264
- amount = base .NewWei (0 )
265
- }
266
- if r .opts .AccountFor == sender {
267
- amountOut = * amount
268
- }
269
- if r .opts .AccountFor == recipient {
270
- amountIn = * amount
270
+ name := r .names [stmt .Asset ]
271
+ stmt .Symbol = stmt .Asset .DefaultSymbol ()
272
+ stmt .Decimals = base .Value (18 )
273
+ if name .Address == stmt .Asset {
274
+ if name .Symbol != "" {
275
+ stmt .Symbol = name .Symbol
271
276
}
272
- s := types.Statement {
273
- AccountedFor : r .opts .AccountFor ,
274
- Sender : sender ,
275
- Recipient : recipient ,
276
- BlockNumber : normalized .BlockNumber ,
277
- TransactionIndex : normalized .TransactionIndex ,
278
- LogIndex : normalized .LogIndex ,
279
- TransactionHash : normalized .TransactionHash ,
280
- Timestamp : normalized .Timestamp ,
281
- Asset : normalized .Address ,
282
- Symbol : sym ,
283
- Decimals : decimals ,
284
- SpotPrice : 0.0 ,
285
- PriceSource : "not-priced" ,
286
- AmountIn : amountIn ,
287
- AmountOut : amountOut ,
277
+ if name .Decimals != 0 {
278
+ stmt .Decimals = base .Value (name .Decimals )
288
279
}
289
- receiptStatements = append (receiptStatements , s )
290
280
}
281
+ statements = append (statements , * stmt )
291
282
}
292
283
}
293
- return receiptStatements , nil
284
+ return statements , nil
294
285
}
0 commit comments