@stellar-expert/tx-meta-effects-parser 7.0.0-rc.9 → 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.MD +92 -14
- package/package.json +21 -21
- package/src/aggregation/events-analyzer.js +323 -307
- package/src/aggregation/sac-contract-mapper.js +3 -3
- package/src/effect-types.js +104 -101
- package/src/effects-analyzer.js +1142 -1123
- package/src/index.js +226 -233
- package/src/parser/ledger-entry-changes-parser.js +331 -312
- package/src/parser/normalization.js +73 -0
- package/src/parser/tx-xdr-parser-utils.js +299 -322
- package/tmp +0 -100
package/src/effects-analyzer.js
CHANGED
|
@@ -1,1123 +1,1142 @@
|
|
|
1
|
-
const {StrKey, hash, xdr, nativeToScVal} = require('@stellar/stellar-base')
|
|
2
|
-
const effectTypes = require('./effect-types')
|
|
3
|
-
const {
|
|
4
|
-
const {
|
|
5
|
-
const {
|
|
6
|
-
const {contractIdFromPreimage} = require('./parser/contract-preimage-encoder')
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
this.
|
|
31
|
-
this.
|
|
32
|
-
this.
|
|
33
|
-
this.
|
|
34
|
-
this.
|
|
35
|
-
this.
|
|
36
|
-
this.
|
|
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
|
-
* @param {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
const
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
const
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
const
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
this.processDexOperationEffects()
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
this.processDexOperationEffects()
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
this.processDexOperationEffects()
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
this.processDexOperationEffects()
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
const {
|
|
348
|
-
this.
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
this.
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
switch
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
effect.
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
case '
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
case '
|
|
519
|
-
effect.account = before?.
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
effect.
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
effect.
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
const
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
if (before.
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
if (
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
}
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
effect.
|
|
705
|
-
effect.
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
case '
|
|
788
|
-
effect.type = effectTypes.
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
if (
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
const
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
if (
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
const
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
if (
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
effect =
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
const
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
}
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
*
|
|
1089
|
-
* @
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
if (
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
* @
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1
|
+
const {StrKey, hash, xdr, nativeToScVal} = require('@stellar/stellar-base')
|
|
2
|
+
const effectTypes = require('./effect-types')
|
|
3
|
+
const {validateAmount, normalizeAddress, parseLargeInt} = require('./parser/normalization')
|
|
4
|
+
const {parseLedgerEntryChanges} = require('./parser/ledger-entry-changes-parser')
|
|
5
|
+
const {xdrParseAsset, xdrParseAccountAddress, xdrParseScVal} = require('./parser/tx-xdr-parser-utils')
|
|
6
|
+
const {contractIdFromPreimage} = require('./parser/contract-preimage-encoder')
|
|
7
|
+
const {generateContractCodeEntryHash} = require('./parser/ledger-key')
|
|
8
|
+
const {analyzeSignerChanges} = require('./aggregation/signer-changes-analyzer')
|
|
9
|
+
const EventsAnalyzer = require('./aggregation/events-analyzer')
|
|
10
|
+
const AssetSupplyAnalyzer = require('./aggregation/asset-supply-analyzer')
|
|
11
|
+
const {mapSacContract} = require('./aggregation/sac-contract-mapper')
|
|
12
|
+
const {UnexpectedTxMetaChangeError, TxMetaEffectParserError} = require('./errors')
|
|
13
|
+
|
|
14
|
+
class EffectsAnalyzer {
|
|
15
|
+
constructor({
|
|
16
|
+
operation,
|
|
17
|
+
meta,
|
|
18
|
+
result,
|
|
19
|
+
network,
|
|
20
|
+
events,
|
|
21
|
+
diagnosticEvents,
|
|
22
|
+
mapSac,
|
|
23
|
+
processSystemEvents,
|
|
24
|
+
processFailedOpEffects,
|
|
25
|
+
processMetrics
|
|
26
|
+
}) {
|
|
27
|
+
//set execution context
|
|
28
|
+
if (!operation.source)
|
|
29
|
+
throw new TxMetaEffectParserError('Operation source is not explicitly defined')
|
|
30
|
+
this.operation = operation
|
|
31
|
+
this.isContractCall = this.operation.type === 'invokeHostFunction'
|
|
32
|
+
this.result = result
|
|
33
|
+
this.changes = parseLedgerEntryChanges(meta)
|
|
34
|
+
this.source = this.operation.source
|
|
35
|
+
this.events = events
|
|
36
|
+
this.processFailedOpEffects = processFailedOpEffects
|
|
37
|
+
this.processMetrics = processMetrics
|
|
38
|
+
if (diagnosticEvents?.length) {
|
|
39
|
+
this.diagnosticEvents = diagnosticEvents
|
|
40
|
+
if (processSystemEvents) {
|
|
41
|
+
this.processSystemEvents = true
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
this.network = network
|
|
45
|
+
if (mapSac) {
|
|
46
|
+
this.sacMap = new Map()
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @type {{}[]}
|
|
52
|
+
* @internal
|
|
53
|
+
* @readonly
|
|
54
|
+
*/
|
|
55
|
+
effects = []
|
|
56
|
+
/**
|
|
57
|
+
* @type {Object}
|
|
58
|
+
* @private
|
|
59
|
+
* @readonly
|
|
60
|
+
*/
|
|
61
|
+
operation = null
|
|
62
|
+
/**
|
|
63
|
+
* @type {String}
|
|
64
|
+
* @readonly
|
|
65
|
+
*/
|
|
66
|
+
network
|
|
67
|
+
/**
|
|
68
|
+
* @type {Map<string,string>}
|
|
69
|
+
* @readonly
|
|
70
|
+
*/
|
|
71
|
+
sacMap
|
|
72
|
+
/**
|
|
73
|
+
* @type {ParsedLedgerEntryMeta[]}
|
|
74
|
+
* @private
|
|
75
|
+
* @readonly
|
|
76
|
+
*/
|
|
77
|
+
changes = null
|
|
78
|
+
/**
|
|
79
|
+
* @type {Object}
|
|
80
|
+
* @private
|
|
81
|
+
* @readonly
|
|
82
|
+
*/
|
|
83
|
+
result = null
|
|
84
|
+
/**
|
|
85
|
+
* @type {String}
|
|
86
|
+
* @private
|
|
87
|
+
* @readonly
|
|
88
|
+
*/
|
|
89
|
+
source = ''
|
|
90
|
+
/**
|
|
91
|
+
* @type {Boolean}
|
|
92
|
+
* @private
|
|
93
|
+
*/
|
|
94
|
+
isContractCall = false
|
|
95
|
+
/**
|
|
96
|
+
* @type {Boolean}
|
|
97
|
+
* @readonly
|
|
98
|
+
*/
|
|
99
|
+
processSystemEvents = false
|
|
100
|
+
/**
|
|
101
|
+
* @type {Boolean}
|
|
102
|
+
* @readonly
|
|
103
|
+
*/
|
|
104
|
+
processMetrics = true
|
|
105
|
+
/**
|
|
106
|
+
* @type {{}}
|
|
107
|
+
* @private
|
|
108
|
+
*/
|
|
109
|
+
metrics
|
|
110
|
+
|
|
111
|
+
analyze() {
|
|
112
|
+
//find appropriate parser method
|
|
113
|
+
const parse = this[this.operation.type]
|
|
114
|
+
if (parse) {
|
|
115
|
+
parse.call(this)
|
|
116
|
+
}
|
|
117
|
+
//process Soroban events
|
|
118
|
+
new EventsAnalyzer(this).analyze()
|
|
119
|
+
//process state data changes in the end
|
|
120
|
+
this.processStateChanges()
|
|
121
|
+
//process ledger entry changes
|
|
122
|
+
this.processChanges()
|
|
123
|
+
//handle effects that are processed indirectly
|
|
124
|
+
this.processSponsorshipEffects()
|
|
125
|
+
//calculate minted/burned assets
|
|
126
|
+
new AssetSupplyAnalyzer(this).analyze()
|
|
127
|
+
//add Soroban op metrics if available
|
|
128
|
+
if (this.metrics) {
|
|
129
|
+
this.addEffect(this.metrics)
|
|
130
|
+
}
|
|
131
|
+
return this.effects
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* @param {{}} effect
|
|
136
|
+
* @param {Number} [atPosition]
|
|
137
|
+
*/
|
|
138
|
+
addEffect(effect, atPosition) {
|
|
139
|
+
if (!effect.source) {
|
|
140
|
+
effect.source = this.source
|
|
141
|
+
}
|
|
142
|
+
if (atPosition !== undefined) {
|
|
143
|
+
this.effects.splice(atPosition < 0 ? 0 : atPosition, 0, effect)
|
|
144
|
+
} else {
|
|
145
|
+
this.effects.push(effect)
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
debit(amount, asset, source, balance) {
|
|
150
|
+
if (amount === '0')
|
|
151
|
+
return
|
|
152
|
+
const effect = {
|
|
153
|
+
type: effectTypes.accountDebited,
|
|
154
|
+
source,
|
|
155
|
+
asset,
|
|
156
|
+
amount: validateAmount(amount)
|
|
157
|
+
}
|
|
158
|
+
if (balance !== undefined) {
|
|
159
|
+
effect.balance = balance
|
|
160
|
+
}
|
|
161
|
+
this.addEffect(effect)
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
credit(amount, asset, source, balance) {
|
|
165
|
+
if (amount === '0')
|
|
166
|
+
return
|
|
167
|
+
const effect = {
|
|
168
|
+
type: effectTypes.accountCredited,
|
|
169
|
+
source,
|
|
170
|
+
asset,
|
|
171
|
+
amount: validateAmount(amount)
|
|
172
|
+
}
|
|
173
|
+
if (balance !== undefined) {
|
|
174
|
+
effect.balance = balance
|
|
175
|
+
}
|
|
176
|
+
this.addEffect(effect)
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
mint(asset, amount, autoLookupPosition = false) {
|
|
180
|
+
const position = autoLookupPosition ?
|
|
181
|
+
this.effects.findIndex(e => e.asset === asset || e.assets?.find(a => a.asset === asset)) :
|
|
182
|
+
undefined
|
|
183
|
+
this.addEffect({
|
|
184
|
+
type: effectTypes.assetMinted,
|
|
185
|
+
asset,
|
|
186
|
+
amount: validateAmount(amount)
|
|
187
|
+
}, position)
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
burn(asset, amount, position = undefined) {
|
|
191
|
+
this.addEffect({
|
|
192
|
+
type: effectTypes.assetBurned,
|
|
193
|
+
asset,
|
|
194
|
+
amount: validateAmount(amount)
|
|
195
|
+
}, position)
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
addMetric(contract, metric, value) {
|
|
199
|
+
let {metrics} = this
|
|
200
|
+
if (!metrics) {
|
|
201
|
+
metrics = this.metrics = {
|
|
202
|
+
type: effectTypes.contractMetrics,
|
|
203
|
+
contract
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
metrics[metric] = value
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
addFeeMetric(metaValue) {
|
|
210
|
+
const {sorobanMeta} = metaValue._attributes
|
|
211
|
+
if (!sorobanMeta)
|
|
212
|
+
return
|
|
213
|
+
const sorobanExt = sorobanMeta._attributes.ext._value
|
|
214
|
+
if (sorobanExt) {
|
|
215
|
+
const attrs = sorobanExt._attributes
|
|
216
|
+
const fee = {
|
|
217
|
+
nonrefundable: parseInt(parseLargeInt(attrs.totalNonRefundableResourceFeeCharged)),
|
|
218
|
+
refundable: parseInt(parseLargeInt(attrs.totalRefundableResourceFeeCharged)),
|
|
219
|
+
rent: parseInt(parseLargeInt(attrs.rentFeeCharged))
|
|
220
|
+
}
|
|
221
|
+
this.addMetric(this.retrieveOpContractId(), 'fee', fee)
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
setOptions() {
|
|
226
|
+
const sourceAccount = normalizeAddress(this.source)
|
|
227
|
+
const change = this.changes.find(ch => ch.type === 'account' && ch.before.address === sourceAccount)
|
|
228
|
+
if (!change)
|
|
229
|
+
return // failed tx or no changes
|
|
230
|
+
const {before, after} = change
|
|
231
|
+
if (before.homeDomain !== after.homeDomain) {
|
|
232
|
+
this.addEffect({
|
|
233
|
+
type: effectTypes.accountHomeDomainUpdated,
|
|
234
|
+
domain: after.homeDomain
|
|
235
|
+
})
|
|
236
|
+
}
|
|
237
|
+
if (before.thresholds !== after.thresholds) {
|
|
238
|
+
this.addEffect({
|
|
239
|
+
type: effectTypes.accountThresholdsUpdated,
|
|
240
|
+
thresholds: after.thresholds.split(',').map(v => parseInt(v, 10))
|
|
241
|
+
})
|
|
242
|
+
}
|
|
243
|
+
if (before.flags !== after.flags) {
|
|
244
|
+
this.addEffect({
|
|
245
|
+
type: effectTypes.accountFlagsUpdated,
|
|
246
|
+
flags: after.flags,
|
|
247
|
+
prevFlags: before.flags
|
|
248
|
+
})
|
|
249
|
+
}
|
|
250
|
+
if (before.inflationDest !== after.inflationDest) {
|
|
251
|
+
this.addEffect({
|
|
252
|
+
type: effectTypes.accountInflationDestinationUpdated,
|
|
253
|
+
inflationDestination: after.inflationDest
|
|
254
|
+
})
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
allowTrust() {
|
|
259
|
+
this.setTrustLineFlags()
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
setTrustLineFlags() {
|
|
263
|
+
if (!this.changes.length)
|
|
264
|
+
return
|
|
265
|
+
const trustAsset = xdrParseAsset(this.operation.asset || {
|
|
266
|
+
code: this.operation.assetCode,
|
|
267
|
+
issuer: normalizeAddress(this.source)
|
|
268
|
+
})
|
|
269
|
+
const change = this.changes.find(ch => ch.type === 'trustline' && ch.before.asset === trustAsset)
|
|
270
|
+
if (!change)
|
|
271
|
+
return
|
|
272
|
+
if (change.action !== 'updated')
|
|
273
|
+
throw new UnexpectedTxMetaChangeError(change)
|
|
274
|
+
const {before, after} = change
|
|
275
|
+
if (before.flags !== after.flags) {
|
|
276
|
+
this.addEffect({
|
|
277
|
+
type: effectTypes.trustlineAuthorizationUpdated,
|
|
278
|
+
trustor: this.operation.trustor,
|
|
279
|
+
asset: after.asset,
|
|
280
|
+
flags: after.flags,
|
|
281
|
+
prevFlags: before.flags
|
|
282
|
+
})
|
|
283
|
+
for (const change of this.changes) {
|
|
284
|
+
if (change.type !== 'liquidityPool')
|
|
285
|
+
continue
|
|
286
|
+
const {before, after} = change
|
|
287
|
+
this.addEffect({
|
|
288
|
+
type: effectTypes.liquidityPoolWithdrew,
|
|
289
|
+
source: this.operation.trustor,
|
|
290
|
+
pool: before.pool,
|
|
291
|
+
assets: before.asset.map((asset, i) => ({
|
|
292
|
+
asset,
|
|
293
|
+
amount: (BigInt(before.amount[i]) - (after ? BigInt(after.amount[i]) : 0n)).toString()
|
|
294
|
+
})),
|
|
295
|
+
shares: (BigInt(before.shares) - (after ? BigInt(after.shares) : 0n)).toString()
|
|
296
|
+
})
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
inflation() {
|
|
302
|
+
/*const paymentEffects = (result.inflationPayouts || []).map(ip => ({
|
|
303
|
+
type: effectTypes.accountCredited,
|
|
304
|
+
source: ip.account,
|
|
305
|
+
asset: 'XLM',
|
|
306
|
+
amount: ip.amount
|
|
307
|
+
}))*/
|
|
308
|
+
this.addEffect({type: effectTypes.inflation})
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
bumpSequence() {
|
|
312
|
+
if (!this.changes.length)
|
|
313
|
+
return
|
|
314
|
+
const change = this.changes.find(ch => ch.type === 'account')
|
|
315
|
+
if (!change)
|
|
316
|
+
return //failed tx or no changes
|
|
317
|
+
const {before, after} = change
|
|
318
|
+
if (before.sequence !== after.sequence) {
|
|
319
|
+
this.addEffect({
|
|
320
|
+
type: effectTypes.sequenceBumped,
|
|
321
|
+
sequence: after.sequence
|
|
322
|
+
})
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
pathPaymentStrictReceive() {
|
|
327
|
+
this.processDexOperationEffects()
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
pathPaymentStrictSend() {
|
|
331
|
+
this.processDexOperationEffects()
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
manageSellOffer() {
|
|
335
|
+
this.processDexOperationEffects()
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
manageBuyOffer() {
|
|
339
|
+
this.processDexOperationEffects()
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
createPassiveSellOffer() {
|
|
343
|
+
this.processDexOperationEffects()
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
liquidityPoolDeposit() {
|
|
347
|
+
const {liquidityPoolId} = this.operation
|
|
348
|
+
const change = this.changes.find(ch => ch.type === 'liquidityPool' && ch.action === 'updated' && ch.after.pool === liquidityPoolId)
|
|
349
|
+
if (!change) //tx failed
|
|
350
|
+
return
|
|
351
|
+
const {before, after} = change
|
|
352
|
+
this.addEffect({
|
|
353
|
+
type: effectTypes.liquidityPoolDeposited,
|
|
354
|
+
pool: this.operation.liquidityPoolId,
|
|
355
|
+
assets: after.asset.map((asset, i) => ({
|
|
356
|
+
asset,
|
|
357
|
+
amount: (after.amount[i] - before.amount[i]).toString()
|
|
358
|
+
})),
|
|
359
|
+
shares: (after.shares - before.shares).toString(),
|
|
360
|
+
accounts: after.accounts
|
|
361
|
+
})
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
liquidityPoolWithdraw() {
|
|
365
|
+
const pool = this.operation.liquidityPoolId
|
|
366
|
+
const change = this.changes.find(ch => ch.type === 'liquidityPool' && ch.action === 'updated' && ch.before.pool === pool)
|
|
367
|
+
if (!change) //tx failed
|
|
368
|
+
return
|
|
369
|
+
const {before, after} = change
|
|
370
|
+
this.addEffect({
|
|
371
|
+
type: effectTypes.liquidityPoolWithdrew,
|
|
372
|
+
pool,
|
|
373
|
+
assets: before.asset.map((asset, i) => ({
|
|
374
|
+
asset,
|
|
375
|
+
amount: (before.amount[i] - after.amount[i]).toString()
|
|
376
|
+
})),
|
|
377
|
+
shares: (before.shares - after.shares).toString(),
|
|
378
|
+
accounts: after.accounts
|
|
379
|
+
})
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
invokeHostFunction() {
|
|
383
|
+
const {func} = this.operation
|
|
384
|
+
const value = func.value()
|
|
385
|
+
switch (func.arm()) {
|
|
386
|
+
case 'invokeContract':
|
|
387
|
+
if (!this.diagnosticEvents) {
|
|
388
|
+
//add top-level contract invocation effect only if diagnostic events are unavailable
|
|
389
|
+
const rawArgs = value.args()
|
|
390
|
+
const effect = {
|
|
391
|
+
type: effectTypes.contractInvoked,
|
|
392
|
+
contract: xdrParseScVal(value.contractAddress()),
|
|
393
|
+
function: value.functionName().toString(),
|
|
394
|
+
args: rawArgs.map(xdrParseScVal),
|
|
395
|
+
rawArgs: nativeToScVal(rawArgs).toXDR('base64')
|
|
396
|
+
}
|
|
397
|
+
this.addEffect(effect)
|
|
398
|
+
}
|
|
399
|
+
break
|
|
400
|
+
case 'wasm': {
|
|
401
|
+
const codeHash = hash(value)
|
|
402
|
+
this.addEffect({
|
|
403
|
+
type: effectTypes.contractCodeUploaded,
|
|
404
|
+
wasm: value.toString('base64'),
|
|
405
|
+
wasmHash: codeHash.toString('hex'),
|
|
406
|
+
keyHash: generateContractCodeEntryHash(codeHash)
|
|
407
|
+
})
|
|
408
|
+
break
|
|
409
|
+
}
|
|
410
|
+
case 'createContract':
|
|
411
|
+
case 'createContractV2':
|
|
412
|
+
const preimage = value.contractIdPreimage()
|
|
413
|
+
const executable = value.executable()
|
|
414
|
+
const executableType = executable.switch().name
|
|
415
|
+
|
|
416
|
+
const effect = {
|
|
417
|
+
type: effectTypes.contractCreated,
|
|
418
|
+
contract: contractIdFromPreimage(preimage, this.network)
|
|
419
|
+
}
|
|
420
|
+
switch (executableType) {
|
|
421
|
+
case 'contractExecutableWasm':
|
|
422
|
+
effect.kind = 'wasm'
|
|
423
|
+
effect.wasmHash = executable.wasmHash().toString('hex')
|
|
424
|
+
break
|
|
425
|
+
case 'contractExecutableStellarAsset':
|
|
426
|
+
const preimageParams = preimage.value()
|
|
427
|
+
switch (preimage.switch().name) {
|
|
428
|
+
case 'contractIdPreimageFromAddress':
|
|
429
|
+
effect.kind = 'fromAddress'
|
|
430
|
+
effect.issuer = xdrParseAccountAddress(preimageParams.address().value())
|
|
431
|
+
effect.salt = preimageParams.salt().toString('base64')
|
|
432
|
+
break
|
|
433
|
+
case 'contractIdPreimageFromAsset':
|
|
434
|
+
effect.kind = 'fromAsset'
|
|
435
|
+
effect.asset = xdrParseAsset(preimageParams)
|
|
436
|
+
break
|
|
437
|
+
default:
|
|
438
|
+
throw new TxMetaEffectParserError('Unknown preimage type: ' + preimage.switch().name)
|
|
439
|
+
}
|
|
440
|
+
break
|
|
441
|
+
default:
|
|
442
|
+
throw new TxMetaEffectParserError('Unknown contract type: ' + executableType)
|
|
443
|
+
}
|
|
444
|
+
if (func.arm() === 'createContractV2') {
|
|
445
|
+
const args = value.constructorArgs() //array
|
|
446
|
+
if (args.length > 0) {
|
|
447
|
+
effect.constructorArgs = args.map(arg => arg.toXDR('base64'))
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
this.addEffect(effect, 0)
|
|
451
|
+
break
|
|
452
|
+
default:
|
|
453
|
+
throw new TxMetaEffectParserError('Unknown host function call type: ' + func.arm())
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
bumpFootprintExpiration() {
|
|
458
|
+
//const {ledgersToExpire} = this.operation
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
restoreFootprint() {
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
setAdmin(contractId, newAdmin) {
|
|
465
|
+
const effect = {
|
|
466
|
+
type: effectTypes.contractUpdated,
|
|
467
|
+
contract: contractId,
|
|
468
|
+
admin: newAdmin
|
|
469
|
+
}
|
|
470
|
+
this.addEffect(effect)
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
processDexOperationEffects() {
|
|
474
|
+
if (!this.result)
|
|
475
|
+
return
|
|
476
|
+
//process trades first
|
|
477
|
+
for (const claimedOffer of this.result.claimedOffers) {
|
|
478
|
+
const trade = {
|
|
479
|
+
type: effectTypes.trade,
|
|
480
|
+
amount: claimedOffer.amount,
|
|
481
|
+
asset: claimedOffer.asset
|
|
482
|
+
}
|
|
483
|
+
if (claimedOffer.poolId) {
|
|
484
|
+
trade.pool = claimedOffer.poolId.toString('hex')
|
|
485
|
+
} else {
|
|
486
|
+
trade.offer = claimedOffer.offerId
|
|
487
|
+
trade.seller = claimedOffer.account
|
|
488
|
+
|
|
489
|
+
}
|
|
490
|
+
this.addEffect(trade)
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
processSponsorshipEffects() {
|
|
495
|
+
for (const change of this.changes) {
|
|
496
|
+
const {type, action, before, after} = change
|
|
497
|
+
const effect = {}
|
|
498
|
+
switch (action) {
|
|
499
|
+
case 'created':
|
|
500
|
+
case 'restored':
|
|
501
|
+
if (!after.sponsor)
|
|
502
|
+
continue
|
|
503
|
+
effect.sponsor = after.sponsor
|
|
504
|
+
break
|
|
505
|
+
case 'updated':
|
|
506
|
+
if (before.sponsor === after.sponsor)
|
|
507
|
+
continue
|
|
508
|
+
effect.sponsor = after.sponsor
|
|
509
|
+
effect.prevSponsor = before.sponsor
|
|
510
|
+
break
|
|
511
|
+
case 'removed':
|
|
512
|
+
if (!before.sponsor)
|
|
513
|
+
continue
|
|
514
|
+
effect.prevSponsor = before.sponsor
|
|
515
|
+
break
|
|
516
|
+
}
|
|
517
|
+
switch (type) {
|
|
518
|
+
case 'account':
|
|
519
|
+
effect.account = before?.address || after?.address
|
|
520
|
+
break
|
|
521
|
+
case 'trustline':
|
|
522
|
+
effect.account = before?.account || after?.account
|
|
523
|
+
effect.asset = before?.asset || after?.asset
|
|
524
|
+
break
|
|
525
|
+
case 'offer':
|
|
526
|
+
effect.account = before?.account || after?.account
|
|
527
|
+
effect.offer = before?.id || after?.id
|
|
528
|
+
break
|
|
529
|
+
case 'data':
|
|
530
|
+
effect.account = before?.account || after?.account
|
|
531
|
+
effect.name = before?.name || after?.name
|
|
532
|
+
break
|
|
533
|
+
case 'claimableBalance':
|
|
534
|
+
effect.balance = before?.balanceId || after?.balanceId
|
|
535
|
+
//TODO: add claimable balance asset to the effect
|
|
536
|
+
break
|
|
537
|
+
case 'liquidityPool': //ignore??
|
|
538
|
+
continue
|
|
539
|
+
}
|
|
540
|
+
effect.type = encodeSponsorshipEffectName(action, type)
|
|
541
|
+
this.addEffect(effect)
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
processAccountChanges({action, before, after}) {
|
|
546
|
+
switch (action) {
|
|
547
|
+
case 'created':
|
|
548
|
+
const accountCreated = {
|
|
549
|
+
type: effectTypes.accountCreated,
|
|
550
|
+
account: after.address
|
|
551
|
+
}
|
|
552
|
+
if (after.sponsor) {
|
|
553
|
+
accountCreated.sponsor = after.sponsor
|
|
554
|
+
}
|
|
555
|
+
this.addEffect(accountCreated)
|
|
556
|
+
if (after.balance > 0) {
|
|
557
|
+
this.credit(after.balance, 'XLM', after.address, after.balance)
|
|
558
|
+
}
|
|
559
|
+
break
|
|
560
|
+
case 'updated':
|
|
561
|
+
if (before.balance !== after.balance) {
|
|
562
|
+
this.processBalanceChange(after.address, 'XLM', before.balance, after.balance)
|
|
563
|
+
}
|
|
564
|
+
//other operations do not yield signer sponsorship effects
|
|
565
|
+
if (this.operation.type === 'setOptions' || this.operation.type === 'revokeSignerSponsorship') {
|
|
566
|
+
this.processSignerSponsorshipEffects({before, after})
|
|
567
|
+
}
|
|
568
|
+
break
|
|
569
|
+
case 'removed':
|
|
570
|
+
if (before.balance > 0) {
|
|
571
|
+
this.debit(before.balance, 'XLM', before.address, '0')
|
|
572
|
+
}
|
|
573
|
+
const accountRemoved = {
|
|
574
|
+
type: effectTypes.accountRemoved
|
|
575
|
+
}
|
|
576
|
+
if (before.sponsor) {
|
|
577
|
+
accountRemoved.sponsor = before.sponsor
|
|
578
|
+
}
|
|
579
|
+
this.addEffect(accountRemoved)
|
|
580
|
+
break
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
for (const effect of analyzeSignerChanges(before, after)) {
|
|
584
|
+
this.addEffect(effect)
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
processTrustlineEffectsChanges({action, before, after}) {
|
|
589
|
+
const snapshot = (after || before)
|
|
590
|
+
const trustEffect = {
|
|
591
|
+
type: '',
|
|
592
|
+
source: snapshot.account,
|
|
593
|
+
asset: snapshot.asset,
|
|
594
|
+
kind: snapshot.asset.includes('-') ? 'asset' : 'poolShares',
|
|
595
|
+
flags: snapshot.flags
|
|
596
|
+
}
|
|
597
|
+
if (snapshot.sponsor) {
|
|
598
|
+
trustEffect.sponsor = snapshot.sponsor
|
|
599
|
+
}
|
|
600
|
+
switch (action) {
|
|
601
|
+
case 'created':
|
|
602
|
+
trustEffect.type = effectTypes.trustlineCreated
|
|
603
|
+
trustEffect.limit = snapshot.limit
|
|
604
|
+
break
|
|
605
|
+
case 'updated':
|
|
606
|
+
if (before.balance !== after.balance) {
|
|
607
|
+
this.processBalanceChange(after.account, after.asset, before.balance, after.balance)
|
|
608
|
+
}
|
|
609
|
+
if (before.limit === after.limit && before.flags === after.flags)
|
|
610
|
+
return
|
|
611
|
+
trustEffect.type = effectTypes.trustlineUpdated
|
|
612
|
+
trustEffect.limit = snapshot.limit
|
|
613
|
+
trustEffect.prevFlags = before.flags
|
|
614
|
+
break
|
|
615
|
+
case 'removed':
|
|
616
|
+
trustEffect.type = effectTypes.trustlineRemoved
|
|
617
|
+
if (before.balance > 0) {
|
|
618
|
+
this.processBalanceChange(before.account, before.asset, before.balance, '0')
|
|
619
|
+
}
|
|
620
|
+
break
|
|
621
|
+
}
|
|
622
|
+
this.addEffect(trustEffect)
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
processBalanceChange(account, asset, beforeBalance, afterBalance) {
|
|
626
|
+
if (this.isContractCall) { //map contract=>asset proactively
|
|
627
|
+
mapSacContract(this, undefined, asset)
|
|
628
|
+
}
|
|
629
|
+
const balanceChange = BigInt(afterBalance) - BigInt(beforeBalance)
|
|
630
|
+
if (balanceChange < 0n) {
|
|
631
|
+
this.debit((-balanceChange).toString(), asset, account, afterBalance)
|
|
632
|
+
} else {
|
|
633
|
+
this.credit(balanceChange.toString(), asset, account, afterBalance)
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
processSignerSponsorshipEffects({before, after}) {
|
|
638
|
+
if (!before.signerSponsoringIDs?.length && !after.signerSponsoringIDs?.length)
|
|
639
|
+
return
|
|
640
|
+
const [beforeMap, afterMap] = [before, after].map(state => {
|
|
641
|
+
const signersMap = {}
|
|
642
|
+
if (state.signerSponsoringIDs?.length) {
|
|
643
|
+
for (let i = 0; i < state.signers.length; i++) {
|
|
644
|
+
const sponsor = state.signerSponsoringIDs[i]
|
|
645
|
+
if (sponsor) { //add only sponsored signers to the map
|
|
646
|
+
signersMap[state.signers[i].key] = sponsor
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
return signersMap
|
|
651
|
+
})
|
|
652
|
+
|
|
653
|
+
for (const signerKey of Object.keys(beforeMap)) {
|
|
654
|
+
const newSponsor = afterMap[signerKey]
|
|
655
|
+
if (!newSponsor) {
|
|
656
|
+
this.addEffect({
|
|
657
|
+
type: effectTypes.signerSponsorshipRemoved,
|
|
658
|
+
account: before.address,
|
|
659
|
+
signer: signerKey,
|
|
660
|
+
prevSponsor: beforeMap[signerKey]
|
|
661
|
+
})
|
|
662
|
+
break
|
|
663
|
+
}
|
|
664
|
+
if (newSponsor !== beforeMap[signerKey]) {
|
|
665
|
+
this.addEffect({
|
|
666
|
+
type: effectTypes.signerSponsorshipUpdated,
|
|
667
|
+
account: before.address,
|
|
668
|
+
signer: signerKey,
|
|
669
|
+
sponsor: newSponsor,
|
|
670
|
+
prevSponsor: beforeMap[signerKey]
|
|
671
|
+
})
|
|
672
|
+
break
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
for (const signerKey of Object.keys(afterMap)) {
|
|
677
|
+
const prevSponsor = beforeMap[signerKey]
|
|
678
|
+
if (!prevSponsor) {
|
|
679
|
+
this.addEffect({
|
|
680
|
+
type: effectTypes.signerSponsorshipCreated,
|
|
681
|
+
account: after.address,
|
|
682
|
+
signer: signerKey,
|
|
683
|
+
sponsor: afterMap[signerKey]
|
|
684
|
+
})
|
|
685
|
+
break
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
processOfferChanges({action, before, after}) {
|
|
691
|
+
const snapshot = after || before
|
|
692
|
+
const effect = {
|
|
693
|
+
type: effectTypes.offerRemoved,
|
|
694
|
+
owner: snapshot.account,
|
|
695
|
+
offer: snapshot.id,
|
|
696
|
+
asset: snapshot.asset,
|
|
697
|
+
flags: snapshot.flags
|
|
698
|
+
}
|
|
699
|
+
if (snapshot.sponsor) {
|
|
700
|
+
effect.sponsor = snapshot.sponsor
|
|
701
|
+
}
|
|
702
|
+
switch (action) {
|
|
703
|
+
case 'created':
|
|
704
|
+
effect.type = effectTypes.offerCreated
|
|
705
|
+
effect.amount = after.amount
|
|
706
|
+
effect.price = after.price
|
|
707
|
+
break
|
|
708
|
+
case 'updated':
|
|
709
|
+
if (before.price === after.price && before.asset.join() === after.asset.join() && before.amount === after.amount)
|
|
710
|
+
return //no changes - skip
|
|
711
|
+
effect.type = effectTypes.offerUpdated
|
|
712
|
+
effect.amount = after.amount
|
|
713
|
+
effect.price = after.price
|
|
714
|
+
break
|
|
715
|
+
}
|
|
716
|
+
this.addEffect(effect)
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
processLiquidityPoolChanges({action, before, after}) {
|
|
720
|
+
const snapshot = after || before
|
|
721
|
+
const effect = {
|
|
722
|
+
type: effectTypes.liquidityPoolRemoved,
|
|
723
|
+
pool: snapshot.pool
|
|
724
|
+
}
|
|
725
|
+
if (snapshot.sponsor) {
|
|
726
|
+
effect.sponsor = snapshot.sponsor
|
|
727
|
+
}
|
|
728
|
+
switch (action) {
|
|
729
|
+
case 'created':
|
|
730
|
+
Object.assign(effect, {
|
|
731
|
+
type: effectTypes.liquidityPoolCreated,
|
|
732
|
+
reserves: after.asset.map(asset => ({asset, amount: '0'})),
|
|
733
|
+
shares: '0',
|
|
734
|
+
accounts: 1
|
|
735
|
+
})
|
|
736
|
+
this.addEffect(effect, this.effects.findIndex(e => e.pool === effect.pool || e.asset === effect.pool))
|
|
737
|
+
return
|
|
738
|
+
case 'updated':
|
|
739
|
+
Object.assign(effect, {
|
|
740
|
+
type: effectTypes.liquidityPoolUpdated,
|
|
741
|
+
reserves: after.asset.map((asset, i) => ({
|
|
742
|
+
asset,
|
|
743
|
+
amount: after.amount[i]
|
|
744
|
+
})),
|
|
745
|
+
shares: after.shares,
|
|
746
|
+
accounts: after.accounts
|
|
747
|
+
})
|
|
748
|
+
break
|
|
749
|
+
}
|
|
750
|
+
this.addEffect(effect)
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
processClaimableBalanceChanges({action, before, after}) {
|
|
754
|
+
switch (action) {
|
|
755
|
+
case 'created':
|
|
756
|
+
this.addEffect({
|
|
757
|
+
type: effectTypes.claimableBalanceCreated,
|
|
758
|
+
sponsor: after.sponsor,
|
|
759
|
+
balance: after.balanceId,
|
|
760
|
+
asset: after.asset,
|
|
761
|
+
amount: after.amount,
|
|
762
|
+
claimants: after.claimants
|
|
763
|
+
})
|
|
764
|
+
break
|
|
765
|
+
case 'removed':
|
|
766
|
+
this.addEffect({
|
|
767
|
+
type: effectTypes.claimableBalanceRemoved,
|
|
768
|
+
sponsor: before.sponsor,
|
|
769
|
+
balance: before.balanceId,
|
|
770
|
+
asset: before.asset,
|
|
771
|
+
amount: before.amount,
|
|
772
|
+
claimants: before.claimants
|
|
773
|
+
})
|
|
774
|
+
break
|
|
775
|
+
case 'updated':
|
|
776
|
+
//nothing to process here
|
|
777
|
+
break
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
processDataEntryChanges({action, before, after}) {
|
|
782
|
+
const effect = {type: ''}
|
|
783
|
+
const {sponsor, name, value} = after || before
|
|
784
|
+
effect.name = name
|
|
785
|
+
effect.value = value && value.toString('base64')
|
|
786
|
+
switch (action) {
|
|
787
|
+
case 'created':
|
|
788
|
+
effect.type = effectTypes.dataEntryCreated
|
|
789
|
+
break
|
|
790
|
+
case 'updated':
|
|
791
|
+
if (before.value === after.value)
|
|
792
|
+
return //value has not changed
|
|
793
|
+
effect.type = effectTypes.dataEntryUpdated
|
|
794
|
+
break
|
|
795
|
+
case 'removed':
|
|
796
|
+
effect.type = effectTypes.dataEntryRemoved
|
|
797
|
+
delete effect.value
|
|
798
|
+
break
|
|
799
|
+
}
|
|
800
|
+
if (sponsor) {
|
|
801
|
+
effect.sponsor = sponsor
|
|
802
|
+
}
|
|
803
|
+
this.addEffect(effect)
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
processContractBalance(effect) {
|
|
807
|
+
const parsedKey = xdr.ScVal.fromXDR(effect.key, 'base64')
|
|
808
|
+
if (parsedKey._arm !== 'vec')
|
|
809
|
+
return
|
|
810
|
+
const keyParts = parsedKey._value
|
|
811
|
+
if (!(keyParts instanceof Array) || keyParts.length !== 2)
|
|
812
|
+
return
|
|
813
|
+
if (keyParts[0]._arm !== 'sym' || keyParts[1]._arm !== 'address' || keyParts[0]._value.toString() !== 'Balance')
|
|
814
|
+
return
|
|
815
|
+
const account = xdrParseScVal(keyParts[1])
|
|
816
|
+
const balanceEffects = this.effects.filter(e => (e.type === effectTypes.accountCredited || e.type === effectTypes.accountDebited) && e.source === account && e.asset === effect.owner)
|
|
817
|
+
if (balanceEffects.length !== 1) //we can set balance only when we found 1-1 mapping, if there are several balance changes, we can't establish balance relation
|
|
818
|
+
return
|
|
819
|
+
if (effect.type === effectTypes.contractDataRemoved) { //balance completely removed - this may be a reversible operation if the balance simply expired
|
|
820
|
+
balanceEffects[0].balance = '0'
|
|
821
|
+
return
|
|
822
|
+
}
|
|
823
|
+
const value = xdr.ScVal.fromXDR(effect.value, 'base64')
|
|
824
|
+
if (value._arm !== 'map')
|
|
825
|
+
return
|
|
826
|
+
const parsedValue = xdrParseScVal(value)
|
|
827
|
+
if (typeof parsedValue.clawback !== 'boolean' || typeof parsedValue.authorized !== 'boolean' || typeof parsedValue.amount !== 'string')
|
|
828
|
+
return
|
|
829
|
+
//set transfer effect balance
|
|
830
|
+
balanceEffects[0].balance = parsedValue.amount
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
processContractChanges({action, before, after}) {
|
|
834
|
+
const {kind, owner: contract, keyHash} = after
|
|
835
|
+
let effect = {
|
|
836
|
+
type: effectTypes.contractCreated,
|
|
837
|
+
contract,
|
|
838
|
+
kind,
|
|
839
|
+
keyHash
|
|
840
|
+
}
|
|
841
|
+
switch (kind) {
|
|
842
|
+
case 'fromAsset':
|
|
843
|
+
effect.asset = after.asset
|
|
844
|
+
break
|
|
845
|
+
case 'wasm':
|
|
846
|
+
effect.wasmHash = after.wasmHash
|
|
847
|
+
break
|
|
848
|
+
default:
|
|
849
|
+
throw new TxMetaEffectParserError('Unexpected contract type: ' + kind)
|
|
850
|
+
}
|
|
851
|
+
switch (action) {
|
|
852
|
+
case 'created':
|
|
853
|
+
if (this.effects.some(e => e.type === effectTypes.contractCreated && e.contract === contract)) {
|
|
854
|
+
effect = undefined //skip contract creation effects processed by top-level createContract operation call
|
|
855
|
+
}
|
|
856
|
+
break
|
|
857
|
+
case 'updated':
|
|
858
|
+
effect.type = effectTypes.contractUpdated
|
|
859
|
+
effect.prevWasmHash = before.wasmHash
|
|
860
|
+
if (before.wasmHash === after.wasmHash) {//skip if hash unchanged
|
|
861
|
+
effect = undefined
|
|
862
|
+
}
|
|
863
|
+
break
|
|
864
|
+
case 'restored':
|
|
865
|
+
effect.type = effectTypes.contractRestored
|
|
866
|
+
break
|
|
867
|
+
default:
|
|
868
|
+
throw new UnexpectedTxMetaChangeError({type: 'contract', action})
|
|
869
|
+
}
|
|
870
|
+
if (effect) {
|
|
871
|
+
this.addEffect(effect, effect.type === effectTypes.contractCreated ? 0 : undefined)
|
|
872
|
+
}
|
|
873
|
+
if (before?.storage?.length || after?.storage?.length) {
|
|
874
|
+
this.processInstanceDataChanges(before, after, action === 'restored')
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
processContractStateEntryChanges({action, before, after}) {
|
|
879
|
+
const {owner, key, durability, keyHash} = after || before
|
|
880
|
+
const effect = {
|
|
881
|
+
type: '',
|
|
882
|
+
owner,
|
|
883
|
+
key,
|
|
884
|
+
durability,
|
|
885
|
+
keyHash
|
|
886
|
+
}
|
|
887
|
+
switch (action) {
|
|
888
|
+
case 'created':
|
|
889
|
+
effect.type = effectTypes.contractDataCreated
|
|
890
|
+
effect.value = after.value
|
|
891
|
+
break
|
|
892
|
+
case 'updated':
|
|
893
|
+
if (before.value === after.value)
|
|
894
|
+
return //value has not changed
|
|
895
|
+
effect.type = effectTypes.contractDataUpdated
|
|
896
|
+
effect.value = after.value
|
|
897
|
+
effect.prevValue = before.value
|
|
898
|
+
break
|
|
899
|
+
case 'removed':
|
|
900
|
+
effect.type = effectTypes.contractDataRemoved
|
|
901
|
+
effect.prevValue = before.value
|
|
902
|
+
break
|
|
903
|
+
case 'restored':
|
|
904
|
+
effect.type = effectTypes.contractDataRestored
|
|
905
|
+
effect.value = after.value
|
|
906
|
+
break
|
|
907
|
+
}
|
|
908
|
+
this.addEffect(effect)
|
|
909
|
+
this.processContractBalance(effect)
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
processContractCodeChanges({type, action, before, after}) {
|
|
913
|
+
const {hash, keyHash} = after || before
|
|
914
|
+
switch (action) {
|
|
915
|
+
case 'created':
|
|
916
|
+
break //processed separately
|
|
917
|
+
case 'updated':
|
|
918
|
+
break //it doesn't change the state
|
|
919
|
+
case 'removed':
|
|
920
|
+
this.addEffect({
|
|
921
|
+
type: effectTypes.contractCodeRemoved,
|
|
922
|
+
wasmHash: hash,
|
|
923
|
+
keyHash
|
|
924
|
+
})
|
|
925
|
+
break
|
|
926
|
+
case 'restored':
|
|
927
|
+
this.addEffect({
|
|
928
|
+
type: effectTypes.contractCodeRestored,
|
|
929
|
+
wasmHash: hash,
|
|
930
|
+
keyHash
|
|
931
|
+
})
|
|
932
|
+
break
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
processInstanceDataChanges(before, after, restored) {
|
|
937
|
+
const storageBefore = before?.storage || []
|
|
938
|
+
const storageAfter = [...(after?.storage || [])]
|
|
939
|
+
if (!restored) {
|
|
940
|
+
for (const {key, val} of storageBefore) {
|
|
941
|
+
let newVal
|
|
942
|
+
for (let i = 0; i < storageAfter.length; i++) {
|
|
943
|
+
const afterValue = storageAfter[i]
|
|
944
|
+
if (afterValue.key === key) {
|
|
945
|
+
newVal = afterValue.val //update new value
|
|
946
|
+
storageAfter.splice(i, 1) //remove from array to simplify iteration
|
|
947
|
+
break
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
if (newVal === undefined) { //removed
|
|
951
|
+
const effect = {
|
|
952
|
+
type: effectTypes.contractDataRemoved,
|
|
953
|
+
owner: after?.owner || before.owner,
|
|
954
|
+
key,
|
|
955
|
+
prevValue: val,
|
|
956
|
+
durability: 'instance'
|
|
957
|
+
}
|
|
958
|
+
this.addEffect(effect)
|
|
959
|
+
continue
|
|
960
|
+
}
|
|
961
|
+
if (val === newVal) //value has not changed
|
|
962
|
+
continue
|
|
963
|
+
|
|
964
|
+
const effect = {
|
|
965
|
+
type: effectTypes.contractDataUpdated,
|
|
966
|
+
owner: after?.owner || before.owner,
|
|
967
|
+
key,
|
|
968
|
+
value: newVal,
|
|
969
|
+
prevValue: val,
|
|
970
|
+
durability: 'instance'
|
|
971
|
+
}
|
|
972
|
+
this.addEffect(effect)
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
//iterate all storage items left
|
|
976
|
+
for (const {key, val} of storageAfter) {
|
|
977
|
+
const effect = {
|
|
978
|
+
type: restored ? effectTypes.contractDataRestored : effectTypes.contractDataCreated,
|
|
979
|
+
owner: after?.owner || before.owner,
|
|
980
|
+
key,
|
|
981
|
+
value: val,
|
|
982
|
+
durability: 'instance'
|
|
983
|
+
}
|
|
984
|
+
this.addEffect(effect)
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
processTtlChanges({action, before, after}) {
|
|
989
|
+
/*if (action === 'removed')
|
|
990
|
+
throw new UnexpectedTxMetaChangeError({type: 'ttl', action})*/
|
|
991
|
+
const {keyHash, ttl} = after || before
|
|
992
|
+
const stateEffect = this.effects.find(e => e.keyHash === keyHash && e.type !== effectTypes.setTtl)
|
|
993
|
+
const effect = {
|
|
994
|
+
type: effectTypes.setTtl,
|
|
995
|
+
keyHash,
|
|
996
|
+
ttl
|
|
997
|
+
}
|
|
998
|
+
if (stateEffect) {
|
|
999
|
+
if (stateEffect.type.startsWith('contractCode')) {
|
|
1000
|
+
effect.kind = 'contractCode'
|
|
1001
|
+
} else if (stateEffect.type.startsWith('contractData')) {
|
|
1002
|
+
effect.kind = 'contractData'
|
|
1003
|
+
effect.owner = stateEffect.owner
|
|
1004
|
+
} else if (stateEffect.type.startsWith('contract')) {
|
|
1005
|
+
effect.kind = 'contractData'
|
|
1006
|
+
effect.owner = stateEffect.contract
|
|
1007
|
+
} else
|
|
1008
|
+
throw new UnexpectedTxMetaChangeError({type: 'ttl', action: stateEffect.type})
|
|
1009
|
+
stateEffect.ttl = ttl
|
|
1010
|
+
}
|
|
1011
|
+
this.addEffect(effect)
|
|
1012
|
+
}
|
|
1013
|
+
|
|
1014
|
+
processChanges() {
|
|
1015
|
+
for (const change of this.changes)
|
|
1016
|
+
switch (change.type) {
|
|
1017
|
+
case 'account':
|
|
1018
|
+
this.processAccountChanges(change)
|
|
1019
|
+
break
|
|
1020
|
+
case 'trustline':
|
|
1021
|
+
this.processTrustlineEffectsChanges(change)
|
|
1022
|
+
break
|
|
1023
|
+
case 'claimableBalance':
|
|
1024
|
+
this.processClaimableBalanceChanges(change)
|
|
1025
|
+
break
|
|
1026
|
+
case 'offer':
|
|
1027
|
+
this.processOfferChanges(change)
|
|
1028
|
+
break
|
|
1029
|
+
case 'liquidityPool':
|
|
1030
|
+
this.processLiquidityPoolChanges(change)
|
|
1031
|
+
break
|
|
1032
|
+
case 'data':
|
|
1033
|
+
this.processDataEntryChanges(change)
|
|
1034
|
+
break
|
|
1035
|
+
case 'contractData':
|
|
1036
|
+
if (change.before?.kind || change.after?.kind) {
|
|
1037
|
+
this.processContractChanges(change)
|
|
1038
|
+
}
|
|
1039
|
+
break
|
|
1040
|
+
case 'contractCode':
|
|
1041
|
+
this.processContractCodeChanges(change)
|
|
1042
|
+
break
|
|
1043
|
+
case 'ttl':
|
|
1044
|
+
this.processTtlChanges(change)
|
|
1045
|
+
break
|
|
1046
|
+
default:
|
|
1047
|
+
throw new UnexpectedTxMetaChangeError(change)
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
processStateChanges() {
|
|
1052
|
+
for (const change of this.changes)
|
|
1053
|
+
if (change.type === 'contractData') {
|
|
1054
|
+
this.processContractStateEntryChanges(change)
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
/**
|
|
1059
|
+
* @return {String|null}
|
|
1060
|
+
* @private
|
|
1061
|
+
*/
|
|
1062
|
+
retrieveOpContractId() {
|
|
1063
|
+
const funcValue = this.operation.func._value._attributes
|
|
1064
|
+
if (funcValue) {
|
|
1065
|
+
if (funcValue.contractAddress)
|
|
1066
|
+
return StrKey.encodeContract(funcValue.contractAddress._value)
|
|
1067
|
+
const preimage = funcValue.contractIdPreimage
|
|
1068
|
+
if (preimage)
|
|
1069
|
+
return contractIdFromPreimage(preimage, this.network)
|
|
1070
|
+
}
|
|
1071
|
+
return null
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
/**
|
|
1075
|
+
*
|
|
1076
|
+
* @param assetOrContract
|
|
1077
|
+
* @return {*}
|
|
1078
|
+
*/
|
|
1079
|
+
resolveAsset(assetOrContract) {
|
|
1080
|
+
if (!assetOrContract.startsWith('C') || !this.sacMap)
|
|
1081
|
+
return assetOrContract
|
|
1082
|
+
//try to resolve using SAC map
|
|
1083
|
+
return this.sacMap.get(assetOrContract) || assetOrContract
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1087
|
+
/**
|
|
1088
|
+
* Generates fee charged effect
|
|
1089
|
+
* @param {{}} tx - Transaction
|
|
1090
|
+
* @param {String} source - Source account
|
|
1091
|
+
* @param {String} chargedAmount - Charged amount
|
|
1092
|
+
* @param {Boolean} [feeBump] - Is fee bump transaction
|
|
1093
|
+
* @returns {{}} - Fee charged effect
|
|
1094
|
+
*/
|
|
1095
|
+
function processFeeChargedEffect(tx, source, chargedAmount, feeBump = false) {
|
|
1096
|
+
if (tx._switch) { //raw XDR
|
|
1097
|
+
const txXdr = tx.value().tx()
|
|
1098
|
+
tx = {
|
|
1099
|
+
source: xdrParseAccountAddress((txXdr.feeSource ? txXdr.feeSource : txXdr.sourceAccount).call(txXdr)),
|
|
1100
|
+
fee: txXdr.fee().toString()
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
const res = {
|
|
1104
|
+
type: effectTypes.feeCharged,
|
|
1105
|
+
source,
|
|
1106
|
+
asset: 'XLM',
|
|
1107
|
+
bid: tx.fee,
|
|
1108
|
+
charged: chargedAmount
|
|
1109
|
+
}
|
|
1110
|
+
if (feeBump) {
|
|
1111
|
+
res.bump = true
|
|
1112
|
+
}
|
|
1113
|
+
return res
|
|
1114
|
+
}
|
|
1115
|
+
|
|
1116
|
+
/**
|
|
1117
|
+
* @param {String} action
|
|
1118
|
+
* @param {String} type
|
|
1119
|
+
* @return {String}
|
|
1120
|
+
*/
|
|
1121
|
+
function encodeSponsorshipEffectName(action, type) {
|
|
1122
|
+
let actionKey
|
|
1123
|
+
switch (action) {
|
|
1124
|
+
case 'created':
|
|
1125
|
+
actionKey = 'Created'
|
|
1126
|
+
break
|
|
1127
|
+
case 'updated':
|
|
1128
|
+
actionKey = 'Updated'
|
|
1129
|
+
break
|
|
1130
|
+
case 'removed':
|
|
1131
|
+
actionKey = 'Removed'
|
|
1132
|
+
break
|
|
1133
|
+
case 'restored':
|
|
1134
|
+
actionKey = 'Restored'
|
|
1135
|
+
break
|
|
1136
|
+
default:
|
|
1137
|
+
throw new UnexpectedTxMetaChangeError({action, type})
|
|
1138
|
+
}
|
|
1139
|
+
return effectTypes[`${type}Sponsorship${actionKey}`]
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
module.exports = {EffectsAnalyzer, processFeeChargedEffect}
|