-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
executable file
·35 lines (28 loc) · 846 Bytes
/
example.py
File metadata and controls
executable file
·35 lines (28 loc) · 846 Bytes
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
#!/usr/bin/env python
from blockcache import BlockCache
from web3 import Web3
import time
import sys
w3 = Web3()
if w3.eth.syncing :
sys.stderr.write('Connected, syncing...\n')
while w3.eth.syncing :
time.sleep(1)
sys.stderr.write('Synced!\n')
else :
sys.stderr.write('Connected.\n')
blks = BlockCache(w3, length=10)
blks.ensureHead()
print(blks.head.number)
while True :
start = time.time()
holes, pruned = blks.update()
if holes :
print('HOLES ' + str([(b.hash, b.number) for b in holes]))
print('PRUNED ' + str([(b.hash, b.number) for b in pruned]))
print(len(list(blks.canonical_chain)))
#for x in pruned :
# print(f'{x.hash} is canonical: {blks.is_canonical(x)}')
end = time.time()
print('%r seconds' % str(end - start))
time.sleep(1)