-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblockchainrpcserver.py
3316 lines (3312 loc) · 264 KB
/
blockchainrpcserver.py
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
import queue
import json
import time
import base64
import inspect
def blockingserver(uriresource, postedcontent, headerparams, nextjobgroup, backlinkqueue):
#print((uriresource, postedcontent, nextjobgroup, backlinkqueue).__repr__() + ' on blockingserver')
livefirstactivity = [time.time()]
livelastactivity = [time.time()]
liveresponse = [None]
backlinkqueue.put((livefirstactivity, livelastactivity, liveresponse))
protocolstring, includebody = headerparams
requestrpcjob, = nextjobgroup
requestrpcjobqueue, requestrpcjobpusher, requestrpcsockets = requestrpcjob
uriresourcelen = len(uriresource)
response = b''
if uriresourcelen and uriresource[0:1] == b'/':
requestrpcsocketscount = len(requestrpcsockets)
i = 0
responsecontainer = b''
responsepart = b''
lastresponsepart = b''
while i < requestrpcsocketscount:
rpcsocketqueue, ipportpair, rpcauthpair = requestrpcsockets[i]
if not requestrpcjobpusher.is_alive():
try:
requestrpcjobpusher.start()
except RuntimeError:
pass
status = b'not processed'
bestblockhashhandle = queue.Queue()
requestrpcjobqueue.put((rpcsocketqueue, ipportpair, rpcauthpair, b'{"jsonrpc": "1.0", "method": "getbestblockhash", "id": "blockchainrpcserver_py_' + str(inspect.getframeinfo(inspect.currentframe()).lineno).encode() + b'"}', bestblockhashhandle))
livelastactivity[0] = time.time()
rpcstatus, data = bestblockhashhandle.get()
livelastactivity[0] = time.time()
responsepart2 = b''
if rpcstatus == b'received':
try:
bestblockhash = json.loads(data.decode())['result'].encode()
blockhash = bestblockhash
blockhashstatus = b'ok'
j = 0
while j < 6:
blockrowhandle = queue.Queue()
rawblockrowhandle = queue.Queue()
if blockhashstatus != b'ok':
responsepart2 += b' <span style="color=red;">' + blockhashstatus + b'</span> <br/>'
break
requestrpcjobqueue.put((rpcsocketqueue, ipportpair, rpcauthpair, b'{"jsonrpc": "1.0", "method": "getblock", "params": ["' + blockhash + b'", true], "id": "blockchainrpcserver_py_' + str(inspect.getframeinfo(inspect.currentframe()).lineno).encode() + b'"}', blockrowhandle))
livelastactivity[0] = time.time()
requestrpcjobqueue.put((rpcsocketqueue, ipportpair, rpcauthpair, b'{"jsonrpc": "1.0", "method": "getblock", "params": ["' + blockhash + b'", false], "id": "blockchainrpcserver_py_' + str(inspect.getframeinfo(inspect.currentframe()).lineno).encode() + b'"}', rawblockrowhandle))
livelastactivity[0] = time.time()
rpcstatus2, data2 = blockrowhandle.get()
livelastactivity[0] = time.time()
rawrpcstatus2, rawdata2 = rawblockrowhandle.get()
livelastactivity[0] = time.time()
if rpcstatus2 == b'received':
data2jsonobject = json.loads(data2.decode())
rawblockhex = None
rawblockhexlen = 0
i_28 = 0
if rawrpcstatus2 != b'received':
rawblockbinary = None
else:
## time1_start = time.time()
v1_32 = json.loads(rawdata2.decode())
if v1_32['error'] != None:
rawblockbinary = None
else:
v1_36 = v1_32['result']
rawblockhex = v1_36.encode()
rawblockhexlen = len(rawblockhex)
try:
rawblockbinary = bytes.fromhex(v1_36)
except ValueError:
pass
if (not rawblockhexlen) or (len(rawblockbinary) != (rawblockhexlen >> 1)):
rawblockbinary = None
## time1_end = time.time()
## print('binary block creation took ' + str(time1_end - time1_start) + ' seconds')
blocksizestatus = b'not processed'
blocksize = b''
if rawblockbinary == None:
try:
blocksize = str(data2jsonobject['result']['size']).encode()
blocksizestatus = b'ok'
except KeyError:
blocksizestatus = b'unexpected rpc json response structure (' + str(inspect.getframeinfo(inspect.currentframe()).lineno).encode() + b')'
try:
blocksizestatus = b'rpc json error message: ' + data2jsonobject['error']['message'].encode()
except TypeError:
pass
except TypeError:
blocksizestatus = b'unexpected rpc json response structure (' + str(inspect.getframeinfo(inspect.currentframe()).lineno).encode() + b')'
try:
blocksizestatus = b'rpc json error message: ' + data2jsonobject['error']['message'].encode()
except TypeError:
pass
else:
blocksize = str(len(rawblockbinary)).encode()
blocksizestatus = b'ok'
blockheightstatus = b'not processed'
blockheight = b''
try:
blockheight = str(data2jsonobject['result']['height']).encode()
blockheightstatus = b'ok'
except KeyError:
blockheightstatus = b'unexpected rpc json response structure (' + str(inspect.getframeinfo(inspect.currentframe()).lineno).encode() + b')'
try:
blockheightstatus = b'rpc json error message: ' + data2jsonobject['error']['message'].encode()
except TypeError:
pass
except TypeError:
blockheightstatus = b'unexpected rpc json response structure (' + str(inspect.getframeinfo(inspect.currentframe()).lineno).encode() + b')'
try:
blockheightstatus = b'rpc json error message: ' + data2jsonobject['error']['message'].encode()
except TypeError:
pass
transactioncountstatus = b'not processed'
transactioncount = b''
minerrewardstatus = b'not processed'
minerreward = b''
if rawblockbinary == None:
try:
transactioncount = str(len(data2jsonobject['result']['tx'])).encode()
transactioncountstatus = b'ok'
coinbasetransactionid = data2jsonobject['result']['tx'][0].encode()
coinbasetransactionhandle = queue.Queue()
requestrpcjobqueue.put((rpcsocketqueue, ipportpair, rpcauthpair, b'{"jsonrpc": "1.0", "method": "getrawtransaction", "params": ["' + coinbasetransactionid + b'", 1], "id": "blockchainrpcserver_py_' + str(inspect.getframeinfo(inspect.currentframe()).lineno).encode() + b'"}', coinbasetransactionhandle))
livelastactivity[0] = time.time()
rpcstatus3, data3 = coinbasetransactionhandle.get()
livelastactivity[0] = time.time()
if rpcstatus3 == b'received':
try:
data3jsonobject = json.loads(data3.decode())
txinputcount = len(data3jsonobject['result']['vin'])
k = 0
coinbaseinputstatus = b'coinbase not found'
coinbaseoutputvaluesatoshis = 0
txoutputcount = len(data3jsonobject['result']['vout'])
while k < txoutputcount:
coinbaseoutputvaluesatoshis += int(data3jsonobject['result']['vout'][k]['value'] * 100000000) # Float arithmetic nailed
k += 1
if txinputcount == 1:
try:
col88x = data3jsonobject['result']['vin'][0]['coinbase']
coinbaseinputstatus = b'found'
except KeyError:
pass
else:
coinbaseinputstatus = b'unexpected input count in coinbase transaction: ' + str(txinputcount).encode()
if coinbaseinputstatus == b'found':
v1_48 = coinbaseoutputvaluesatoshis
minerreward = (str(v1_48//100000000)+'.'+str(v1_48%100000000//10000000)+str(v1_48%10000000//1000000)+str(v1_48%1000000//100000)+str(v1_48%100000//10000)+str(v1_48%10000//1000)+str(v1_48%1000//100)+str(v1_48%100//10)+str(v1_48%10)).encode()
minerrewardstatus = b'ok'
else:
minerrewardstatus = coinbaseinputstatus
except json.decoder.JSONDecodeError:
minerrewardstatus = b'could not interpret rpc json response, data3 = ' + data3.__repr__().encode()
except KeyError:
minerrewardstatus = b'unexpected rpc json response structure (' + str(inspect.getframeinfo(inspect.currentframe()).lineno).encode() + b')'
try:
minerrewardstatus = b'rpc json error message: ' + json.loads(data3.decode())['error']['message'].encode()
except TypeError:
pass
except TypeError:
minerrewardstatus = b'unexpected rpc json response structure (' + str(inspect.getframeinfo(inspect.currentframe()).lineno).encode() + b')'
try:
minerrewardstatus = b'rpc json error message: ' + json.loads(data3.decode())['error']['message'].encode()
except TypeError:
pass
except KeyError:
transactioncountstatus = b'unexpected rpc json response structure (' + str(inspect.getframeinfo(inspect.currentframe()).lineno).encode() + b')'
try:
transactioncountstatus = b'rpc json error message: ' + data2jsonobject['error']['message'].encode()
except TypeError:
pass
except TypeError:
transactioncountstatus = b'unexpected rpc json response structure (' + str(inspect.getframeinfo(inspect.currentframe()).lineno).encode() + b')'
try:
transactioncountstatus = b'rpc json error message: ' + data2jsonobject['error']['message'].encode()
except TypeError:
pass
else:
try:
i_36 = 80 #block header
if rawblockbinary[i_36] == b'\xff'[0]:
transactioncount = str(rawblockbinary[i_36+1] + rawblockbinary[i_36+2]*(1<<8) + rawblockbinary[i_36+3]*(1<<16) + rawblockbinary[i_36+4]*(1<<24) + rawblockbinary[i_36+5]*(1<<32) + rawblockbinary[i_36+6]*(1<<40) + rawblockbinary[i_36+7]*(1<<48) + rawblockbinary[i_36+8]*(1<<56)).encode()
i_36 += 9
elif rawblockbinary[i_36] == b'\xfe'[0]:
transactioncount = str(rawblockbinary[i_36+1] + rawblockbinary[i_36+2]*(1<<8) + rawblockbinary[i_36+3]*(1<<16) + rawblockbinary[i_36+4]*(1<<24)).encode()
i_36 += 5
elif rawblockbinary[i_36] == b'\xfd'[0]:
transactioncount = str(rawblockbinary[i_36+1] + rawblockbinary[i_36+2]*(1<<8)).encode()
i_36 += 3
else:
transactioncount = str(rawblockbinary[i_36]).encode()
i_36 += 1
transactioncountstatus = b'ok'
i_36 += 4 #first transaction version
v1_36 = 0 #first transaction vin count
if rawblockbinary[i_36] == b'\xff'[0]:
v1_36 = rawblockbinary[i_36+1] + rawblockbinary[i_36+2]*(1<<8) + rawblockbinary[i_36+3]*(1<<16) + rawblockbinary[i_36+4]*(1<<24) + rawblockbinary[i_36+5]*(1<<32) + rawblockbinary[i_36+6]*(1<<40) + rawblockbinary[i_36+7]*(1<<48) + rawblockbinary[i_36+8]*(1<<56)
i_36 += 9
elif rawblockbinary[i_36] == b'\xfe'[0]:
v1_36 = rawblockbinary[i_36+1] + rawblockbinary[i_36+2]*(1<<8) + rawblockbinary[i_36+3]*(1<<16) + rawblockbinary[i_36+4]*(1<<24)
i_36 += 5
elif rawblockbinary[i_36] == b'\xfd'[0]:
v1_36 = rawblockbinary[i_36+1] + rawblockbinary[i_36+2]*(1<<8)
i_36 += 3
else:
v1_36 = rawblockbinary[i_36]
i_36 += 1
j_36 = 0
while j_36 < v1_36:
i_36 += 32 #vin previous txid
i_36 += 4 #vin previous txid index
v1_40 = 0 #vin script len
if rawblockbinary[i_36] == b'\xff'[0]:
v1_40 = rawblockbinary[i_36+1] + rawblockbinary[i_36+2]*(1<<8) + rawblockbinary[i_36+3]*(1<<16) + rawblockbinary[i_36+4]*(1<<24) + rawblockbinary[i_36+5]*(1<<32) + rawblockbinary[i_36+6]*(1<<40) + rawblockbinary[i_36+7]*(1<<48) + rawblockbinary[i_36+8]*(1<<56)
i_36 += 9
elif rawblockbinary[i_36] == b'\xfe'[0]:
v1_40 = rawblockbinary[i_36+1] + rawblockbinary[i_36+2]*(1<<8) + rawblockbinary[i_36+3]*(1<<16) + rawblockbinary[i_36+4]*(1<<24)
i_36 += 5
elif rawblockbinary[i_36] == b'\xfd'[0]:
v1_40 = rawblockbinary[i_36+1] + rawblockbinary[i_36+2]*(1<<8)
i_36 += 3
else:
v1_40 = rawblockbinary[i_36]
i_36 += 1
i_36 += v1_40 #vin script
i_36 += 4 #vin sequenceno
j_36 += 1
v2_36 = 0 #first transaction vout count
if rawblockbinary[i_36] == b'\xff'[0]:
v2_36 = rawblockbinary[i_36+1] + rawblockbinary[i_36+2]*(1<<8) + rawblockbinary[i_36+3]*(1<<16) + rawblockbinary[i_36+4]*(1<<24) + rawblockbinary[i_36+5]*(1<<32) + rawblockbinary[i_36+6]*(1<<40) + rawblockbinary[i_36+7]*(1<<48) + rawblockbinary[i_36+8]*(1<<56)
i_36 += 9
elif rawblockbinary[i_36] == b'\xfe'[0]:
v2_36 = rawblockbinary[i_36+1] + rawblockbinary[i_36+2]*(1<<8) + rawblockbinary[i_36+3]*(1<<16) + rawblockbinary[i_36+4]*(1<<24)
i_36 += 5
elif rawblockbinary[i_36] == b'\xfd'[0]:
v2_36 = rawblockbinary[i_36+1] + rawblockbinary[i_36+2]*(1<<8)
i_36 += 3
else:
v2_36 = rawblockbinary[i_36]
i_36 += 1
j_36 = 0
v3_36 = 0 #first transaction vout value sum aka miner reward
while j_36 < v1_36:
v3_36 += rawblockbinary[i_36] + rawblockbinary[i_36+1]*(1<<8) + rawblockbinary[i_36+2]*(1<<16) + rawblockbinary[i_36+3]*(1<<24) + rawblockbinary[i_36+4]*(1<<32) + rawblockbinary[i_36+5]*(1<<40) + rawblockbinary[i_36+6]*(1<<48) + rawblockbinary[i_36+7]*(1<<56)
i_36 += 8
v1_40 = 0 #vout script len
if rawblockbinary[i_36] == b'\xff'[0]:
v1_40 = rawblockbinary[i_36+1] + rawblockbinary[i_36+2]*(1<<8) + rawblockbinary[i_36+3]*(1<<16) + rawblockbinary[i_36+4]*(1<<24) + rawblockbinary[i_36+5]*(1<<32) + rawblockbinary[i_36+6]*(1<<40) + rawblockbinary[i_36+7]*(1<<48) + rawblockbinary[i_36+8]*(1<<56)
i_36 += 9
elif rawblockbinary[i_36] == b'\xfe'[0]:
v1_40 = rawblockbinary[i_36+1] + rawblockbinary[i_36+2]*(1<<8) + rawblockbinary[i_36+3]*(1<<16) + rawblockbinary[i_36+4]*(1<<24)
i_36 += 5
elif rawblockbinary[i_36] == b'\xfd'[0]:
v1_40 = rawblockbinary[i_36+1] + rawblockbinary[i_36+2]*(1<<8)
i_36 += 3
else:
v1_40 = rawblockbinary[i_36]
i_36 += 1
i_36 += v1_40 #vout script
j_36 += 1
minerreward = (str(v3_36//100000000)+'.'+str(v3_36%100000000//10000000)+str(v3_36%10000000//1000000)+str(v3_36%1000000//100000)+str(v3_36%100000//10000)+str(v3_36%10000//1000)+str(v3_36%1000//100)+str(v3_36%100//10)+str(v3_36%10)).encode()
minerrewardstatus = b'ok'
# += 4 #locktime
except IndexError:
minerrewardstatus = b'invalid raw block received'
blocktimestatus = b'not processed'
blocktime = b''
if rawblockbinary == None:
try:
blocktime = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(data2jsonobject['result']['time'])).encode()
blocktimestatus = b'ok'
except KeyError:
blocktimestatus = b'unexpected rpc json response structure (' + str(inspect.getframeinfo(inspect.currentframe()).lineno).encode() + b')'
try:
blocktimestatus = b'rpc json error message: ' + data2jsonobject['error']['message'].encode()
except TypeError:
pass
else:
i_32 = 4 #block version
i_32 += 32 #previous block hash
i_32 += 32 #merkle root
try:
blocktime = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(rawblockbinary[i_32] + rawblockbinary[i_32+1]*(1<<8) + rawblockbinary[i_32+2]*(1<<16) + rawblockbinary[i_32+3]*(1<<24))).encode()
blocktimestatus = b'ok'
except IndexError:
blocktimestatus += b'invalid raw block received'
responsepart3 = b''
if blockheightstatus == b'ok':
responsepart3 += b' <b>Block Height</b>: <a href="/getblockbyheight/' + blockheight + b'/">' + blockheight + b'</a>'
else:
responsepart3 += b' <b>Block Height</b>: <span style="color:red;">' + blockheightstatus + b'</span>'
responsepart3 += b' <a href="/getblockbyhash/' + blockhash + b'/">hash</a>'
if blocktimestatus == b'ok':
responsepart3 += b' <b>Time</b>: ' + blocktime
else:
responsepart3 += b' <b>Time</b>: <span style="color:red;">' + blocktimestatus + b'</span>'
if transactioncountstatus == b'ok':
responsepart3 += b' <b>Transaction Count</b>: ' + transactioncount
else:
responsepart3 += b' <b>Transaction Count</b>: <span style="color:red;">' + transactioncountstatus + b'</span>'
if minerrewardstatus == b'ok':
responsepart3 += b' <b>Miner Reward</b>: ' + minerreward
else:
responsepart3 += b' <b>Miner Reward</b>: <span style="color:red;">' + minerrewardstatus + b'</span>'
if blocksizestatus == b'ok':
responsepart3 += b' <b>Block Size</b>: ' + blocksize
else:
responsepart3 += b' <b>Block Size</b>: <span style="color:red;">' + blocksizestatus + b'</span>'
responsepart2 += responsepart3 + b' <br/>'
status = b'ok'
try:
blockhash = data2jsonobject['result']['previousblockhash'].encode()
except KeyError:
blockhashstatus = b'no previous block hash'
else:
status = b'rpc response delivery status: ' + rpcstatus2
break
j += 1
except json.decoder.JSONDecodeError:
status = b'could not interpret rpc json response, data = ' + data.__repr__().encode()
except KeyError:
status = b'unexpected rpc json response structure (' + str(inspect.getframeinfo(inspect.currentframe()).lineno).encode() + b')'
try:
status = b'rpc json error message: ' + json.loads(data.decode())['error']['message'].encode()
except TypeError:
pass
except TypeError:
status = b'unexpected rpc json response structure (' + str(inspect.getframeinfo(inspect.currentframe()).lineno).encode() + b')'
try:
status = b'rpc json error message: ' + json.loads(data.decode())['error']['message'].encode()
except TypeError:
pass
except AttributeError:
status = b'unexpected rpc json response structure (' + str(inspect.getframeinfo(inspect.currentframe()).lineno).encode() + b')'
else:
status = b'rpc response delivery status: ' + rpcstatus
if status != b'ok':
responsepart2 += b' <span style="color=red;">' + status + b'</span> <br/>'
unescapedid = rpcsocketqueue.__repr__().encode()
unescapedidlen = len(unescapedid)
escapedid = b''
i_j = 0
while i_j < unescapedidlen:
if unescapedid[i_j:i_j+1] == b'"':
escapedid += b'"'
elif unescapedid[i_j:i_j+1] == b'&':
escapedid += b'&'
elif unescapedid[i_j:i_j+1] == b"'":
escapedid += b'''
elif unescapedid[i_j:i_j+1] == b'<':
escapedid += b'<'
elif unescapedid[i_j:i_j+1] == b'>':
escapedid += b'>'
else:
escapedid += unescapedid[i_j:i_j+1]
i_j += 1
col52family, ip, port = ipportpair
responsepart = b' <b>Previous 6 blocks on endpoint ' + ip.encode() + b':' + str(port).encode() + b' bound to ' + escapedid + b'</b> <br/>' + responsepart2
if responsepart == lastresponsepart:
responsecontainer += b' <b><span style="color:green;">Duplicate content dropped from endpoint ' + ip.encode() + b':' + str(port).encode() + b'</span></b> <br/>'
else:
responsecontainer += responsepart
lastresponsepart = responsepart
i += 1
i = 0
responsepart = b''
lastresponsepart = b''
while i < requestrpcsocketscount:
rpcsocketqueue, ipportpair, rpcauthpair = requestrpcsockets[i]
if not requestrpcjobpusher.is_alive():
try:
requestrpcjobpusher.start()
except RuntimeError:
pass
responsepart2 = b''
if uriresource[0:len(b'/getblockbyheight/')] == b'/getblockbyheight/' or uriresource[0:len(b'/getblockbyhash/')] == b'/getblockbyhash/' or uriresource[0:len(b'/address/')] == b'/address/' or uriresource[0:len(b'/mempool/')] == b'/mempool/' or uriresource[0:len(b'/tx/')] == b'/tx/':
blockhashstatus = b'not processed'
blockhash = b''
httpchoice = b'not processed'
j = 0
if uriresource[0:len(b'/getblockbyheight/')] == b'/getblockbyheight/':
httpchoice = b'block'
j = len(b'/getblockbyheight/')
blockheight = 0
while j < uriresourcelen:
if b'0'[0] <= uriresource[j] and uriresource[j] <= b'9'[0]:
blockheight = blockheight * 10 + uriresource[j] - b'0'[0]
elif uriresource[j:j+1] == b'/':
getblockbyheighthandle = queue.Queue()
requestrpcjobqueue.put((rpcsocketqueue, ipportpair, rpcauthpair, b'{"jsonrpc": "1.0", "method": "getblockhash", "params": [' + str(blockheight).encode() + b'], "id": "blockchainrpcserver_py_' + str(inspect.getframeinfo(inspect.currentframe()).lineno).encode() + b'"}', getblockbyheighthandle))
livelastactivity[0] = time.time()
rpcstatus, data = getblockbyheighthandle.get()
livelastactivity[0] = time.time()
if rpcstatus == b'received':
try:
blockhash = json.loads(data.decode())['result'].encode()
blockhashstatus = b'ok'
except json.decoder.JSONDecodeError:
blockhashstatus = b'could not interpret rpc json response, data = ' + data.__repr__().encode()
except KeyError:
blockhashstatus = b'unexpected rpc json response structure (' + str(inspect.getframeinfo(inspect.currentframe()).lineno).encode() + b')'
try:
blockhashstatus = b'rpc json error message: ' + json.loads(data.decode())['error']['message'].encode()
except TypeError:
pass
except TypeError:
blockhashstatus = b'unexpected rpc json response structure (' + str(inspect.getframeinfo(inspect.currentframe()).lineno).encode() + b')'
try:
blockhashstatus = b'rpc json error message: ' + json.loads(data.decode())['error']['message'].encode()
except TypeError:
pass
except AttributeError:
blockhashstatus = b'unexpected rpc json response structure (' + str(inspect.getframeinfo(inspect.currentframe()).lineno).encode() + b')'
try:
blockhashstatus = b'rpc json error message: ' + json.loads(data.decode())['error']['message'].encode()
except TypeError:
pass
else:
blockhashstatus = b'rpc response delivery status: ' + rpcstatus
break
else:
blockhashstatus = b'invalid block height requested'
break
j += 1
if uriresource[0:len(b'/getblockbyhash/')] == b'/getblockbyhash/':
httpchoice = b'block'
j = len(b'/getblockbyhash/')
blockhash = b''
while j < uriresourcelen:
if b'0'[0] <= uriresource[j] and uriresource[j] <= b'9'[0]:
blockhash += uriresource[j:j+1]
elif b'a'[0] <= uriresource[j] and uriresource[j] <= b'f'[0]:
blockhash += uriresource[j:j+1]
elif uriresource[j:j+1] == b'/':
blockhashstatus = b'ok'
break
else:
break
j += 1
if len(blockhash) != len(b'000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f'):
blockhashstatus = b'invalid block hash requested'
addressstatus = b'not processed'
address = b''
if uriresource[0:len(b'/address/')] == b'/address/':
httpchoice = b'address'
j = len(b'/address/')
while j < uriresourcelen:
if b'1'[0] <= uriresource[j] and uriresource[j] <= b'9'[0]:
address += uriresource[j:j+1]
elif b'A'[0] <= uriresource[j] and uriresource[j] <= b'H'[0]:
address += uriresource[j:j+1]
elif b'J'[0] <= uriresource[j] and uriresource[j] <= b'N'[0]:
address += uriresource[j:j+1]
elif b'P'[0] <= uriresource[j] and uriresource[j] <= b'Z'[0]:
address += uriresource[j:j+1]
elif b'a'[0] <= uriresource[j] and uriresource[j] <= b'k'[0]:
address += uriresource[j:j+1]
elif b'm'[0] <= uriresource[j] and uriresource[j] <= b'z'[0]:
address += uriresource[j:j+1]
elif uriresource[j:j+1] == b'/':
addressstatus = b'ok'
break
else:
break
j += 1
mempoolstatus = b'not processed'
if uriresource[0:len(b'/mempool/')] == b'/mempool/':
httpchoice = b'mempool'
j = len(b'/mempool/') - 1
mempoolstatus = b'ok'
requestedtxarray = []
lastrequestedtx = b''
while j < uriresourcelen:
if uriresource[j:j+len(b'/tx/')] == b'/tx/':
lastrequestedtx = b''
j += len(b'/tx/')
while j < uriresourcelen:
if b'0'[0] <= uriresource[j] and uriresource[j] <= b'9'[0]:
lastrequestedtx += uriresource[j:j+1]
elif b'a'[0] <= uriresource[j] and uriresource[j] <= b'f'[0]:
lastrequestedtx += uriresource[j:j+1]
else:
break
j += 1
if len(lastrequestedtx) == len(b'4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b'):
requestedtxarray += [lastrequestedtx]
else:
break
## tracebackcommand = None
## if uriresource[j:j+len(b'/traceback/locaterequested/')] == b'/traceback/locaterequested/':
## tracebackcommand = b'locaterequested'
## elif uriresource[j:j+len(b'/traceback/locatereturned/')] == b'/traceback/locatereturned/':
## tracebackcommand = b'locatereturned'
## elif uriresource[j:j+len(b'/traceback/locateall/')] == b'/traceback/locateall/':
## tracebackcommand = b'locateall'
## elif uriresource[j:j+len(b'/traceback/locaterequesteddeps/')] == b'/traceback/locaterequesteddeps/':
## tracebackcommand = b'locaterequesteddeps'
## elif uriresource[j:j+len(b'/traceback/locatereturneddeps/')] == b'/traceback/locatereturneddeps/':
## tracebackcommand = b'locatereturneddeps'
## elif uriresource[j:j+len(b'/traceback/locatealldeps/')] == b'/traceback/locatealldeps/':
## tracebackcommand = b'locatealldeps'
## elif uriresource[j:j+len(b'/traceback/tracebackrequested/')] == b'/traceback/tracebackrequested/':
## tracebackcommand = b'tracebackrequested'
## elif uriresource[j:j+len(b'/traceback/tracebackreturned/')] == b'/traceback/tracebackreturned/':
## tracebackcommand = b'tracebackreturned'
## elif uriresource[j:j+len(b'/traceback/tracebackall/')] == b'/traceback/tracebackall/':
## tracebackcommand = b'tracebackall'
## elif uriresource[j:j+len(b'/traceback/tracebackrequesteddeps/')] == b'/traceback/tracebackrequesteddeps/':
## tracebackcommand = b'tracebackrequesteddeps'
## elif uriresource[j:j+len(b'/traceback/tracebackreturneddeps/')] == b'/traceback/tracebackreturneddeps/':
## tracebackcommand = b'tracebackreturneddeps'
## elif uriresource[j:j+len(b'/traceback/tracebackalldeps/')] == b'/traceback/tracebackalldeps/':
## tracebackcommand = b'tracebackalldeps'
requestedtxmap = {}
for requestedtxindex, requestedtxid in enumerate(requestedtxarray):
requestedtxmap[requestedtxid] = requestedtxindex
responsepart2 = b''
returnedtxlist = []
rawblockbinary = b''
rawblockhex = None
rawblockindex = 0
if httpchoice == b'block':
print('httpchoice block hit')
blockhashquerystatus = b'no errors'
if blockhashstatus == b'ok':
blockhashqueryhandle = queue.Queue()
rawblockhashqueryhandle = queue.Queue()
requestrpcjobqueue.put((rpcsocketqueue, ipportpair, rpcauthpair, b'{"jsonrpc": "1.0", "method": "getblock", "params": ["' + blockhash + b'", true], "id": "blockchainrpcserver_py_' + str(inspect.getframeinfo(inspect.currentframe()).lineno).encode() + b'"}', blockhashqueryhandle))
livelastactivity[0] = time.time()
requestrpcjobqueue.put((rpcsocketqueue, ipportpair, rpcauthpair, b'{"jsonrpc": "1.0", "method": "getblock", "params": ["' + blockhash + b'", false], "id": "blockchainrpcserver_py_' + str(inspect.getframeinfo(inspect.currentframe()).lineno).encode() + b'"}', rawblockhashqueryhandle))
livelastactivity[0] = time.time()
rpcstatus, data = blockhashqueryhandle.get()
livelastactivity[0] = time.time()
rawblockrpcstatus, rawblockdata = rawblockhashqueryhandle.get()
livelastactivity[0] = time.time()
if rpcstatus == b'received':
try:
rawblockbinary = b''
rawblockhex = None
i_32 = 0
if rawblockrpcstatus != b'received':
rawblockbinary = None
else:
v1_36 = json.loads(rawblockdata.decode())
if v1_36['error'] != None:
rawblockbinary = None
else:
v1_40 = json.loads(rawblockdata.decode())['result']
rawblockhex = v1_40.encode()
try:
rawblockbinary = bytes.fromhex(rawblockhex.decode())
except ValueError:
rawblockbinary = None
if len(rawblockbinary) != (len(rawblockhex)>>1) or (not rawblockhex):
rawblockbinary = None
datajsonobject = json.loads(data.decode())
blockrawheaderstatus = b'not processed'
blockrawheader = b''
if rawblockbinary == None:
blockrawheaderstatus = b'raw block not available'
else:
try:
blockrawheader = rawblockhex[0:80*2]
blockrawheaderstatus = b'ok'
except IndexError:
blockrawheaderstatus = b'invalid raw block received'
blockconfirmationsstatus = b'not processed'
blockconfirmations = b''
try:
blockconfirmations = str(datajsonobject['result']['confirmations']).encode()
blockconfirmationsstatus = b'ok'
except KeyError:
blockconfirmationsstatus = b'unexpected rpc json response structure (' + str(inspect.getframeinfo(inspect.currentframe()).lineno).encode() + b')'
try:
blockconfirmationsstatus = b'rpc json error message: ' + datajsonobject['error']['message'].encode()
except TypeError:
pass
except TypeError:
blockconfirmationsstatus = b'unexpected rpc json response structure (' + str(inspect.getframeinfo(inspect.currentframe()).lineno).encode() + b')'
try:
blockconfirmationsstatus = b'rpc json error message: ' + datajsonobject['error']['message'].encode()
except TypeError:
pass
blocksizestatus = b'not processed'
blocksize = b''
if rawblockbinary == None:
try:
blocksize = str(datajsonobject['result']['size']).encode()
blocksizestatus = b'ok'
except KeyError:
blocksizestatus = b'unexpected rpc json response structure (' + str(inspect.getframeinfo(inspect.currentframe()).lineno).encode() + b')'
try:
blocksizestatus = b'rpc json error message: ' + datajsonobject['error']['message'].encode()
except TypeError:
pass
except TypeError:
blocksizestatus = b'unexpected rpc json response structure (' + str(inspect.getframeinfo(inspect.currentframe()).lineno).encode() + b')'
try:
blocksizestatus = b'rpc json error message: ' + datajsonobject['error']['message'].encode()
except TypeError:
pass
else:
blocksize = str(len(rawblockbinary)).encode()
blocksizestatus = b'ok'
blockheightstatus = b'not processed'
blockheight = b''
try:
blockheight = str(datajsonobject['result']['height']).encode()
blockheightstatus = b'ok'
except KeyError:
blockheightstatus = b'unexpected rpc json response structure (' + str(inspect.getframeinfo(inspect.currentframe()).lineno).encode() + b')'
try:
blockheightstatus = b'rpc json error message: ' + datajsonobject['error']['message'].encode()
except TypeError:
pass
except TypeError:
blockheightstatus = b'unexpected rpc json response structure (' + str(inspect.getframeinfo(inspect.currentframe()).lineno).encode() + b')'
try:
blockheightstatus = b'rpc json error message: ' + datajsonobject['error']['message'].encode()
except TypeError:
pass
blockversionstatus = b'not processed'
blockversion = b''
if rawblockbinary == None:
try:
blockversion = hex(datajsonobject['result']['version']).encode()
blockversionstatus = b'ok'
except KeyError:
blockversionstatus = b'unexpected rpc json response structure (' + str(inspect.getframeinfo(inspect.currentframe()).lineno).encode() + b')'
try:
blockversionstatus = b'rpc json error message: ' + datajsonobject['error']['message'].encode()
except TypeError:
pass
except TypeError:
blockversionstatus = b'unexpected rpc json response structure (' + str(inspect.getframeinfo(inspect.currentframe()).lineno).encode() + b')'
try:
blockversionstatus = b'rpc json error message: ' + datajsonobject['error']['message'].encode()
except TypeError:
pass
else:
try:
blockversion = hex(rawblockbinary[0] + rawblockbinary[1]*(1<<8) + rawblockbinary[2]*(1<<16) + rawblockbinary[3]*(1<<24)).encode()
blockversionstatus = b'ok'
except IndexError:
blockversionstatus = b'invalid raw block received'
blockmerklerootstatus = b'not processed'
blockmerkleroot = b''
if rawblockbinary == None:
try:
blockmerkleroot = datajsonobject['result']['merkleroot'].encode()
blockmerklerootstatus = b'ok'
except KeyError:
blockmerklerootstatus = b'unexpected rpc json response structure (' + str(inspect.getframeinfo(inspect.currentframe()).lineno).encode() + b')'
try:
blockmerklerootstatus = b'rpc json error message: ' + datajsonobject['error']['message'].encode()
except TypeError:
pass
except TypeError:
blockmerklerootstatus = b'unexpected rpc json response structure (' + str(inspect.getframeinfo(inspect.currentframe()).lineno).encode() + b')'
try:
blockmerklerootstatus = b'rpc json error message: ' + datajsonobject['error']['message'].encode()
except TypeError:
pass
else:
try:
i_40 = 4 #block version
i_40 += 32 #previous block hash
j_40 = 0
while j_40 < 32:
blockmerkleroot += rawblockhex[(i_40 + 31 - j_40)*2:(i_40 + 32 - j_40)*2]
j_40 += 1
blockmerklerootstatus = b'ok'
except IndexError:
blockmerklerootstatus = b'invalid raw block received'
blocktxcountstatus = b'not processed'
blocktxcount = b''
blockminerrewardstatus = b'not processed'
blockminerreward = b''
blockcoinbasestatus = b'not processed'
blockcoinbase = b''
blocktxarray = []
try:
blocktxcountinteger = len(datajsonobject['result']['tx'])
blocktxcount = str(blocktxcountinteger).encode()
blocktxcountstatus = b'ok'
j = 0
while j < blocktxcountinteger:
foundtxid = datajsonobject['result']['tx'][j].encode()
txisrequested = False
try:
x = requestedtxarray[requestedtxmap[foundtxid]]
txisrequested = True
except KeyError:
pass
if txisrequested:
blocktxarray += [(foundtxid, queue.Queue())]
else:
blocktxarray += [(foundtxid,)]
j += 1
except KeyError:
blocktxcountstatus = b'unexpected rpc json response structure (' + str(inspect.getframeinfo(inspect.currentframe()).lineno).encode() + b')'
try:
blocktxcountstatus = b'rpc json error message: ' + datajsonobject['error']['message'].encode()
except TypeError:
pass
except TypeError:
blocktxcountstatus = b'unexpected rpc json response structure (' + str(inspect.getframeinfo(inspect.currentframe()).lineno).encode() + b')'
try:
blocktxcountstatus = b'rpc json error message: ' + datajsonobject['error']['message'].encode()
except TypeError:
pass
returnedtxlist = blocktxarray[:]
if rawblockbinary == None:
try:
coinbasetxid = datajsonobject['result']['tx'][0].encode()
coinbasetxqueue = queue.Queue()
requestrpcjobqueue.put((rpcsocketqueue, ipportpair, rpcauthpair, b'{"jsonrpc": "1.0", "method": "getrawtransaction", "params": ["' + coinbasetxid + b'", 1], "id": "blockchainrpcserver_py_' + str(inspect.getframeinfo(inspect.currentframe()).lineno).encode() + b'"}', coinbasetxqueue))
livelastactivity[0] = time.time()
col40rpcstatus, col40data = coinbasetxqueue.get()
livelastactivity[0] = time.time()
col40status = b'no failures'
if col40rpcstatus == b'received':
coinbaseoutputvaluesatoshis = 0
coinbaseoutputvaluestatus = b'not processed'
unescapedcoinbase = b''
unescapedcoinbasestatus = b'not processed'
col44status = b'no failures'
try:
col48datajsonobject = json.loads(col40data.decode())
try:
unescapedcoinbase = col48datajsonobject['result']['vin'][0]['coinbase'].encode()
unescapedcoinbasestatus = b'ok'
coinbaseoutputvaluesatoshis = 0
txoutputcount = len(col48datajsonobject['result']['vout'])
j = 0
while j < txoutputcount:
coinbaseoutputvaluesatoshis += int(col84datajsonobject['result']['vout'][j]['value'] * 100000000)
j += 1
coinbaseoutputvaluestatus = b'ok'
except TypeError:
col44status = b'unexpected rpc json response structure (' + str(inspect.getframeinfo(inspect.currentframe()).lineno).encode() + b')'
try:
col44status = b'rpc json error message: ' + col48datajsonobject['error']['message'].encode()
except TypeError:
pass
except KeyError:
col44status = b'unexpected rpc json response structure (' + str(inspect.getframeinfo(inspect.currentframe()).lineno).encode() + b')'
try:
col44status = b'rpc json error message: ' + col48datajsonobject['error']['message'].encode()
except TypeError:
pass
except json.decoder.JSONDecodeError:
col44status = b'could not interpret rpc json response, col76data = ' + col76data.__repr__().encode()
except AttributeError:
col44status = b'unexpected rpc json response structure (' + str(inspect.getframeinfo(inspect.currentframe()).lineno).encode() + b')'
escapedcoinbase = b''
if unescapedcoinbasestatus == b'ok':
unescapedcoinbaselen = len(unescapedcoinbase)
col48_i = 0
col48status = b'no failures'
while (col48_i + 1) < unescapedcoinbaselen:
col52byte = bytes.fromhex(unescapedcoinbase[col48_i:col48_i+2].decode())
if col52byte == b'"':
escapedcoinbase += b'"'
elif col52byte == b'&':
escapedcoinbase += b'&'
elif col52byte == b"'":
escapedcoinbase += b'''
elif col52byte == b'<':
escapedcoinbase += b'<'
elif col52byte == b'>':
escapedcoinbase += b'>'
elif b' ' <= col52byte and col52byte <= b'~':
escapedcoinbase += col52byte
elif col52byte != None:
escapedcoinbase += b'\\x' + unescapedcoinbase[col48_i:col48_i+2]
else:
col48status = b'unexpected response'
break
col48_i += 2
if col48status == b'no failures':
unescapedcoinbasestatus = b'ok'
else:
unescapedcoinbasestatus = col48status
if unescapedcoinbasestatus == b'ok':
blockcoinbase = escapedcoinbase
blockcoinbasestatus = b'ok'
else:
blockcoinbasestatus = unescapedcoinbasestatus
if coinbaseoutputvaluestatus == b'ok':
v1_48 = coinbaseoutputvaluesatoshis
blockminerreward = (str(v1_48//100000000)+'.'+str(v1_48%100000000//10000000)+str(v1_48%10000000//1000000)+str(v1_48%1000000//100000)+str(v1_48%100000//10000)+str(v1_48%10000//1000)+str(v1_48%1000//100)+str(v1_48%100//10)+str(v1_48%10)).encode()
blockminerrewardstatus = b'ok'
else:
blockminerrewardstatus = coinbaseoutputvaluestatus
else:
col40status = b'rpc response delivery status: ' + col40rpcstatus
blockcoinbasestatus = col40status
blockminerrewardstatus = col40status
except KeyError:
blocktxcountstatus = b'unexpected rpc json response structure (' + str(inspect.getframeinfo(inspect.currentframe()).lineno).encode() + b')'
try:
blocktxcountstatus = b'rpc json error message: ' + datajsonobject['error']['message'].encode()
except TypeError:
pass
except TypeError:
blocktxcountstatus = b'unexpected rpc json response structure (' + str(inspect.getframeinfo(inspect.currentframe()).lineno).encode() + b')'
try:
blocktxcountstatus = b'rpc json error message: ' + datajsonobject['error']['message'].encode()
except TypeError:
pass
else:
try:
#blocktxcount = b''
#blockminerreward = b''
#blockcoinbase = b''
blockcoinbaseraw = b''
j = 0
i_40 = 80 #block header
blocktxcountinteger = 0
if rawblockbinary[i_40] == b'\xff'[0]:
blocktxcountinteger = rawblockbinary[i_40+1] + rawblockbinary[i_40+2]*(1<<8) + rawblockbinary[i_40+3]*(1<<16) + rawblockbinary[i_40+4]*(1<<24) + rawblockbinary[i_40+5]*(1<<32) + rawblockbinary[i_40+6]*(1<<40) + rawblockbinary[i_40+7]*(1<<48) + rawblockbinary[i_40+8]*(1<<56)
i_40 += 9
elif rawblockbinary[i_40] == b'\xfe'[0]:
blocktxcountinteger = rawblockbinary[i_40+1] + rawblockbinary[i_40+2]*(1<<8) + rawblockbinary[i_40+3]*(1<<16) + rawblockbinary[i_40+4]*(1<<24)
i_40 += 5
elif rawblockbinary[i_40] == b'\xfd'[0]:
blocktxcountinteger = rawblockbinary[i_40+1] + rawblockbinary[i_40+2]*(1<<8)
i_40 += 3
else:
blocktxcountinteger = rawblockbinary[i_40]
i_40 += 1
blocktxcount = str(blocktxcountinteger).encode()
blocktxcountstatus = b'ok'
while j < 1: # < blocktxcountinteger:
coinbtx = False
i_40 += 4 #transaction version
v1_44 = 0 #transaction vin count
if rawblockbinary[i_40] == b'\xff'[0]:
v1_44 = rawblockbinary[i_40+1] + rawblockbinary[i_40+2]*(1<<8) + rawblockbinary[i_40+3]*(1<<16) + rawblockbinary[i_40+4]*(1<<24) + rawblockbinary[i_40+5]*(1<<32) + rawblockbinary[i_40+6]*(1<<40) + rawblockbinary[i_40+7]*(1<<48) + rawblockbinary[i_40+8]*(1<<56)
i_40 += 9
elif rawblockbinary[i_40] == b'\xfe'[0]:
v1_44 = rawblockbinary[i_40+1] + rawblockbinary[i_40+2]*(1<<8) + rawblockbinary[i_40+3]*(1<<16) + rawblockbinary[i_40+4]*(1<<24)
i_40 += 5
elif rawblockbinary[i_40] == b'\xfd'[0]:
v1_44 = rawblockbinary[i_40+1] + rawblockbinary[i_40+2]*(1<<8)
i_40 += 3
else:
v1_44 = rawblockbinary[i_40]
i_40 += 1
j_44 = 0
while j_44 < v1_44:
v1_48 = rawblockbinary[i_40:i_40+32]
i_40 += 32 #vin previous txid
v2_48 = rawblockbinary[i_40:i_40+4]
i_40 += 4 #vin previous txid index
v3_48 = 0 #vin script len
if rawblockbinary[i_40] == b'\xff'[0]:
v3_48 = rawblockbinary[i_40+1] + rawblockbinary[i_40+2]*(1<<8) + rawblockbinary[i_40+3]*(1<<16) + rawblockbinary[i_40+4]*(1<<24) + rawblockbinary[i_40+5]*(1<<32) + rawblockbinary[i_40+6]*(1<<40) + rawblockbinary[i_40+7]*(1<<48) + rawblockbinary[i_40+8]*(1<<56)
i_40 += 9
elif rawblockbinary[i_40] == b'\xfe'[0]:
v3_48 = rawblockbinary[i_40+1] + rawblockbinary[i_40+2]*(1<<8) + rawblockbinary[i_40+3]*(1<<16) + rawblockbinary[i_40+4]*(1<<24)
i_40 += 5
elif rawblockbinary[i_40] == b'\xfd'[0]:
v3_48 = rawblockbinary[i_40+1] + rawblockbinary[i_40+2]*(1<<8)
i_40 += 3
else:
v3_48 = rawblockbinary[i_40]
i_40 += 1
if v1_48 == b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' and v2_48 == b'\xff\xff\xff\xff':
blockcoinbaseraw += rawblockbinary[i_40:i_40+v3_48]
coinbtx = True
else:
i_52 = 0
v1_48len = len(v1_48)
v1_52 = b''
while i_52 < v1_48len:
v1_52 += v1_48[v1_48len - 1 - i_52:v1_48len - i_52].hex().encode()
i_52 += 1
i_40 += v3_48 #vin script sometimes coinbase
i_40 += 4 #vin sequenceno
j_44 += 1
v2_44 = 0 #transaction vout count
if rawblockbinary[i_40] == b'\xff'[0]:
v2_44 = rawblockbinary[i_40+1] + rawblockbinary[i_40+2]*(1<<8) + rawblockbinary[i_40+3]*(1<<16) + rawblockbinary[i_40+4]*(1<<24) + rawblockbinary[i_40+5]*(1<<32) + rawblockbinary[i_40+6]*(1<<40) + rawblockbinary[i_40+7]*(1<<48) + rawblockbinary[i_40+8]*(1<<56)
i_40 += 9
elif rawblockbinary[i_40] == b'\xfe'[0]:
v2_44 = rawblockbinary[i_40+1] + rawblockbinary[i_40+2]*(1<<8) + rawblockbinary[i_40+3]*(1<<16) + rawblockbinary[i_40+4]*(1<<24)
i_40 += 5
elif rawblockbinary[i_40] == b'\xfd'[0]:
v2_44 = rawblockbinary[i_40+1] + rawblockbinary[i_40+2]*(1<<8)
i_40 += 3
else:
v2_44 = rawblockbinary[i_40]
i_40 += 1
j_44 = 0
v3_44 = 0 #transaction vout value sum sometimes miner reward
while j_44 < v2_44:
v3_44 += rawblockbinary[i_40] + rawblockbinary[i_40+1]*(1<<8) + rawblockbinary[i_40+2]*(1<<16) + rawblockbinary[i_40+3]*(1<<24) + rawblockbinary[i_40+4]*(1<<32) + rawblockbinary[i_40+5]*(1<<40) + rawblockbinary[i_40+6]*(1<<48) + rawblockbinary[i_40+7]*(1<<56)
i_40 += 8
v1_48 = 0 #vout script len
if rawblockbinary[i_40] == b'\xff'[0]:
v1_48 = rawblockbinary[i_40+1] + rawblockbinary[i_40+2]*(1<<8) + rawblockbinary[i_40+3]*(1<<16) + rawblockbinary[i_40+4]*(1<<24) + rawblockbinary[i_40+5]*(1<<32) + rawblockbinary[i_40+6]*(1<<40) + rawblockbinary[i_40+7]*(1<<48) + rawblockbinary[i_40+8]*(1<<56)
i_40 += 9
elif rawblockbinary[i_40] == b'\xfe'[0]:
v1_48 = rawblockbinary[i_40+1] + rawblockbinary[i_40+2]*(1<<8) + rawblockbinary[i_40+3]*(1<<16) + rawblockbinary[i_40+4]*(1<<24)
i_40 += 5
elif rawblockbinary[i_40] == b'\xfd'[0]:
v1_48 = rawblockbinary[i_40+1] + rawblockbinary[i_40+2]*(1<<8)
i_40 += 3
else:
v1_48 = rawblockbinary[i_40]
i_40 += 1
i_40 += v1_48 #vout script
j_44 += 1
if coinbtx:
blockminerreward = (str(v3_44//100000000)+'.'+str(v3_44%100000000//10000000)+str(v3_44%10000000//1000000)+str(v3_44%1000000//100000)+str(v3_44%100000//10000)+str(v3_44%10000//1000)+str(v3_44%1000//100)+str(v3_44%100//10)+str(v3_44%10)).encode()
blockminerrewardstatus = b'ok'
i_40 += 4 #locktime
j += 1
blockcoinbaserawlen = len(blockcoinbaseraw)
j_40 = 0
while j_40 < blockcoinbaserawlen:
if blockcoinbaseraw[j_40] == b'"'[0]:
blockcoinbase += b'"'
elif blockcoinbaseraw[j_40] == b'&'[0]:
blockcoinbase += b'&'
elif blockcoinbaseraw[j_40] == b"'"[0]:
blockcoinbase += b'''
elif blockcoinbaseraw[j_40] == b'<'[0]:
blockcoinbase += b'<'
elif blockcoinbaseraw[j_40] == b'>'[0]:
blockcoinbase += b'>'
elif b' '[0] <= blockcoinbaseraw[j_40] and blockcoinbaseraw[j_40] <= b'~'[0]:
blockcoinbase += blockcoinbaseraw[j_40:j_40+1]
else:
blockcoinbase += b'\\x' + blockcoinbaseraw[j_40:j_40+1].hex().encode()
j_40 += 1
blockcoinbasestatus = b'ok'
except IndexError:
blocktxcountstatus = b'invalid raw block received'
blockminerrewardstatus = b'invalid raw block received'
blockcoinbasestatus = b'invalid raw block received'
blocktimestatus = b'not processed'
blocktime = b''
if rawblockbinary == None:
try:
blocktime = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(datajsonobject['result']['time'])).encode()
blocktimestatus = b'ok'
except KeyError:
blocktimestatus = b'unexpected rpc json response structure (' + str(inspect.getframeinfo(inspect.currentframe()).lineno).encode() + b')'
try:
blocktimestatus = b'rpc json error message: ' + datajsonobject['error']['message'].encode()
except TypeError:
pass
except TypeError:
blocktimestatus = b'unexpected rpc json response structure (' + str(inspect.getframeinfo(inspect.currentframe()).lineno).encode() + b')'
try:
blocktimestatus = b'rpc json error message: ' + datajsonobject['error']['message'].encode()
except TypeError:
pass
else:
i_36 = 4 #block version
i_36 += 32 #previous block hash
i_36 += 32 #merkle root
try:
blocktime = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(rawblockbinary[i_36] + rawblockbinary[i_36+1]*(1<<8) + rawblockbinary[i_36+2]*(1<<16) + rawblockbinary[i_36+3]*(1<<24))).encode()
blocktimestatus = b'ok'
except IndexError:
blocktimestatus += b'invalid raw block received'
blockmediantimestatus = b'not processed'
blockmediantime = b''
try:
blockmediantime = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(datajsonobject['result']['mediantime'])).encode()
blockmediantimestatus = b'ok'
except KeyError:
blockmediantimestatus = b'unexpected rpc json response structure (' + str(inspect.getframeinfo(inspect.currentframe()).lineno).encode() + b')'
try:
blockmediantimestatus = b'rpc json error message: ' + datajsonobject['error']['message'].encode()
except TypeError:
pass
except TypeError:
blockmediantimestatus = b'unexpected rpc json response structure (' + str(inspect.getframeinfo(inspect.currentframe()).lineno).encode() + b')'
try:
blockmediantimestatus = b'rpc json error message: ' + datajsonobject['error']['message'].encode()
except TypeError:
pass
blocknoncestatus = b'not processed'
blocknonce = b''
if rawblockbinary == None:
try:
blocknonce = hex(datajsonobject['result']['nonce']).encode()
blocknoncestatus = b'ok'