forked from KMDLabs/LabsNotary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstats.py
executable file
·88 lines (73 loc) · 2.47 KB
/
stats.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
#!/usr/bin/env python3
import lib
import sys
import bitcoin
from bitcoin.wallet import P2PKHBitcoinAddress
from bitcoin.core import x
from bitcoin.core import CoreMainParams
class CoinParams(CoreMainParams):
MESSAGE_START = b'\x24\xe9\x27\x64'
DEFAULT_PORT = 7770
BASE58_PREFIXES = {'PUBKEY_ADDR': 60,
'SCRIPT_ADDR': 85,
'SECRET_KEY': 188}
bitcoin.params = CoinParams
CHAIN = input('Please specify chain: ')
ADDRESS = 'RXL3YXG2ceaB6C5hfJcN4fvmLH2C34knhA'
try:
rpc_connection = lib.def_credentials(CHAIN)
except:
print(CHAIN + ' daemon is not running or RPC creds not found')
sys.exit(0)
try:
block_range = int(input('Please specify amount of previous blocks(0 for all): '))
except:
print('Blocks must be whole number. Exiting...')
sys.exit(0)
print('Please wait...')
getinfo_result = rpc_connection.getinfo()
height = getinfo_result['blocks']
getnotarysendmany_result = rpc_connection.getnotarysendmany()
iguana_json = rpc_connection.getiguanajson()
notary_keys = {}
score = {}
for notary in iguana_json['notaries']:
for i in notary:
addr = str(P2PKHBitcoinAddress.from_pubkey(x(notary[i])))
notary_keys[addr] = i
start_height = height - block_range
if block_range == 0 or block_range > height:
start_height = 2
for block in range(start_height,height):
getblock_result = rpc_connection.getblock(str(block), 2)
if len(getblock_result['tx'][0]['vout']) > 1:
vouts = getblock_result['tx'][0]['vout']
for vout in vouts[1:]:
try:
addr = vout['scriptPubKey']['addresses'][0]
if addr in getnotarysendmany_result:
getnotarysendmany_result[addr] += 1
else:
print('BUG in the coinbase tx, please report this.')
except:
pass
for i in notary_keys:
score[notary_keys[i]] = getnotarysendmany_result[i]
notaryname = ''
getinfo_result = rpc_connection.getinfo()
if 'notaryname' in getinfo_result:
notaryname = getinfo_result['notaryname']
total = 0
for i in score:
total += score[i]
average = int((total / len(score)/4))
s = [(k, score[k]) for k in sorted(score, key=score.get, reverse=True)]
for k, v in s:
if k == notaryname:
myscore = str(k) + ' ' + str(v)
print(lib.colorize(myscore, 'green'))
elif v < average:
dropped_NN = str(k) + ' ' + str(v)
print(lib.colorize(dropped_NN, 'red'))
else:
print(k, v)