-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.html
1232 lines (1068 loc) · 41.9 KB
/
index.html
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
<!DOCTYPE html>
<!--
XRPL serialized object format visualizer
Author: Richard Holland
Date: 6 October 2020
-->
<html>
<head>
<title>XRPL Binary Visualizer</title>
<style>
body {
margin: 0;
padding: 0;
}
div#errormsg {
margin: 0em .8em 0.8em .8em;
padding: 1em;
border-radius: 5px;
border: 1px solid red;
display: none;
color: #b72c00;
font-weight:bold;
font-family: monospace;
padding-left: 1.4em;
}
.clickable:before {
content: "👉";
color: black;
cursor: pointer;
}
.clickable {
cursor: pointer;
background: rgb(43 3 244 / 9%);
margin: 0.3em;
line-height: 1.2em;
padding-left: 0.2em;
padding-right: 0.2em;
}
.tainput {
width: calc(100vw - 2em);
height: 20vh;
margin: 1em;
box-sizing: border-box;
border-radius: 5px;
border: 1px solid #9C27B0;
padding: 1em;
}
.output {
background: hsl(0 0% 98% / 1);
margin: 0em .8em 0.8em .8em;
padding: 1em;
border: 1px solid #2196F3;
border-radius: 5px;
font-family: monospace;
overflow-wrap: break-word;
}
.payloadhex.right {
color: rgb(224 5 5);
}
.left {
margin-right: 1em;
border-right: 1px solid black;
padding-right: 1em;
font: small-caption;
font-size: small;
text-align: right;
max-width: 20em;
color: #673AB7;
font-family: monospace;
display: inline-block;
width: 20em;
}
.right:before {
content: "0x";
font-weight: normal;
color: #9e9e9e5e;
margin-right: 0.1em;
}
.right {
display: inline-block;
text-align: left;
font-family: monospace;
font-weight: bold;
color: hsl(227deg 100% 46%);
vertical-align: top;
text-indent: -1.3em;
padding-left: 1.3em;
word-break: break-word;
width: calc(100vw - 35em);
}
.fieldtext:before {
content: "Field-code";
font-size: smaller;
margin-right: 2em;
color: orange;
position: absolute;
left: 2em;
}
.typetext:before {
content: "Type-code";
font-size: smaller;
margin-right: 2em;
color: orange;
position: absolute;
left: 2em;
}
.payloadtext:before {
content: "Field-contents";
font-size: smaller;
margin-right: 2em;
color: orange;
position: absolute;
left: 2em;
}
.invalid {
}
.type {
}
.field {
}
.explain {
}
.payload {
}
</style>
<script>
var parse_stack = [] // when using objects inside objects this is used, by run_
var indent_level = 0
var unknown_detected = false
function print_error(c, out) {
out.innerHTML += "<br/><div class='invalid left'>Invalid character</div><div class='invalid right'>" +
c + "</div>";
}
let defs = false;
let type_lookup = {};
function process_defs()
{
for (let k in defs["FIELDS"])
{
const fe = defs["FIELDS"][k];
const fe_type = fe[1].type;
let fe_type_code = typeof(defs["TYPES"][fe_type]) == "undefined" ? -1 :
defs["TYPES"][fe_type];
if (!(fe_type_code in type_lookup))
type_lookup[fe_type_code] = {};
type_lookup[fe_type_code][fe[1].nth] =
{
name: fe[0],
vl: fe[1].isVLEncoded,
signing: fe[1].isSigningField
};
}
}
function strip(html)
{
let doc = new DOMParser().parseFromString(html, 'text/html');
return doc.body.textContent || "";
}
function getDefJson(url)
{
fetch(url === undefined || (''+url).trim() == '' ? 'def.json' : strip(url))
.then(function(response) {
return response.json();
})
.then(function(jsonResponse) {
defs = jsonResponse;
process_defs();
}).catch(e=>{
console.log(e);
return ugly("Could not load: " + strip(url));
});
}
getDefJson(window.location.search.substr(1));
function print_type(t, h, out) {
let s = "Unknown";
for (let k in defs["TYPES"])
if (defs["TYPES"][k] == t)
{
s = k;
break;
}
if (s == "Unknown")
unknown_detected = true;
s = s.replaceAll('Hash', 'UInt').toUpperCase();
if (s.substr(0,2) == "ST")
s = s.substr(2);
out.innerHTML += "<br/><div style='margin-left: "+indent_level+"em' class='type'><div class='typetext left'><b>" + s
+ "</b></div><div class='typehex right'>" + h + "</div></div>"
}
function print_field(t, fc, h, out) {
var s = "[[UNKNOWN_FIELD]]"
if ((t in type_lookup) && (fc in type_lookup[t]))
s = type_lookup[t][fc].name;
else
unknown_detected = true;
out.innerHTML += "<br/><div style='margin-left: "+indent_level+"em' class='field'><div class='fieldtext left'><b>" + s +
"</b></div><div class='fieldhex right'>" + h + "</div></div>"
}
function print_explain(h, msg, out, nnl) {
out.innerHTML += (typeof(nnl) == "undefined" ? "" : "<br/>") +
"<div class='explain' style='margin-left: "+indent_level+"em'><div class='explaintext left'>" + msg + "</div>" +
"<div class='explainhex right'>" + h + "</div></div>";
}
function print_explain_payload(h, msg, out, nnl) {
out.innerHTML += (typeof(nnl) == "undefined" ? "" : "<br/>") +
"<div class='explain' style='margin-left: "+indent_level+"em'><div class='explaintext left'>" + msg + "</div>" +
"<div class='payloadhex right'>" + h + "</div></div>";
}
function print_explain_payload_special(h, msg, out, nnl, breakdown) {
out.innerHTML += (typeof(nnl) == "undefined" ? "" : "<br/>") +
"<div class='explain' style='margin-left: "+indent_level+"em'><div class='explaintext left'>" + msg + "</div>" +
"<div class='payloadhex right'>" + h + '<div style="font-weight: normal; color: purple; margin-left:3em;">' + breakdown + '</div></div></div>';
}
function print_payload(t, f, h, msg, out) {
out.innerHTML += "<br/>" +
"<div class='payload' style='margin-left: "+indent_level+"em'><div class='payloadtext left'>" + msg + "</div>" +
"<div class='payloadhex right'>" + h + "</div></div>";
}
function inpele()
{
return document.getElementsByTagName("textarea")[0]
}
function errorele()
{
return document.getElementById("errormsg")
}
// these functions help report errors to the user
function clear()
{
inpele().style.background = "white"
var m = make_up_link()
if (m == "")
{
errorele().innerHTML = ""
errorele().style.display = "none"
} else
{
errorele().innerHTML = m
errorele().style.display = "block"
errorele().style.background = "#ffffff"
errorele().style.color = "#3F51B5"
errorele().style.border = "1px solid blue";
}
}
function good()
{
inpele().style.background = "#e0ffd7"
var m = make_up_link()
errorele().innerHTML = "Looks like a valid STObject. " + m
errorele().style.display = "block"
errorele().style.background = "#d7ffdc"
errorele().style.color = "#3F51B5"
errorele().style.border = "1px solid blue";
}
function bad(msg)
{
inpele().style.background = "#ffd7d7"
errorele().style.background = "#ffd7d7"
errorele().innerHTML = msg + make_up_link()
errorele().style.display = "block"
errorele().style.color = "#F44336"
errorele().style.border = "1px solid red";
}
function make_up_link()
{
return ( parse_stack.length > 0 ? "<a class='clickable' onclick='pop_()'>Go up</a>" : "" )
}
function info(msg)
{
inpele().style.background = "#fafafa"
errorele().style.background = "#fafafa"
errorele().innerHTML = msg + make_up_link()
errorele().style.display = "block"
errorele().style.color = "#3F51B5"
errorele().style.border = "1px solid blue";
}
function ugly(msg)
{
inpele().style.background = "#ffecd7"
errorele().style.background = "#ffecd7"
errorele().innerHTML = msg + make_up_link()
errorele().style.display = "block"
errorele().style.color = "#F44336"
errorele().style.border = "1px solid red";
}
function run_(x)
{
parse_stack.push(inpele().value)
inpele().value = x
run(0, true)
}
function pop_()
{
if (parse_stack.length == 0)
{
console.log("could not pop, no elements on stack")
return
}
const v = parse_stack[parse_stack.length-1]
parse_stack.pop()
inpele().value = v
run(0, true)
}
// convert the leaf values in a json object to links that populate the decoder
function convert_json_to_links(j)
{
Object.keys(j).forEach(function(key) {
var t = typeof(j[key])
if (t == "object")
j[key] = convert_json_to_links(j[key])
else if (t == "string")
{
var inp = j[key].replace(/\s/gi, '')
if (inp.match(/^[A-Fa-f0-9]+$/) || inp.match(/^[-A-Za-z0-9+/]*={0,3}$/))
j[key] = '<a class=vvvv~clickablevvvv~ onclick=vvvv~run_(~vvvv' + inp + '~vvvv)vvvv~>' + j[key] + '</a>'
}
})
return j
}
function obj_to_html(j)
{
var t = JSON.stringify(j)
if (!t.match(/vvvv~/) && !t.match(/~vvvv/))
{
j = convert_json_to_links(j)
var s = JSON.stringify(j, null, 2)
s = s.replaceAll("vvvv~", "'").replaceAll("~vvvv", '"').replaceAll('\n', '<br/>')
s = s.replaceAll(/(<br\/> +)/g, (s, g)=>{ return g.replaceAll(' ', ' '); })
return s
} else
{
var s = JSON.stringify(j, null, 2)
s = s.replaceAll(/(<br\/> +)/g, (s, g)=>{ return g.replaceAll(' ', ' '); })
return s
}
}
function run(depth, dontclearstack) {
if (!defs)
return ugly("No definitions loaded. Try attach ?def.json to the url");
if (!dontclearstack) parse_stack = []
const out = document.getElementsByClassName("output")[0]
out.innerHTML = ""
indent_level = 0
var inp = inpele().value
// do an analysis to see if it's actually base64
if (inp == "")
return clear()
const inp_nospace = inp.replace(/\s/gi, '')
if (inp_nospace[0] == '{')
{
// probably json
try {
j = JSON.parse(inp)
out.innerHTML = obj_to_html(j)
return info("You entered json... Click a field!")
} catch (e) {
console.log(e)
// do nothing
}
}
if (!inp_nospace.match(/^[A-Fa-f0-9]+$/) && /* not hex */
inp_nospace.match(/^[-A-Za-z0-9+/]*={0,3}$/)) /* and is base64 */
{
if (depth > 0) {
console.log("recusrive loop detected, stopping")
return
}
// probably base64, convert to hex
const binstr = atob(inp.replace(/\s/gi, ''))
try {
var j = JSON.parse(binstr)
out.innerHTML = obj_to_html(j)
return info("When decoding base64 I found it contained json... Click a field!")
} catch (e)
{
console.log(e)
inp = ""
for (var i = 0; i < binstr.length; ++i)
{
var hex = binstr.charCodeAt(i).toString(16)
if (hex.length < 2) hex = "0" + hex
inp += hex
}
document.getElementsByTagName("textarea")[0].value = inp
return run(depth + 1, true)
}
}
if (!inp_nospace.match(/^[A-Fa-f0-9]+$/)) /* not hex */
{
return bad("Input was not base64 or hex, I don't know what to do with it...")
}
unknown_detected = false
var negative_depth = false
var state = 0;
var to_accumulate = 0;
var hexaccum = "";
var vec_counter = 0;
var lastnibble = 0;
var st_type = 0;
var st_field = 0;
var field_hex = "";
var array_depth = 0
var object_depth = 0
var amount_type = -1;
var mantissa_carry = 0;
var flags = 0;
var i = 0
for (i = 0; i < inp.length; ++i) {
console.log("state: " + state)
var nibble = 0;
var ascii = inp.charCodeAt(i);
if (ascii >= 48 && ascii <= 57) { // 0-9
nibble = ascii - 48
} else if (ascii >= 65 && ascii <= 70) { // A-F
nibble = ascii - 65 + 10
} else if (ascii >= 97 && ascii <= 102) { // a-f
nibble = ascii - 97 + 10
} else if (ascii == 32 || ascii == 9 || ascii == 10 || ascii == 13) {
// whitepsace, skip
continue
} else {
print_error(inp[i], out)
break;
}
if (state == 51) {
hexaccum += inp[i]
if (st_type == 6 && to_accumulate == -1 && (nibble & 8)) {
to_accumulate = 96 // non-xrp currency
amount_type = 1
} else if (st_type == 6 && to_accumulate == -1 && (nibble & 8) == 0) {
to_accumulate = 16 // xrp currency
amount_type = 0
} else if (st_type == 8 && to_accumulate == 41) {
// accumulate the 2 VL nibbles at the start of the account field
print_explain(hexaccum, "account vl prefix", out)
if (hexaccum == '00')
to_accumulate = 1;
hexaccum = ""
amount_type = -1
}
to_accumulate--
if (amount_type == 0)
{
if (to_accumulate == 15)
{
let r = parseInt(hexaccum, 16) >>> 0;
r &= 0x3;
mantissa_carry = r;
r = r.toString(2);
if (r.length == 1) r = '0' + r;
print_explain_payload_special(hexaccum, "Flags", out, undefined,
'<span style="color:blue;">Bit </span>0 <small style="color:orange;">(XRP Bit)</small> '+
'1 <small style="color:orange;">(Sign Bit + Positve)</small> ' +
r + ' <small style="color:orange;">(First bits of drops integer)</small>'
);
hexaccum = ""
} else if (to_accumulate == 0)
{
print_explain_payload_special(hexaccum, "XRP Drops", out, undefined,
'<span style="color:blue;">Dec </span>' + (mantissa_carry + parseInt(hexaccum, 16))+
' <small style="color:orange;">(XRP Drops including two bits above)</small>'
);
amount_type = -1;
state = 0;
}
} else if (amount_type == 1)
{
if (to_accumulate == 93)
{
let firstthree = parseInt(hexaccum.slice(0,3), 16);
let bits = (firstthree >> 10);
let exponent_num = ((((firstthree >> 2)&0xFF)) >>> 0);
let exponent = exponent_num.toString(2);
if (exponent.length != 8) exponent = '0'.repeat(8 - exponent.length) + exponent;
print_explain_payload_special(hexaccum, "Flags + Exponent",
out, undefined,
'<span style="color:blue;">Bit </span>1 <small style="color:orange;">(Not XRP Bit)</small> ' +
(bits & 1) + ' <small style="color:orange;">(' + ((bits & 1) ? 'Sign Bit + Positive' : 'Sign Bit - Negative') + ')</small> ' +
exponent + ' <small style="color:orange;">(Exponent Raw: ' + exponent_num + ', Adjusted: '+(exponent_num-97)+')</small> ' +
(firstthree & 0x2) + (firstthree & 0x1) + ' <small style="color:orange;">(First two bits of mantissa)</small>');
mantissa_carry = (firstthree & 0x3) << 52;
hexaccum = "";
} else if (to_accumulate == 80)
{
print_explain_payload_special(hexaccum, "Mantissa", out, undefined, '<span style="color:blue;">Dec </span>' + (mantissa_carry + parseInt(hexaccum, 16))+
' <small style="color:orange;">(Mantissa including two bits above)</small>');
hexaccum = "";
} else if (to_accumulate == 40)
{
let currency =
String.fromCharCode(parseInt(hexaccum.slice(24,26), 16)) +
String.fromCharCode(parseInt(hexaccum.slice(26,28), 16)) +
String.fromCharCode(parseInt(hexaccum.slice(28,30), 16));
print_explain_payload_special(hexaccum, "Currency Code", out, undefined, '<span style="color:blue;">Asc </span>' + currency);
hexaccum = "";
} else if (to_accumulate == 0)
{
print_explain_payload(hexaccum, "Issuer", out);
hexaccum = "";
state = 0;
amount_type = -1;
}
} else if (amount_type == -1 && to_accumulate == 0) {
print_payload("", "", hexaccum, " ", out)
state = 0
}
continue
}
if (state == 70) { // parsing a VL field
hexaccum = inp[i]
lastnibble = nibble
state = 71
continue
}
if (state == 71) {
hexaccum += inp[i]
var b = (lastnibble << 4) + nibble
if (b <= 192) {
to_accumulate = b*2
print_explain(hexaccum, "1 byte length " + b, out)
hexaccum = ""
if (to_accumulate == 0)
state = 0;
else
state = (st_type == 19 ? 190 : 51);
continue
} else if (b >= 193 && b <= 240) {
to_accumulate = ((b - 193)*256) + 193
state = 72
continue
} else {
to_accumulate = 12481 + ((b - 241) * 65536)
state = 74
continue
}
}
if (state == 72) {
hexaccum += inp[i]
lastnibble = nibble
state = 73
continue
}
if (state == 73) {
hexaccum += inp[i]
var b = (lastnibble << 4) + nibble
to_accumulate += b
print_explain(hexaccum, "2 byte length " + to_accumulate , out)
to_accumulate *= 2
hexaccum = ""
state = (st_type == 19 ? 190 : 51)
continue
}
if (state == 74) {
hexaccum += inp[i]
lastnibble = nibble
state = 75
continue
}
if (state == 75) {
hexaccum += inp[i]
var b = (lastnibble << 4) + nibble
to_accumulate += b * 256
state = 76
continue
}
if (state == 76) {
hexaccum += inp[i]
lastnibble = nibble
state = 77
continue
}
if (state == 77) {
hexaccum += inp[i]
var b = (lastnibble << 4) + nibble
to_accumulate += b
print_explain(hexaccum, "3 byte length " + to_accumulate, out)
to_accumulate *= 2
hexaccum = ""
state = (st_type == 19 ? 190 : 51)
continue
}
if (state == -4)
{
// check if its another nop (type)
if (nibble == 9)
{
hexaccum += nibble;
state = -3
continue
}
else
{
if (hexaccum != "")
{
print_payload("", "", hexaccum, "", out);
hexaccum = "";
}
state = 0; // fall through
}
}
if (state == -3)
{
hexaccum += nibble
if (nibble == 0)
{
// field uncommon
state = -2
continue
}
state = -4
continue
}
if (state == -2)
{
hexaccum += nibble
state = -4
continue
}
if (state == 0) { // parsing type
if (nibble == 0) {
print_explain(inp[i], "type uncommon", out)
state = 1
continue
}
st_type = nibble // this is the case where it's a one nibble type
print_type(st_type, inp[i], out)
state = 4 // expect 4 bit field code
continue
}
if (state == 4) {
if (nibble == 0) {
print_explain(inp[i], "field uncommon", out)
state = 6
continue
}
st_field = nibble
print_field(st_type, nibble, inp[i], out)
if (st_type == 9)
{
// nop
hexaccum = ""
state = -4
continue
}
state = 5 // state 5 is a fallthrough state so do not continue
}
if (state == 6) {
lastnibble = nibble; // store the high nibble of fieldcode
hexaccum = inp[i];
state = 61;
continue;
}
if (state == 61) {
hexaccum += inp[i];
st_field = (lastnibble << 4) + nibble
print_field(st_type, st_field, hexaccum, out);
state = 5; // both type code (4 bits) and field code (8 bits) parsed
}
if (state == 1) { // parsing type with first nibble = 0
if (nibble == 0) {
print_explain(inp[i], "both type and field uncommon", out)
state = 2 // expect 8 bit typecode next followed by 8 bit field code
continue
}
st_field = nibble // we cant print until we parse type
field_hex = inp[i];
state = 3 // except 8 bit typecode next, we still need to print field
continue
}
if (state == 3) { // expect 8 bit typecode
lastnibble = nibble; // store the high nibble of typecode
hexaccum = inp[i];
state = 31;
continue;
}
if (state == 31) {
hexaccum += inp[i];
st_type = (lastnibble << 4) + nibble
// we still need to print the field because it came first but we didnt know it until we had type
print_field(st_type, st_field, field_hex, out);
print_type(st_type, hexaccum, out);
state = 5; // both field code (4 bits) and type code (8 bits) parsed
}
if (state == 2) { // expect 8 bit typecode followed by 8 bit field code
lastnibble = nibble; // store the high nibble of typecode
hexaccum = inp[i];
state = 21;
continue;
}
if (state == 21) {
hexaccum += inp[i];
st_type = (lastnibble << 4) + nibble
print_type(st_type, hexaccum, out);
state = 22; // expect 8 bit field code
continue;
}
if (state == 22) {
lastnibble = nibble;
hexaccum = inp[i];
state = 23;
continue;
}
if (state == 23) {
hexaccum += inp[i];
st_field = (lastnibble << 4) + nibble;
print_field(st_type, st_field, hexaccum, out);
state = 5; // type and field read
}
if (state == 240)
{
hexaccum += inp[i]
if (--to_accumulate == 0)
{
print_payload("", "", hexaccum, "currency", out);
if (hexaccum != "0".repeat(40))
{
state = 241;
hexaccum = "";
to_accumulate = 42;
continue;
}
state = 0;
}
continue;
}
if (state == 241)
{
hexaccum += inp[i]
if (--to_accumulate == 0)
{
print_payload("", "", hexaccum, "issuer", out);
hexaccum = "";
state = 0;
}
continue;
}
if (state == 250)
{
// account
hexaccum += inp[i]
if (--to_accumulate == 0)
{
print_payload("", "", hexaccum, "locking chain door", out);
hexaccum = "";
state = 251;
to_accumulate = 40;
}
continue;
}
if (state == 251)
{
// currency
hexaccum += inp[i]
if (--to_accumulate == 0)
{
print_payload("", "", hexaccum, "locking chain currency", out);
if (hexaccum != "0".repeat(40))
{
// we need to read a currency-issuer first
state = 252;
hexaccum = "";
to_accumulate = 42;
continue;
}
else
{
// skip to issuing chain door
state = 253;
hexaccum = "";
to_accumulate = 42;
continue;
}
state = 0;
}
continue;
}
if (state == 252)
{
// account
hexaccum += inp[i]
if (--to_accumulate == 0)
{
print_payload("", "", hexaccum, "locking chain issuer", out);
hexaccum = "";
to_accumulate = 42;
state = 253;
}
continue;
}
if (state == 253)
{
// account
hexaccum += inp[i]
if (--to_accumulate == 0)
{
print_payload("", "", hexaccum, "issuing chain door", out);
hexaccum = "";
state = 254;
to_accumulate = 40;
}
continue;
}
if (state == 254)
{
// currnecy
hexaccum += inp[i]
if (--to_accumulate == 0)
{
print_payload("", "", hexaccum, "issuing chain currency", out);
if (hexaccum != "0".repeat(40))
{
// we need to read a currency-issuer first
hexaccum = "";
state = 255;
to_accumulate = 42;
continue;
}
state = 0;
}
continue;
}
if (state == 255)
{
// account
hexaccum += inp[i]
if (--to_accumulate == 0)
{
print_payload("", "", hexaccum, "issuing chain issuer", out);
hexaccum = "";
state = 0;
}
continue;
}
if (state == 5) {
// now we process VL if any and print the field contents
hexaccum = ""
if (st_type == 1) to_accumulate = 4
else if (st_type == 2) to_accumulate = 8
else if (st_type == 3) to_accumulate = 16
else if (st_type == 4) to_accumulate = 32
else if (st_type == 5) to_accumulate = 64
else if (st_type == 6) {
to_accumulate = -1 /* special value because we need the next byte to know how big 16 or 96 */
amount_type = -1
}
else if (st_type == 24) {
to_accumulate = 40;
state = 240
continue
}
else if (st_type == 25) {
to_accumulate = 42;
state = 250
continue
}
else if (st_type == 7) {
state = 70
continue
}
else if (st_type == 8) to_accumulate = 42
else if (st_type == 14) {
if (st_field == 1) {
object_depth-- // end of object