-
Notifications
You must be signed in to change notification settings - Fork 9
/
nado.py
829 lines (628 loc) · 29.3 KB
/
nado.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
import asyncio
import json
import os
import signal
import socket
import sys
import msgpack
import tornado.ioloop
import tornado.web
import versioner
from config import get_config
from genesis import make_genesis, make_folders
from loops.consensus_loop import ConsensusClient
from loops.core_loop import CoreClient
from loops.message_loop import MessageClient
from loops.peer_loop import PeerClient
from memserver import MemServer
from ops.account_ops import get_account, fetch_totals
from ops.block_ops import get_block, fee_over_blocks, get_block_number, get_penalty
from ops.data_ops import get_home, allow_async
from ops.key_ops import keyfile_found, generate_keys, save_keys, load_keys
from ops.log_ops import get_logger, logging
from ops.peer_ops import save_peer, get_remote_status, get_producer_set, check_ip
from ops.transaction_ops import get_transaction, get_transactions_of_account, to_readable_amount
from pympler import summary, muppy
def is_port_in_use(port: int) -> bool:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
return s.connect_ex(("localhost", port)) == 0
def handler(signum, frame):
logger.info(f"Terminating: {signum}: {frame}")
memserver.terminate = True
sys.exit(0)
def serialize(output, name=None, compress=None):
if compress == "msgpack":
output = msgpack.packb(output)
elif not isinstance(output, dict) and name:
output = {name: output}
return output
class HomeHandler(tornado.web.RequestHandler):
def home(self):
self.render("templates/homepage.html", ip=get_config()["ip"])
def get(self):
self.home()
class StatusHandler(tornado.web.RequestHandler):
def status(self):
compress = StatusHandler.get_argument(self, "compress", default="none")
try:
status_dict = {
"reported_uptime": memserver.reported_uptime,
"address": memserver.address,
"transaction_pool_hash": memserver.transaction_pool_hash,
"block_producers_hash": memserver.block_producers_hash,
"latest_block_hash": memserver.latest_block["block_hash"],
"earliest_block_hash": memserver.earliest_block["block_hash"],
"protocol": memserver.protocol,
"version": memserver.version,
}
self.write(serialize(name="status",
output=status_dict,
compress=compress))
except Exception as e:
self.set_status(403)
self.write(f"Error: {e}")
async def get(self, parameter):
await asyncio.to_thread(self.status)
class TransactionPoolHandler(tornado.web.RequestHandler):
def transaction_pool(self):
compress = TransactionPoolHandler.get_argument(self, "compress", default="none")
transaction_pool_data = memserver.transaction_pool
self.write(serialize(name="transaction_pool",
output=transaction_pool_data,
compress=compress))
async def get(self, parameter):
await asyncio.to_thread(self.transaction_pool)
class TransactionBufferHandler(tornado.web.RequestHandler):
def transaction_buffer(self):
compress = TransactionBufferHandler.get_argument(self, "compress", default="none")
buffer_data = memserver.tx_buffer
self.write(serialize(name="transaction_buffer",
output=buffer_data,
compress=compress))
async def get(self, parameter):
await asyncio.to_thread(self.transaction_buffer)
class UserTxBufferHandler(tornado.web.RequestHandler):
def transaction_buffer(self):
compress = UserTxBufferHandler.get_argument(self, "compress", default="none")
buffer_data = memserver.user_tx_buffer
self.write(serialize(name="user_transaction_buffer",
output=buffer_data,
compress=compress))
async def get(self, parameter):
await asyncio.to_thread(self.transaction_buffer)
class TrustPoolHandler(tornado.web.RequestHandler):
def trust_pool(self):
compress = TrustPoolHandler.get_argument(self, "compress", default="none")
trust_pool_data = consensus.trust_pool
self.write(serialize(name="trust_pool_data",
output=trust_pool_data,
compress=compress,
))
async def get(self, parameter):
await asyncio.to_thread(self.trust_pool)
class PeerPoolHandler(tornado.web.RequestHandler):
def peer_pool(self):
compress = PeerPoolHandler.get_argument(self, "compress", default="none")
peers_data = list(memserver.peers)
self.write(serialize(name="peers",
output=peers_data,
compress=compress
))
async def get(self, parameter):
await asyncio.to_thread(self.peer_pool)
class PeerBufferHandler(tornado.web.RequestHandler):
def peer_buffer(self):
compress = PeerBufferHandler.get_argument(self, "compress", default="none")
peers_data = list(memserver.peer_buffer)
self.write(serialize(name="peer_buffer",
output=peers_data,
compress=compress
))
async def get(self, parameter):
await asyncio.to_thread(self.peer_buffer)
class PenaltiesHandler(tornado.web.RequestHandler):
def penalties(self):
compress = PenaltiesHandler.get_argument(self, "compress", default="none")
output = {
"penalties": memserver.penalties
}
self.write(serialize(name="penalties",
output=output,
compress=compress
))
async def get(self, parameter):
await asyncio.to_thread(self.penalties)
class UnreachableHandler(tornado.web.RequestHandler):
def unreachable(self):
compress = PeerPoolHandler.get_argument(self, "compress", default="none")
unreachable_data = memserver.unreachable
self.write(serialize(name="unreachable",
output=unreachable_data,
compress=compress
))
async def get(self, parameter):
await asyncio.to_thread(self.unreachable)
class BlockProducerPoolHandler(tornado.web.RequestHandler):
def block_producers(self):
compress = BlockProducerPoolHandler.get_argument(self, "compress", default="none")
producer_data = list(memserver.block_producers)
self.write(serialize(name="block_producers",
output=producer_data,
compress=compress))
async def get(self, parameter):
await asyncio.to_thread(self.block_producers)
class BlockProducersHashPoolHandler(tornado.web.RequestHandler):
def block_producers_hash_pool(self):
compress = BlockProducersHashPoolHandler.get_argument(self, "compress", default="none")
output = {
"block_producers_hash_pool": consensus.block_producers_hash_pool,
"majority_block_producers_hash_pool": consensus.majority_block_producers_hash,
}
self.write(serialize(name="block_producers_hash_pool",
output=output,
compress=compress))
async def get(self, parameter):
await asyncio.to_thread(self.block_producers_hash_pool)
class TransactionHashPoolHandler(tornado.web.RequestHandler):
def transaction_hash_pool(self):
compress = TransactionHashPoolHandler.get_argument(self, "compress", default="none")
output = {
"transactions_hash_pool": consensus.transaction_hash_pool,
"majority_transactions_hash_pool": consensus.majority_transaction_pool_hash,
}
self.write(serialize(name="transactions_hash_pool",
output=output,
compress=compress))
async def get(self, parameter):
await asyncio.to_thread(self.transaction_hash_pool)
class BlockHashPoolHandler(tornado.web.RequestHandler):
def block_hash_pool(self):
compress = BlockHashPoolHandler.get_argument(self, "compress", default="none")
output = {
"block_opinions": consensus.block_hash_pool,
"majority_block_opinion": consensus.majority_block_hash,
}
self.write(serialize(name="block_hash_pool",
output=output,
compress=compress))
async def get(self, parameter):
await asyncio.to_thread(self.block_hash_pool)
class FeeHandler(tornado.web.RequestHandler):
def fee(self):
self.write({"fee": fee_over_blocks(logger=logger) + 1})
async def get(self):
await asyncio.to_thread(self.fee)
class StatusPoolHandler(tornado.web.RequestHandler):
def status_pool(self):
compress = StatusPoolHandler.get_argument(self, "compress", default="none")
status_pool_data = consensus.status_pool
self.write(serialize(name="status_pool",
output=status_pool_data,
compress=compress))
async def get(self, parameter):
await asyncio.to_thread(self.status_pool)
class SubmitTransactionHandler(tornado.web.RequestHandler):
def submit_transaction(self):
try:
transaction_raw = SubmitTransactionHandler.get_argument(self, "data")
transaction = json.loads(transaction_raw)
output = memserver.merge_transaction(transaction, user_origin=True)
self.write(output)
if not output["result"]:
self.set_status(403)
except Exception as e:
self.set_status(403)
self.write(f"Error: {e}")
async def get(self, parameter):
await asyncio.to_thread(self.submit_transaction)
class HealthHandler(tornado.web.RequestHandler):
def health(self):
compress = LogHandler.get_argument(self, "compress", default="none")
health = summary.summarize(muppy.get_objects())
if compress == "msgpack":
output = msgpack.packb(health)
else:
output = serialize(name="health",
output=health,
compress=compress)
self.write(output)
async def get(self, parameter):
await asyncio.to_thread(self.health)
class LogHandler(tornado.web.RequestHandler):
def log(self):
compress = LogHandler.get_argument(self, "compress", default="none")
with open(f"{get_home()}/logs/log.log") as logfile:
lines = logfile.readlines()
for line in lines:
if compress == "msgpack":
output = msgpack.packb(line)
else:
output = line
self.write(output)
self.write("<br>")
async def get(self, parameter):
await asyncio.to_thread(self.log)
class ForceSyncHandler(tornado.web.RequestHandler):
def force_sync(self):
try:
forced_ip = ForceSyncHandler.get_argument(self, "ip")
server_key = ForceSyncHandler.get_argument(self, "key", default="none")
client_ip = self.request.remote_ip
if server_key == memserver.server_key or client_ip == "127.0.0.1":
if client_ip == "127.0.0.1" or check_ip(client_ip):
memserver.force_sync_ip = forced_ip
memserver.peers = [forced_ip]
self.write(f"Synchronization is now forced only from {forced_ip} until majority consensus is reached")
else:
self.write(f"Failed to force to sync from {forced_ip}")
else:
self.write(f"Wrong server key {server_key}")
except Exception as e:
self.set_status(403)
self.write(f"Error: {e}")
async def get(self, parameter):
await asyncio.to_thread(self.force_sync)
class IpHandler(tornado.web.RequestHandler):
def log(self):
compress = IpHandler.get_argument(self, "compress", default="none")
client_ip = self.request.remote_ip
if compress == "msgpack":
output = msgpack.packb(client_ip)
else:
output = client_ip
self.write(output)
async def get(self, parameter):
await asyncio.to_thread(self.log)
class TerminateHandler(tornado.web.RequestHandler):
def terminate(self):
try:
server_key = TerminateHandler.get_argument(self, "key", default="none")
client_ip = self.request.remote_ip
if client_ip == "127.0.0.1" or server_key == memserver.server_key:
self.write("Termination signal sent, node is shutting down...")
memserver.terminate = True
sys.exit(0)
elif server_key != memserver.server_key:
self.write("Wrong or missing key for a remote node")
except Exception as e:
self.set_status(403)
self.write(f"Error: {e}")
async def get(self, parameter):
await asyncio.to_thread(self.terminate)
class TransactionHandler(tornado.web.RequestHandler):
def transaction(self):
try:
transaction = TransactionHandler.get_argument(self, "txid")
transaction_data = get_transaction(transaction, logger=logger)
compress = TransactionHandler.get_argument(self, "compress", default="none")
if not transaction_data:
transaction_data = "Not found"
self.set_status(403)
self.write(serialize(name="txid",
output=transaction_data,
compress=compress))
except Exception as e:
self.set_status(403)
self.write(f"Error: {e}")
async def get(self, parameter):
await asyncio.to_thread(self.transaction)
class AccountTransactionsHandler(tornado.web.RequestHandler):
"""get transactions from a transaction index batch"""
def account_transactions(self):
try:
address = AccountTransactionsHandler.get_argument(self, "address", default=memserver.address)
min_block = AccountTransactionsHandler.get_argument(self, "min_block", default="0")
compress = AccountTransactionsHandler.get_argument(self, "compress", default="none")
transaction_data = get_transactions_of_account(account=address,
min_block=int(min_block),
logger=logger)
if not transaction_data:
transaction_data = "Not found"
self.set_status(403)
self.write(serialize(name="account_transactions",
output=transaction_data,
compress=compress))
except Exception as e:
self.set_status(403)
self.write(f"Error: {e}")
async def get(self, parameter):
await asyncio.to_thread(self.account_transactions)
class GetBlockHandler(tornado.web.RequestHandler):
def block(self):
output = ""
try:
block = GetBlockHandler.get_argument(self, "hash")
compress = GetBlockHandler.get_argument(self, "compress", default="none")
block_data = get_block(block)
if not block_data:
self.set_status(404)
block_data = "Not found"
output = serialize(name="block_hash",
output=block_data,
compress=compress)
except Exception as e:
self.set_status(403)
self.write(f"Error: {e}")
finally:
self.write(output)
async def get(self, parameter):
await asyncio.to_thread(self.block)
class GetBlockNumberHandler(tornado.web.RequestHandler):
def block(self):
output = ""
try:
number = GetBlockHandler.get_argument(self, "number")
compress = GetBlockHandler.get_argument(self, "compress", default="none")
block_data = get_block_number(number)
if not block_data:
self.set_status(403)
block_data = "Not found"
output = serialize(name="block_number",
output=block_data,
compress=compress)
except Exception as e:
self.set_status(403)
self.write(f"Error: {e}")
finally:
self.write(output)
async def get(self, parameter):
await asyncio.to_thread(self.block)
class GetBlocksBeforeHandler(tornado.web.RequestHandler):
def blocks_before(self):
block_hash = GetBlocksBeforeHandler.get_argument(self, "hash")
count = int(GetBlocksBeforeHandler.get_argument(self, "count", default="1"))
compress = GetBlocksBeforeHandler.get_argument(self, "compress", default="none")
collected_blocks = []
if count > 100:
count = 100
try:
parent = get_block(block_hash)
if parent:
parent_hash=["parent_hash"]
for blocks in range(0, count):
block = get_block(parent_hash)
if not block:
break
elif block:
collected_blocks.append(block)
parent_hash = block["parent_hash"]
collected_blocks.reverse()
else:
logger.debug(f"Parent hash of {block_hash} not found")
self.set_status(404)
except Exception as e:
self.set_status(403)
logger.debug(f"Block collection hit a roadblock: {e}")
if not collected_blocks:
self.set_status(403)
finally:
self.write(serialize(name="blocks_before",
output=collected_blocks,
compress=compress
))
async def get(self, parameter):
await asyncio.to_thread(self.blocks_before)
class GetBlocksAfterHandler(tornado.web.RequestHandler):
def blocks_after(self):
block_hash = GetBlocksAfterHandler.get_argument(self, "hash")
count = int(GetBlocksAfterHandler.get_argument(self, "count", default="1"))
compress = GetBlocksAfterHandler.get_argument(self, "compress", default="none")
collected_blocks = []
if count > 100:
count = 100
try:
child = get_block(block_hash)
if child:
child_hash = child["child_hash"]
for blocks in range(0, count):
block = get_block(child_hash)
if not block:
break
elif block:
collected_blocks.append(block)
child_hash = block["child_hash"]
else:
logger.debug(f"Child hash of {block_hash} not found")
self.set_status(404)
except Exception as e:
logger.debug(f"Block collection hit a roadblock: {e}")
if not collected_blocks:
self.set_status(403)
finally:
self.write(serialize(name="blocks_after",
output=collected_blocks,
compress=compress,
))
async def get(self, parameter):
await asyncio.to_thread(self.blocks_after)
class GetSupplyHandler(tornado.web.RequestHandler):
def get_supply(self):
readable = GetSupplyHandler.get_argument(self, "readable", default="none")
data = fetch_totals()
genesis_acc = get_account(address="ndo18c3afa286439e7ebcb284710dbd4ae42bdaf21b80137b")
data.update({"block_number": memserver.latest_block["block_number"]})
data.update({"reserve": genesis_acc["balance"]})
data.update({"reserve_spent": 1000000000000000000 - genesis_acc["balance"]})
data.update({"circulating": data["reserve_spent"] + data["produced"] - data["burned"] - data["fees"]})
data.update({"total_supply": 1000000000000000000 + data["produced"] - data["burned"] - data["fees"]})
if readable == "true":
data.update({"produced": to_readable_amount(data["produced"])})
data.update({"fees": to_readable_amount(data["fees"])})
data.update({"burned": to_readable_amount(data["burned"])})
data.update({"reserve": to_readable_amount(data["reserve"])})
data.update({"reserve_spent": to_readable_amount(data["reserve_spent"])})
data.update({"circulating": to_readable_amount(data["circulating"])})
data.update({"total_supply": to_readable_amount(data["total_supply"])})
self.write(data)
async def get(self, parameter):
await asyncio.to_thread(self.get_supply)
class GetLatestBlockHandler(tornado.web.RequestHandler):
def latest_block(self):
latest_block_data = memserver.latest_block
compress = GetLatestBlockHandler.get_argument(self, "compress", default="none")
self.write(serialize(name="latest_block",
output=latest_block_data,
compress=compress))
async def get(self, parameter):
await asyncio.to_thread(self.latest_block)
class AccountHandler(tornado.web.RequestHandler):
def account(self):
try:
account = AccountHandler.get_argument(self, "address", default=memserver.address)
compress = AccountHandler.get_argument(self, "compress", default="none")
readable = AccountHandler.get_argument(self, "readable", default="none")
account_data = get_account(account, create_on_error=False)
if account_data:
account_data.update({"penalty": get_penalty(producer_address=account,
block_hash=memserver.latest_block["block_hash"],
block_number=memserver.latest_block["block_number"])})
if readable == "true":
account_data.update({"balance": to_readable_amount(account_data["balance"])})
account_data.update({"produced": to_readable_amount(account_data["produced"])})
account_data.update({"burned": to_readable_amount(account_data["burned"])})
else:
account_data = "Not found"
self.set_status(403)
self.write(serialize(name="address",
output=account_data,
compress=compress))
except Exception as e:
self.set_status(403)
self.write(f"Error: {e}")
async def get(self, parameter):
await asyncio.to_thread(self.account)
class ProducerSetHandler(tornado.web.RequestHandler):
def producer_set(self):
try:
producer_set_hash = ProducerSetHandler.get_argument(self, "hash")
compress = ProducerSetHandler.get_argument(self, "compress", default="none")
producer_data = get_producer_set(producer_set_hash)
if not producer_data:
producer_data = "Not found"
self.set_status(403)
self.write(serialize(name="producer_set",
output=producer_data,
compress=compress))
except Exception as e:
self.set_status(403)
self.write(f"Error: {e}")
async def get(self, parameter):
await asyncio.to_thread(self.producer_set)
class AnnouncePeerHandler(tornado.web.RequestHandler):
def announce(self):
try:
peer_ip = AnnouncePeerHandler.get_argument(self, "ip")
if not check_ip(peer_ip):
self.write("Invalid IP address")
else:
if peer_ip not in memserver.peers and peer_ip not in memserver.unreachable.keys():
status = asyncio.run(get_remote_status(peer_ip, logger=logger))
assert status, f"{peer_ip} unreachable"
address = status["address"]
protocol = status["protocol"]
assert address, "No address detected"
assert protocol >= get_config()["protocol"], f"Protocol of {peer_ip} is too low"
save_peer(ip=peer_ip,
address=address,
port=get_config()["port"],
overwrite=True
)
if peer_ip not in memserver.peer_buffer:
memserver.peer_buffer.append(peer_ip)
message = f"Peer {peer_ip} added to peer buffer"
else:
message = f"{peer_ip} already waiting in peer buffer"
else:
message = f"Peer {peer_ip} is known or invalid"
self.write(message)
except Exception as e:
self.set_status(403)
self.write(f"Error: {e}")
async def get(self, parameter):
await asyncio.to_thread(self.announce)
async def make_app(port):
application = tornado.web.Application(
[
(r"/", HomeHandler),
(r"/get_transactions_of_account(.*)", AccountTransactionsHandler),
(r"/get_transaction(.*)", TransactionHandler),
(r"/get_blocks_after(.*)", GetBlocksAfterHandler),
(r"/get_blocks_before(.*)", GetBlocksBeforeHandler),
(r"/get_block_number(.*)", GetBlockNumberHandler),
(r"/get_block(.*)", GetBlockHandler),
(r"/get_account(.*)", AccountHandler),
(r"/get_producer_set_from_hash(.*)", ProducerSetHandler),
(r"/transaction_pool(.*)", TransactionPoolHandler),
(r"/transaction_hash_pool(.*)", TransactionHashPoolHandler),
(r"/transaction_buffer(.*)", TransactionBufferHandler),
(r"/user_transaction_buffer(.*)", UserTxBufferHandler),
(r"/trust_pool(.*)", TrustPoolHandler),
(r"/get_latest_block(.*)", GetLatestBlockHandler),
(r"/get_supply(.*)", GetSupplyHandler),
(r"/announce_peer(.*)", AnnouncePeerHandler),
(r"/status_pool(.*)", StatusPoolHandler),
(r"/status(.*)", StatusHandler),
(r"/peers(.*)", PeerPoolHandler),
(r"/peer_buffer(.*)", PeerBufferHandler),
(r"/penalties(.*)", PenaltiesHandler),
(r"/unreachable(.*)", UnreachableHandler),
(r"/block_producers_hash_pool(.*)", BlockProducersHashPoolHandler),
(r"/block_producers(.*)", BlockProducerPoolHandler),
(r"/block_hash_pool(.*)", BlockHashPoolHandler),
(r"/get_recommended_fee", FeeHandler),
(r"/terminate(.*)", TerminateHandler),
(r"/health(.*)", HealthHandler),
(r"/submit_transaction(.*)", SubmitTransactionHandler),
(r"/log(.*)", LogHandler),
(r"/whats_my_ip(.*)", IpHandler),
(r"/force_sync(.*)", ForceSyncHandler),
(r"/static/(.*)", tornado.web.StaticFileHandler, {"path": "static"}),
(r'/(favicon.ico)', tornado.web.StaticFileHandler, {"path": "graphics"}),
]
)
application.listen(port)
await asyncio.Event().wait()
"""warning, no intensive operations or locks should be invoked from API interface"""
logging.getLogger('tornado.access').disabled = True
logger = get_logger(logger_name="main_logger")
allow_async()
updated_version = versioner.update_version()
if updated_version:
versioner.set_version(updated_version)
if not os.path.exists(f"{get_home()}/blocks"):
make_folders()
make_genesis(
address="ndo18c3afa286439e7ebcb284710dbd4ae42bdaf21b80137b",
balance=1000000000000000000,
ip="78.102.98.72",
port=9173,
timestamp=1669852800,
logger=logger,
)
if not keyfile_found():
save_keys(generate_keys())
save_peer(ip=get_config()["ip"],
address=load_keys()["address"],
port=get_config()["port"],
peer_trust=10000)
info_path = os.path.normpath(f'{get_home()}/private/keys.dat')
logger.info(f"Key location: {info_path}")
assert not is_port_in_use(get_config()["port"]), "Port already in use, exiting"
signal.signal(signal.SIGINT, handler)
signal.signal(signal.SIGTERM, handler)
memserver = MemServer(logger=logger)
logger.info(f"NADO version {memserver.version} started")
logger.info(f"Your address: {memserver.address}")
logger.info(f"Your IP: {memserver.ip}")
logger.info(f"Promiscuity mode: {memserver.promiscuous}")
logger.info(f"Cascade depth limit: {memserver.cascade_limit}")
consensus = ConsensusClient(memserver=memserver, logger=logger)
consensus.start()
core = CoreClient(memserver=memserver, consensus=consensus, logger=logger)
core.start()
peers = PeerClient(memserver=memserver, consensus=consensus, logger=logger)
peers.start()
messages = MessageClient(memserver=memserver, consensus=consensus, core=core, peers=peers, logger=logger)
messages.start()
logger.info("Starting Request Handler")
asyncio.run(make_app(get_config()["port"]))