-
Notifications
You must be signed in to change notification settings - Fork 3
/
get_all_blocks.py
executable file
·66 lines (49 loc) · 2.04 KB
/
get_all_blocks.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
#!/usr/bin/env python3
import sys
import acctools
from pynanocoin import *
from confirm_req import *
from frontier_request import *
from pull_n_accounts import store_frontiers_handler
def parse_args():
parser = argparse.ArgumentParser()
group = parser.add_mutually_exclusive_group()
group.add_argument('-b', '--beta', action='store_true', default=False,
help='use beta network')
group.add_argument('-t', '--test', action='store_true', default=False,
help='use test network')
parser.add_argument('-p', '--peer',
help='peer to contact for frontiers (if not set, one is randomly selected using DNS)')
parser.add_argument('-H', '--hashes_only', action='store_true', default=False,
help='print only the block hashes')
return parser.parse_args()
def main() -> None:
args = parse_args()
ctx = livectx
if args.beta: ctx = betactx
if args.test: ctx = testctx
if args.peer is not None:
peeraddr, peerport = parse_endpoint(args.peer, default_port=ctx['peerport'])
print('Connecting to [%s]:%s' % (peeraddr, peerport))
else:
peer = get_random_peer(ctx, lambda p: p.score >= 1000 and p.ip.is_ipv4() and p.is_voting)
print('Using peer %s' % peer)
peeraddr = str(peer.ip)
peerport = peer.port
with socket.socket(socket.AF_INET6, socket.SOCK_STREAM) as s:
s.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 0)
s.settimeout(10)
s.connect((peeraddr, peerport))
count = 0
for f in iterate_frontiers_from_stdin():
blocks = get_account_blocks(ctx, s, f.account)
print('ACCOUNT: %s %s' % (hexlify(f.account), acctools.to_account_addr(f.account)))
for b in blocks:
count += 1
if args.hashes_only:
print(hexlify(b.hash()))
else:
print('%s: %s' % (count, b))
print('all blocks printed')
if __name__ == "__main__":
main()