-
Notifications
You must be signed in to change notification settings - Fork 0
/
formatter.c
2499 lines (2272 loc) · 104 KB
/
formatter.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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
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
216
217
218
219
220
221
222
223
224
225
226
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
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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
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
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
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
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
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
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
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
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
705
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
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
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
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
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
#include <string.h>
#include <stdbool.h> // bool
#ifdef TEST
#include <stdio.h>
#define PIC(x) x
#else
#include "os.h"
#endif
#include "base64.h"
#include "stellar/formatter.h"
#include "stellar/parser.h"
#include "stellar/printer.h"
#include "stellar/plugin.h"
#if defined(TARGET_NANOS)
#define INVOKE_SMART_CONTRACT "Invoke Contract"
#else
#define INVOKE_SMART_CONTRACT "Invoke Smart Contract"
#endif
/*
* the formatter prints the details and defines the order of the details
* by setting the next formatter to be called
*/
typedef bool (*format_function_t)(formatter_data_t *fdata);
#define FORMATTER_CHECK(x) \
{ \
if (!(x)) return false; \
}
#define STRLCPY(dst, src, size) \
{ \
size_t len = strlcpy(dst, src, size); \
if (len >= size) return false; \
}
#define STRLCAT(dst, src, size) \
{ \
size_t len = strlcat(dst, src, size); \
if (len >= size) return false; \
}
/* 16 formatters in a row ought to be enough for everybody*/
#define MAX_FORMATTERS_PER_OPERATION 16
static const char *NETWORK_NAMES[3] = {"Public", "Testnet", "Unknown"};
static format_function_t formatter_stack[MAX_FORMATTERS_PER_OPERATION];
static int8_t formatter_index;
static uint8_t current_data_index;
static uint8_t parameters_index;
static uint8_t plugin_data_pair_count;
static bool format_sub_invocation_start(formatter_data_t *fdata);
static bool push_to_formatter_stack(format_function_t formatter) {
if (formatter_index >= MAX_FORMATTERS_PER_OPERATION) {
PRINTF("Formatter stack overflow\n");
return false;
}
formatter_stack[formatter_index++] = formatter;
return true;
}
static bool format_transaction_source(formatter_data_t *fdata) {
STRLCPY(fdata->caption, "Tx Source", fdata->caption_len);
if (fdata->envelope->type == ENVELOPE_TYPE_TX &&
fdata->envelope->tx_details.tx.source_account.type == KEY_TYPE_ED25519 &&
memcmp(fdata->envelope->tx_details.tx.source_account.ed25519,
fdata->signing_key,
RAW_ED25519_PUBLIC_KEY_SIZE) == 0) {
FORMATTER_CHECK(print_muxed_account(&fdata->envelope->tx_details.tx.source_account,
fdata->value,
fdata->value_len,
6,
6))
} else {
FORMATTER_CHECK(print_muxed_account(&fdata->envelope->tx_details.tx.source_account,
fdata->value,
fdata->value_len,
0,
0))
}
FORMATTER_CHECK(push_to_formatter_stack(NULL))
return true;
}
static bool format_min_seq_ledger_gap(formatter_data_t *fdata) {
STRLCPY(fdata->caption, "Min Seq Ledger Gap", fdata->caption_len);
FORMATTER_CHECK(print_uint64_num(fdata->envelope->tx_details.tx.cond.min_seq_ledger_gap,
fdata->value,
fdata->value_len))
FORMATTER_CHECK(push_to_formatter_stack(&format_transaction_source))
return true;
}
static bool format_min_seq_ledger_gap_prepare(formatter_data_t *fdata) {
if (fdata->envelope->tx_details.tx.cond.min_seq_ledger_gap == 0) {
return format_transaction_source(fdata);
} else {
return format_min_seq_ledger_gap(fdata);
}
}
static bool format_min_seq_age(formatter_data_t *fdata) {
STRLCPY(fdata->caption, "Min Seq Age", fdata->caption_len);
FORMATTER_CHECK(print_uint64_num(fdata->envelope->tx_details.tx.cond.min_seq_age,
fdata->value,
fdata->value_len))
FORMATTER_CHECK(push_to_formatter_stack(&format_min_seq_ledger_gap_prepare))
return true;
}
static bool format_min_seq_age_prepare(formatter_data_t *fdata) {
if (fdata->envelope->tx_details.tx.cond.min_seq_age == 0) {
format_min_seq_ledger_gap_prepare(fdata);
} else {
format_min_seq_age(fdata);
}
return true;
}
static bool format_min_seq_num(formatter_data_t *fdata) {
STRLCPY(fdata->caption, "Min Seq Num", fdata->caption_len);
FORMATTER_CHECK(print_uint64_num(fdata->envelope->tx_details.tx.cond.min_seq_num,
fdata->value,
fdata->value_len))
FORMATTER_CHECK(push_to_formatter_stack(&format_min_seq_age_prepare))
return true;
}
static bool format_min_seq_num_prepare(formatter_data_t *fdata) {
if (!fdata->envelope->tx_details.tx.cond.min_seq_num_present ||
fdata->envelope->tx_details.tx.cond.min_seq_num == 0) {
return format_min_seq_age_prepare(fdata);
} else {
return format_min_seq_num(fdata);
}
}
static bool format_ledger_bounds_max_ledger(formatter_data_t *fdata) {
STRLCPY(fdata->caption, "Ledger Bounds Max", fdata->caption_len);
FORMATTER_CHECK(print_uint64_num(fdata->envelope->tx_details.tx.cond.ledger_bounds.max_ledger,
fdata->value,
fdata->value_len))
FORMATTER_CHECK(push_to_formatter_stack(&format_min_seq_num_prepare))
return true;
}
static bool format_ledger_bounds_min_ledger(formatter_data_t *fdata) {
STRLCPY(fdata->caption, "Ledger Bounds Min", fdata->caption_len);
FORMATTER_CHECK(print_uint64_num(fdata->envelope->tx_details.tx.cond.ledger_bounds.min_ledger,
fdata->value,
fdata->value_len))
if (fdata->envelope->tx_details.tx.cond.ledger_bounds.max_ledger != 0) {
FORMATTER_CHECK(push_to_formatter_stack(&format_ledger_bounds_max_ledger))
} else {
FORMATTER_CHECK(push_to_formatter_stack(&format_min_seq_num_prepare))
}
return true;
}
static bool format_ledger_bounds(formatter_data_t *fdata) {
if (!fdata->envelope->tx_details.tx.cond.ledger_bounds_present ||
(fdata->envelope->tx_details.tx.cond.ledger_bounds.min_ledger == 0 &&
fdata->envelope->tx_details.tx.cond.ledger_bounds.max_ledger == 0)) {
return format_min_seq_num_prepare(fdata);
} else if (fdata->envelope->tx_details.tx.cond.ledger_bounds.min_ledger != 0) {
return format_ledger_bounds_min_ledger(fdata);
} else {
return format_ledger_bounds_max_ledger(fdata);
}
return true;
}
static bool format_time_bounds_max_time(formatter_data_t *fdata) {
STRLCPY(fdata->caption, "Valid Before (UTC)", fdata->caption_len);
FORMATTER_CHECK(print_time(fdata->envelope->tx_details.tx.cond.time_bounds.max_time,
fdata->value,
fdata->value_len))
FORMATTER_CHECK(push_to_formatter_stack(&format_ledger_bounds))
return true;
}
static bool format_time_bounds_min_time(formatter_data_t *fdata) {
STRLCPY(fdata->caption, "Valid After (UTC)", fdata->caption_len);
FORMATTER_CHECK(print_time(fdata->envelope->tx_details.tx.cond.time_bounds.min_time,
fdata->value,
fdata->value_len))
if (fdata->envelope->tx_details.tx.cond.time_bounds.max_time != 0) {
FORMATTER_CHECK(push_to_formatter_stack(&format_time_bounds_max_time))
} else {
FORMATTER_CHECK(push_to_formatter_stack(&format_ledger_bounds))
}
return true;
}
static bool format_time_bounds(formatter_data_t *fdata) {
if (!fdata->envelope->tx_details.tx.cond.time_bounds_present ||
(fdata->envelope->tx_details.tx.cond.time_bounds.min_time == 0 &&
fdata->envelope->tx_details.tx.cond.time_bounds.max_time == 0)) {
return format_ledger_bounds(fdata);
} else if (fdata->envelope->tx_details.tx.cond.time_bounds.min_time != 0) {
return format_time_bounds_min_time(fdata);
} else {
return format_time_bounds_max_time(fdata);
}
return true;
}
static bool format_sequence(formatter_data_t *fdata) {
STRLCPY(fdata->caption, "Sequence Num", fdata->caption_len);
FORMATTER_CHECK(print_uint64_num(fdata->envelope->tx_details.tx.sequence_number,
fdata->value,
fdata->value_len))
FORMATTER_CHECK(push_to_formatter_stack(&format_time_bounds))
return true;
}
static bool format_fee(formatter_data_t *fdata) {
STRLCPY(fdata->caption, "Max Fee", fdata->caption_len);
asset_t asset = {.type = ASSET_TYPE_NATIVE};
FORMATTER_CHECK(print_amount(fdata->envelope->tx_details.tx.fee,
&asset,
fdata->envelope->network,
fdata->value,
fdata->value_len))
if (fdata->display_sequence) {
FORMATTER_CHECK(push_to_formatter_stack(&format_sequence))
} else {
FORMATTER_CHECK(push_to_formatter_stack(&format_time_bounds))
}
return true;
}
static bool format_memo(formatter_data_t *fdata) {
memo_t *memo = &fdata->envelope->tx_details.tx.memo;
switch (memo->type) {
case MEMO_ID: {
STRLCPY(fdata->caption, "Memo ID", fdata->caption_len);
FORMATTER_CHECK(print_uint64_num(memo->id, fdata->value, fdata->value_len))
break;
}
case MEMO_TEXT: {
STRLCPY(fdata->caption, "Memo Text", fdata->caption_len);
if (is_printable_binary(memo->text.text, memo->text.text_size)) {
FORMATTER_CHECK(print_string(fdata->value,
fdata->value_len,
memo->text.text,
memo->text.text_size))
} else {
STRLCPY(fdata->value, "Base64: ", fdata->value_len)
FORMATTER_CHECK(base64_encode(memo->text.text,
memo->text.text_size,
fdata->value + strlen(fdata->value),
fdata->value_len - strlen(fdata->value)))
}
break;
}
case MEMO_HASH: {
STRLCPY(fdata->caption, "Memo Hash", fdata->caption_len);
FORMATTER_CHECK(
print_binary(memo->hash, HASH_SIZE, fdata->value, fdata->value_len, 0, 0))
break;
}
case MEMO_RETURN: {
STRLCPY(fdata->caption, "Memo Return", fdata->caption_len);
FORMATTER_CHECK(
print_binary(memo->hash, HASH_SIZE, fdata->value, fdata->value_len, 0, 0))
break;
}
default:
return false;
}
FORMATTER_CHECK(push_to_formatter_stack(&format_fee))
return true;
}
static bool format_transaction_details(formatter_data_t *fdata) {
switch (fdata->envelope->type) {
case ENVELOPE_TYPE_TX_FEE_BUMP:
STRLCPY(fdata->caption, "InnerTx", fdata->caption_len);
break;
case ENVELOPE_TYPE_TX:
STRLCPY(fdata->caption, "Transaction", fdata->caption_len);
break;
default:
return false;
}
STRLCPY(fdata->value, "Details", fdata->value_len);
if (fdata->envelope->tx_details.tx.memo.type != MEMO_NONE) {
FORMATTER_CHECK(push_to_formatter_stack(&format_memo))
} else {
FORMATTER_CHECK(push_to_formatter_stack(&format_fee))
}
return true;
}
static bool format_operation_source(formatter_data_t *fdata) {
STRLCPY(fdata->caption, "Op Source", fdata->caption_len);
if (fdata->envelope->type == ENVELOPE_TYPE_TX &&
fdata->envelope->tx_details.tx.source_account.type == KEY_TYPE_ED25519 &&
fdata->envelope->tx_details.tx.op_details.source_account.type == KEY_TYPE_ED25519 &&
memcmp(fdata->envelope->tx_details.tx.source_account.ed25519,
fdata->signing_key,
RAW_ED25519_PUBLIC_KEY_SIZE) == 0 &&
memcmp(fdata->envelope->tx_details.tx.op_details.source_account.ed25519,
fdata->signing_key,
RAW_ED25519_PUBLIC_KEY_SIZE) == 0) {
FORMATTER_CHECK(
print_muxed_account(&fdata->envelope->tx_details.tx.op_details.source_account,
fdata->value,
fdata->value_len,
6,
6))
} else {
FORMATTER_CHECK(
print_muxed_account(&fdata->envelope->tx_details.tx.op_details.source_account,
fdata->value,
fdata->value_len,
0,
0))
}
FORMATTER_CHECK(push_to_formatter_stack(NULL))
return true;
}
static bool format_operation_source_prepare(formatter_data_t *fdata) {
if (fdata->envelope->tx_details.tx.op_details.source_account_present) {
// If the source exists, when the user clicks the next button,
// it will jump to the page showing the source
FORMATTER_CHECK(push_to_formatter_stack(&format_operation_source))
} else {
FORMATTER_CHECK(push_to_formatter_stack(NULL))
}
return true;
}
static bool format_bump_sequence_bump_to(formatter_data_t *fdata) {
STRLCPY(fdata->caption, "Bump To", fdata->caption_len);
FORMATTER_CHECK(
print_int64_num(fdata->envelope->tx_details.tx.op_details.bump_sequence_op.bump_to,
fdata->value,
fdata->value_len))
return format_operation_source_prepare(fdata);
}
static bool format_bump_sequence(formatter_data_t *fdata) {
(void) fdata;
STRLCPY(fdata->caption, "Operation Type", fdata->caption_len);
STRLCPY(fdata->value, "Bump Sequence", fdata->value_len);
FORMATTER_CHECK(push_to_formatter_stack(&format_bump_sequence_bump_to))
return true;
}
static bool format_inflation(formatter_data_t *fdata) {
(void) fdata;
STRLCPY(fdata->caption, "Operation Type", fdata->caption_len);
STRLCPY(fdata->value, "Inflation", fdata->value_len);
return format_operation_source_prepare(fdata);
}
static bool format_account_merge_destination(formatter_data_t *fdata) {
STRLCPY(fdata->caption, "Destination", fdata->caption_len);
FORMATTER_CHECK(
print_muxed_account(&fdata->envelope->tx_details.tx.op_details.account_merge_op.destination,
fdata->value,
fdata->value_len,
0,
0))
return format_operation_source_prepare(fdata);
}
static bool format_account_merge_detail(formatter_data_t *fdata) {
STRLCPY(fdata->caption, "Send", fdata->caption_len);
STRLCPY(fdata->value, "All Funds", fdata->value_len);
FORMATTER_CHECK(push_to_formatter_stack(&format_account_merge_destination))
return true;
}
static bool format_account_merge(formatter_data_t *fdata) {
(void) fdata;
STRLCPY(fdata->caption, "Operation Type", fdata->caption_len);
STRLCPY(fdata->value, "Account Merge", fdata->value_len);
FORMATTER_CHECK(push_to_formatter_stack(&format_account_merge_detail))
return true;
}
static bool format_manage_data_value(formatter_data_t *fdata) {
STRLCPY(fdata->caption, "Data Value", fdata->caption_len);
if (is_printable_binary(
fdata->envelope->tx_details.tx.op_details.manage_data_op.data_value,
fdata->envelope->tx_details.tx.op_details.manage_data_op.data_value_size)) {
if (fdata->envelope->tx_details.tx.op_details.manage_data_op.data_value_size >=
fdata->value_len) {
return false;
}
FORMATTER_CHECK(
print_string(fdata->value,
fdata->value_len,
fdata->envelope->tx_details.tx.op_details.manage_data_op.data_value,
fdata->envelope->tx_details.tx.op_details.manage_data_op.data_value_size))
} else {
STRLCPY(fdata->value, "Base64: ", fdata->value_len)
FORMATTER_CHECK(
base64_encode(fdata->envelope->tx_details.tx.op_details.manage_data_op.data_value,
fdata->envelope->tx_details.tx.op_details.manage_data_op.data_value_size,
fdata->value + strlen(fdata->value),
fdata->value_len - strlen(fdata->value)))
}
return format_operation_source_prepare(fdata);
}
static bool format_manage_data(formatter_data_t *fdata) {
FORMATTER_CHECK(
print_string(fdata->value,
fdata->value_len,
fdata->envelope->tx_details.tx.op_details.manage_data_op.data_name,
fdata->envelope->tx_details.tx.op_details.manage_data_op.data_name_size))
if (fdata->envelope->tx_details.tx.op_details.manage_data_op.data_value_size) {
STRLCPY(fdata->caption, "Set Data", fdata->caption_len);
FORMATTER_CHECK(push_to_formatter_stack(&format_manage_data_value))
} else {
STRLCPY(fdata->caption, "Remove Data", fdata->caption_len);
return format_operation_source_prepare(fdata);
}
return true;
}
static bool format_allow_trust_authorize(formatter_data_t *fdata) {
STRLCPY(fdata->caption, "Authorize Flag", fdata->caption_len);
FORMATTER_CHECK(
print_allow_trust_flags(fdata->envelope->tx_details.tx.op_details.allow_trust_op.authorize,
fdata->value,
fdata->value_len))
return format_operation_source_prepare(fdata);
}
static bool format_allow_trust_asset_code(formatter_data_t *fdata) {
STRLCPY(fdata->caption, "Asset Code", fdata->caption_len);
switch (fdata->envelope->tx_details.tx.op_details.allow_trust_op.asset_type) {
case ASSET_TYPE_CREDIT_ALPHANUM4: {
FORMATTER_CHECK(
print_string(fdata->value,
fdata->value_len,
fdata->envelope->tx_details.tx.op_details.allow_trust_op.asset_code,
4))
break;
}
case ASSET_TYPE_CREDIT_ALPHANUM12: {
FORMATTER_CHECK(
print_string(fdata->value,
fdata->value_len,
fdata->envelope->tx_details.tx.op_details.allow_trust_op.asset_code,
12))
break;
}
default:
return false; // unknown asset type
}
FORMATTER_CHECK(push_to_formatter_stack(&format_allow_trust_authorize))
return true;
}
static bool format_allow_trust_trustor(formatter_data_t *fdata) {
STRLCPY(fdata->caption, "Trustor", fdata->caption_len);
FORMATTER_CHECK(
print_account_id(fdata->envelope->tx_details.tx.op_details.allow_trust_op.trustor,
fdata->value,
fdata->value_len,
0,
0))
FORMATTER_CHECK(push_to_formatter_stack(&format_allow_trust_asset_code))
return true;
}
static bool format_allow_trust(formatter_data_t *fdata) {
(void) fdata;
STRLCPY(fdata->caption, "Operation Type", fdata->caption_len);
STRLCPY(fdata->value, "Allow Trust", fdata->value_len);
FORMATTER_CHECK(push_to_formatter_stack(&format_allow_trust_trustor))
return true;
}
static bool format_set_option_signer_weight(formatter_data_t *fdata) {
STRLCPY(fdata->caption, "Weight", fdata->caption_len);
FORMATTER_CHECK(
print_uint64_num(fdata->envelope->tx_details.tx.op_details.set_options_op.signer.weight,
fdata->value,
fdata->value_len))
return format_operation_source_prepare(fdata);
}
static bool print_signer_key_detail(signer_key_t *key, char *value, size_t value_len) {
switch (key->type) {
case SIGNER_KEY_TYPE_ED25519: {
FORMATTER_CHECK(print_account_id(key->ed25519, value, value_len, 0, 0))
break;
}
case SIGNER_KEY_TYPE_HASH_X: {
FORMATTER_CHECK(print_hash_x_key(key->hash_x, value, value_len, 0, 0))
break;
}
case SIGNER_KEY_TYPE_PRE_AUTH_TX: {
FORMATTER_CHECK(print_pre_auth_x_key(key->pre_auth_tx, value, value_len, 0, 0))
break;
}
case SIGNER_KEY_TYPE_ED25519_SIGNED_PAYLOAD: {
FORMATTER_CHECK(print_ed25519_signed_payload(&key->ed25519_signed_payload,
value,
value_len,
12,
12))
break;
}
default:
return false;
}
return true;
}
static bool format_set_option_signer_detail(formatter_data_t *fdata) {
STRLCPY(fdata->caption, "Signer Key", fdata->caption_len);
signer_key_t *key = &fdata->envelope->tx_details.tx.op_details.set_options_op.signer.key;
FORMATTER_CHECK(print_signer_key_detail(key, fdata->value, fdata->value_len))
if (fdata->envelope->tx_details.tx.op_details.set_options_op.signer.weight != 0) {
FORMATTER_CHECK(push_to_formatter_stack(&format_set_option_signer_weight))
} else {
return format_operation_source_prepare(fdata);
}
return true;
}
static bool format_set_option_signer(formatter_data_t *fdata) {
signer_t *signer = &fdata->envelope->tx_details.tx.op_details.set_options_op.signer;
if (signer->weight) {
STRLCPY(fdata->caption, "Add Signer", fdata->caption_len);
} else {
STRLCPY(fdata->caption, "Remove Signer", fdata->caption_len);
}
switch (signer->key.type) {
case SIGNER_KEY_TYPE_ED25519: {
STRLCPY(fdata->value, "Type Public Key", fdata->value_len);
break;
}
case SIGNER_KEY_TYPE_HASH_X: {
STRLCPY(fdata->value, "Type Hash(x)", fdata->value_len);
break;
}
case SIGNER_KEY_TYPE_PRE_AUTH_TX: {
STRLCPY(fdata->value, "Type Pre-Auth", fdata->value_len);
break;
}
case SIGNER_KEY_TYPE_ED25519_SIGNED_PAYLOAD: {
STRLCPY(fdata->value, "Type Ed25519 Signed Payload", fdata->value_len);
break;
}
default:
return false;
}
FORMATTER_CHECK(push_to_formatter_stack(&format_set_option_signer_detail))
return true;
}
static bool format_set_option_signer_prepare(formatter_data_t *fdata) {
if (fdata->envelope->tx_details.tx.op_details.set_options_op.signer_present) {
FORMATTER_CHECK(push_to_formatter_stack(&format_set_option_signer))
} else {
return format_operation_source_prepare(fdata);
}
return true;
}
static bool format_set_option_home_domain(formatter_data_t *fdata) {
STRLCPY(fdata->caption, "Home Domain", fdata->caption_len);
if (fdata->envelope->tx_details.tx.op_details.set_options_op.home_domain_size) {
FORMATTER_CHECK(
print_string(fdata->value,
fdata->value_len,
fdata->envelope->tx_details.tx.op_details.set_options_op.home_domain,
fdata->envelope->tx_details.tx.op_details.set_options_op.home_domain_size))
} else {
STRLCPY(fdata->value, "[remove home domain from account]", fdata->value_len);
}
format_set_option_signer_prepare(fdata);
return true;
}
static bool format_set_option_home_domain_prepare(formatter_data_t *fdata) {
if (fdata->envelope->tx_details.tx.op_details.set_options_op.home_domain_present) {
FORMATTER_CHECK(push_to_formatter_stack(&format_set_option_home_domain))
} else {
format_set_option_signer_prepare(fdata);
}
return true;
}
static bool format_set_option_high_threshold(formatter_data_t *fdata) {
STRLCPY(fdata->caption, "High Threshold", fdata->caption_len);
FORMATTER_CHECK(
print_uint64_num(fdata->envelope->tx_details.tx.op_details.set_options_op.high_threshold,
fdata->value,
fdata->value_len))
format_set_option_home_domain_prepare(fdata);
return true;
}
static bool format_set_option_high_threshold_prepare(formatter_data_t *fdata) {
if (fdata->envelope->tx_details.tx.op_details.set_options_op.high_threshold_present) {
FORMATTER_CHECK(push_to_formatter_stack(&format_set_option_high_threshold))
} else {
format_set_option_home_domain_prepare(fdata);
}
return true;
}
static bool format_set_option_medium_threshold(formatter_data_t *fdata) {
STRLCPY(fdata->caption, "Medium Threshold", fdata->caption_len);
FORMATTER_CHECK(
print_uint64_num(fdata->envelope->tx_details.tx.op_details.set_options_op.medium_threshold,
fdata->value,
fdata->value_len))
format_set_option_high_threshold_prepare(fdata);
return true;
}
static bool format_set_option_medium_threshold_prepare(formatter_data_t *fdata) {
if (fdata->envelope->tx_details.tx.op_details.set_options_op.medium_threshold_present) {
FORMATTER_CHECK(push_to_formatter_stack(&format_set_option_medium_threshold))
} else {
format_set_option_high_threshold_prepare(fdata);
}
return true;
}
static bool format_set_option_low_threshold(formatter_data_t *fdata) {
STRLCPY(fdata->caption, "Low Threshold", fdata->caption_len);
FORMATTER_CHECK(
print_uint64_num(fdata->envelope->tx_details.tx.op_details.set_options_op.low_threshold,
fdata->value,
fdata->value_len))
format_set_option_medium_threshold_prepare(fdata);
return true;
}
static bool format_set_option_low_threshold_prepare(formatter_data_t *fdata) {
if (fdata->envelope->tx_details.tx.op_details.set_options_op.low_threshold_present) {
FORMATTER_CHECK(push_to_formatter_stack(&format_set_option_low_threshold))
} else {
format_set_option_medium_threshold_prepare(fdata);
}
return true;
}
static bool format_set_option_master_weight(formatter_data_t *fdata) {
STRLCPY(fdata->caption, "Master Weight", fdata->caption_len);
FORMATTER_CHECK(
print_uint64_num(fdata->envelope->tx_details.tx.op_details.set_options_op.master_weight,
fdata->value,
fdata->value_len))
format_set_option_low_threshold_prepare(fdata);
return true;
}
static bool format_set_option_master_weight_prepare(formatter_data_t *fdata) {
if (fdata->envelope->tx_details.tx.op_details.set_options_op.master_weight_present) {
FORMATTER_CHECK(push_to_formatter_stack(&format_set_option_master_weight))
} else {
format_set_option_low_threshold_prepare(fdata);
}
return true;
}
static bool format_set_option_set_flags(formatter_data_t *fdata) {
STRLCPY(fdata->caption, "Set Flags", fdata->caption_len);
FORMATTER_CHECK(
print_account_flags(fdata->envelope->tx_details.tx.op_details.set_options_op.set_flags,
fdata->value,
fdata->value_len))
format_set_option_master_weight_prepare(fdata);
return true;
}
static bool format_set_option_set_flags_prepare(formatter_data_t *fdata) {
if (fdata->envelope->tx_details.tx.op_details.set_options_op.set_flags_present) {
FORMATTER_CHECK(push_to_formatter_stack(&format_set_option_set_flags))
} else {
format_set_option_master_weight_prepare(fdata);
}
return true;
}
static bool format_set_option_clear_flags(formatter_data_t *fdata) {
STRLCPY(fdata->caption, "Clear Flags", fdata->caption_len);
FORMATTER_CHECK(
print_account_flags(fdata->envelope->tx_details.tx.op_details.set_options_op.clear_flags,
fdata->value,
fdata->value_len))
format_set_option_set_flags_prepare(fdata);
return true;
}
static bool format_set_option_clear_flags_prepare(formatter_data_t *fdata) {
if (fdata->envelope->tx_details.tx.op_details.set_options_op.clear_flags_present) {
FORMATTER_CHECK(push_to_formatter_stack(&format_set_option_clear_flags))
} else {
format_set_option_set_flags_prepare(fdata);
}
return true;
}
static bool format_set_option_inflation_destination(formatter_data_t *fdata) {
STRLCPY(fdata->caption, "Inflation Dest", fdata->caption_len);
FORMATTER_CHECK(print_account_id(
fdata->envelope->tx_details.tx.op_details.set_options_op.inflation_destination,
fdata->value,
fdata->value_len,
0,
0))
format_set_option_clear_flags_prepare(fdata);
return true;
}
static bool format_set_option_inflation_destination_prepare(formatter_data_t *fdata) {
if (fdata->envelope->tx_details.tx.op_details.set_options_op.inflation_destination_present) {
FORMATTER_CHECK(push_to_formatter_stack(format_set_option_inflation_destination))
} else {
format_set_option_clear_flags_prepare(fdata);
}
return true;
}
static bool format_set_options_empty_body(formatter_data_t *fdata) {
(void) fdata;
STRLCPY(fdata->caption, "SET OPTIONS", fdata->caption_len);
STRLCPY(fdata->value, "[BODY IS EMPTY]", fdata->value_len);
return format_operation_source_prepare(fdata);
}
static bool is_empty_set_options_body(formatter_data_t *fdata) {
return !(
fdata->envelope->tx_details.tx.op_details.set_options_op.inflation_destination_present ||
fdata->envelope->tx_details.tx.op_details.set_options_op.clear_flags_present ||
fdata->envelope->tx_details.tx.op_details.set_options_op.set_flags_present ||
fdata->envelope->tx_details.tx.op_details.set_options_op.master_weight_present ||
fdata->envelope->tx_details.tx.op_details.set_options_op.low_threshold_present ||
fdata->envelope->tx_details.tx.op_details.set_options_op.medium_threshold_present ||
fdata->envelope->tx_details.tx.op_details.set_options_op.high_threshold_present ||
fdata->envelope->tx_details.tx.op_details.set_options_op.home_domain_present ||
fdata->envelope->tx_details.tx.op_details.set_options_op.signer_present);
}
static bool format_set_options(formatter_data_t *fdata) {
// this operation is a special one among all operations, because all its
// fields are optional.
STRLCPY(fdata->caption, "Operation Type", fdata->caption_len);
STRLCPY(fdata->value, "Set Options", fdata->value_len);
if (is_empty_set_options_body(fdata)) {
FORMATTER_CHECK(push_to_formatter_stack(format_set_options_empty_body))
} else {
format_set_option_inflation_destination_prepare(fdata);
}
return true;
}
static bool format_change_trust_limit(formatter_data_t *fdata) {
STRLCPY(fdata->caption, "Trust Limit", fdata->caption_len);
FORMATTER_CHECK(print_amount(fdata->envelope->tx_details.tx.op_details.change_trust_op.limit,
NULL,
fdata->envelope->network,
fdata->value,
fdata->value_len))
return format_operation_source_prepare(fdata);
}
static bool format_change_trust_detail_liquidity_pool_fee(formatter_data_t *fdata) {
STRLCPY(fdata->caption, "Pool Fee Rate", fdata->caption_len);
uint8_t fee[4] = {0};
for (int i = 0; i < 4; i++) {
fee[i] = fdata->envelope->tx_details.tx.op_details.change_trust_op.line.liquidity_pool
.constant_product.fee >>
(8 * (3 - i));
}
FORMATTER_CHECK(print_int32(fee, 2, fdata->value, fdata->value_len, false))
STRLCAT(fdata->value, "%", fdata->value_len);
if (fdata->envelope->tx_details.tx.op_details.change_trust_op.limit &&
fdata->envelope->tx_details.tx.op_details.change_trust_op.limit != INT64_MAX) {
FORMATTER_CHECK(push_to_formatter_stack(&format_change_trust_limit))
} else {
return format_operation_source_prepare(fdata);
}
return true;
}
static bool format_change_trust_detail_liquidity_pool_asset_b(formatter_data_t *fdata) {
STRLCPY(fdata->caption, "Asset B", fdata->caption_len);
FORMATTER_CHECK(print_asset(&fdata->envelope->tx_details.tx.op_details.change_trust_op.line
.liquidity_pool.constant_product.asset_b,
fdata->envelope->network,
fdata->value,
fdata->value_len))
FORMATTER_CHECK(push_to_formatter_stack(&format_change_trust_detail_liquidity_pool_fee))
return true;
}
static bool format_change_trust_detail_liquidity_pool_asset_a(formatter_data_t *fdata) {
STRLCPY(fdata->caption, "Asset A", fdata->caption_len);
FORMATTER_CHECK(print_asset(&fdata->envelope->tx_details.tx.op_details.change_trust_op.line
.liquidity_pool.constant_product.asset_a,
fdata->envelope->network,
fdata->value,
fdata->value_len))
FORMATTER_CHECK(push_to_formatter_stack(&format_change_trust_detail_liquidity_pool_asset_b))
return true;
}
static bool format_change_trust(formatter_data_t *fdata) {
if (fdata->envelope->tx_details.tx.op_details.change_trust_op.limit) {
STRLCPY(fdata->caption, "Change Trust", fdata->caption_len);
} else {
STRLCPY(fdata->caption, "Remove Trust", fdata->caption_len);
}
uint8_t asset_type = fdata->envelope->tx_details.tx.op_details.change_trust_op.line.type;
switch (asset_type) {
case ASSET_TYPE_CREDIT_ALPHANUM4:
case ASSET_TYPE_CREDIT_ALPHANUM12:
FORMATTER_CHECK(print_asset(
(asset_t *) &fdata->envelope->tx_details.tx.op_details.change_trust_op.line,
fdata->envelope->network,
fdata->value,
fdata->value_len))
if (fdata->envelope->tx_details.tx.op_details.change_trust_op.limit &&
fdata->envelope->tx_details.tx.op_details.change_trust_op.limit != INT64_MAX) {
FORMATTER_CHECK(push_to_formatter_stack(&format_change_trust_limit))
} else {
return format_operation_source_prepare(fdata);
}
break;
case ASSET_TYPE_POOL_SHARE:
STRLCPY(fdata->value, "Liquidity Pool Asset", fdata->value_len);
FORMATTER_CHECK(
push_to_formatter_stack(&format_change_trust_detail_liquidity_pool_asset_a))
break;
default:
return false;
}
return true;
}
static bool format_manage_sell_offer_price(formatter_data_t *fdata) {
manage_sell_offer_op_t *op = &fdata->envelope->tx_details.tx.op_details.manage_sell_offer_op;
STRLCPY(fdata->caption, "Price", fdata->caption_len);
FORMATTER_CHECK(print_price(&op->price,
&op->buying,
&op->selling,
fdata->envelope->network,
fdata->value,
fdata->value_len))
return format_operation_source_prepare(fdata);
}
static bool format_manage_sell_offer_sell(formatter_data_t *fdata) {
STRLCPY(fdata->caption, "Sell", fdata->caption_len);
FORMATTER_CHECK(
print_amount(fdata->envelope->tx_details.tx.op_details.manage_sell_offer_op.amount,
&fdata->envelope->tx_details.tx.op_details.manage_sell_offer_op.selling,
fdata->envelope->network,
fdata->value,
fdata->value_len))
FORMATTER_CHECK(push_to_formatter_stack(&format_manage_sell_offer_price))
return true;
}
static bool format_manage_sell_offer_buy(formatter_data_t *fdata) {
STRLCPY(fdata->caption, "Buy", fdata->caption_len);
FORMATTER_CHECK(
print_asset(&fdata->envelope->tx_details.tx.op_details.manage_sell_offer_op.buying,
fdata->envelope->network,
fdata->value,
fdata->value_len))
FORMATTER_CHECK(push_to_formatter_stack(&format_manage_sell_offer_sell))
return true;
}
static bool format_manage_sell_offer(formatter_data_t *fdata) {
if (!fdata->envelope->tx_details.tx.op_details.manage_sell_offer_op.amount) {
STRLCPY(fdata->caption, "Remove Offer", fdata->caption_len);
FORMATTER_CHECK(print_uint64_num(
fdata->envelope->tx_details.tx.op_details.manage_sell_offer_op.offer_id,
fdata->value,
fdata->value_len))
return format_operation_source_prepare(fdata);
} else {
if (fdata->envelope->tx_details.tx.op_details.manage_sell_offer_op.offer_id) {
STRLCPY(fdata->caption, "Change Offer", fdata->caption_len);
FORMATTER_CHECK(print_uint64_num(
fdata->envelope->tx_details.tx.op_details.manage_sell_offer_op.offer_id,
fdata->value,
fdata->value_len))
} else {
STRLCPY(fdata->caption, "Create Offer", fdata->caption_len);
}
FORMATTER_CHECK(push_to_formatter_stack(&format_manage_sell_offer_buy))
}
return true;
}
static bool format_manage_buy_offer_price(formatter_data_t *fdata) {
manage_buy_offer_op_t *op = &fdata->envelope->tx_details.tx.op_details.manage_buy_offer_op;
STRLCPY(fdata->caption, "Price", fdata->caption_len);
FORMATTER_CHECK(print_price(&op->price,
&op->selling,
&op->buying,
fdata->envelope->network,
fdata->value,
fdata->value_len))
return format_operation_source_prepare(fdata);
}
static bool format_manage_buy_offer_buy(formatter_data_t *fdata) {
manage_buy_offer_op_t *op = &fdata->envelope->tx_details.tx.op_details.manage_buy_offer_op;
STRLCPY(fdata->caption, "Buy", fdata->caption_len);
FORMATTER_CHECK(print_amount(op->buy_amount,
&op->buying,
fdata->envelope->network,
fdata->value,
fdata->value_len))
FORMATTER_CHECK(push_to_formatter_stack(&format_manage_buy_offer_price))
return true;
}
static bool format_manage_buy_offer_sell(formatter_data_t *fdata) {
manage_buy_offer_op_t *op = &fdata->envelope->tx_details.tx.op_details.manage_buy_offer_op;
STRLCPY(fdata->caption, "Sell", fdata->caption_len);
FORMATTER_CHECK(
print_asset(&op->selling, fdata->envelope->network, fdata->value, fdata->value_len))
FORMATTER_CHECK(push_to_formatter_stack(&format_manage_buy_offer_buy))
return true;
}
static bool format_manage_buy_offer(formatter_data_t *fdata) {
manage_buy_offer_op_t *op = &fdata->envelope->tx_details.tx.op_details.manage_buy_offer_op;
if (op->buy_amount == 0) {
STRLCPY(fdata->caption, "Remove Offer", fdata->caption_len);
FORMATTER_CHECK(print_uint64_num(op->offer_id, fdata->value, fdata->value_len))
return format_operation_source_prepare(fdata);
} else {
if (op->offer_id) {
STRLCPY(fdata->caption, "Change Offer", fdata->caption_len);
FORMATTER_CHECK(print_uint64_num(op->offer_id, fdata->value, fdata->value_len))
} else {
STRLCPY(fdata->caption, "Create Offer", fdata->caption_len);
}
FORMATTER_CHECK(push_to_formatter_stack(&format_manage_buy_offer_sell))
}
return true;
}
static bool format_create_passive_sell_offer_price(formatter_data_t *fdata) {
create_passive_sell_offer_op_t *op =
&fdata->envelope->tx_details.tx.op_details.create_passive_sell_offer_op;
STRLCPY(fdata->caption, "Price", fdata->caption_len);
FORMATTER_CHECK(print_price(&op->price,
&op->buying,
&op->selling,
fdata->envelope->network,
fdata->value,
fdata->value_len))
return format_operation_source_prepare(fdata);
}
static bool format_create_passive_sell_offer_sell(formatter_data_t *fdata) {
STRLCPY(fdata->caption, "Sell", fdata->caption_len);
FORMATTER_CHECK(print_amount(
fdata->envelope->tx_details.tx.op_details.create_passive_sell_offer_op.amount,
&fdata->envelope->tx_details.tx.op_details.create_passive_sell_offer_op.selling,
fdata->envelope->network,
fdata->value,
fdata->value_len))
FORMATTER_CHECK(push_to_formatter_stack(&format_create_passive_sell_offer_price))
return true;
}
static bool format_create_passive_sell_offer_buy(formatter_data_t *fdata) {
STRLCPY(fdata->caption, "Buy", fdata->caption_len);