forked from neocogent/misc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblockscan.py
46 lines (40 loc) · 1.23 KB
/
blockscan.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
#
# Bitcoin rewards script
#
import os, sys, json, datetime
from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException
from decimal import Decimal
cfg = { 'rpc':'http://user:[email protected]:8332' }
rpc = AuthServiceProxy(cfg['rpc'], timeout=240)
nBlk = 0
blkmax = rpc.getblockcount()
rewards = Decimal(0)
unspent = Decimal(0)
fees = Decimal(0)
while nBlk < blkmax:
blkhash = rpc.getblockhash(nBlk)
blkdata = rpc.getblock(blkhash, 2)
reward = Decimal(0)
fee = Decimal(0)
for tx in blkdata['tx']:
if 'coinbase' in tx['vin'][0]:
for vout in tx['vout']:
reward += vout['value']
utxo = rpc.gettxout(tx['txid'], vout['n'])
if not utxo is None:
unspent += vout['value']
if 'fee' in tx:
fee += tx['fee']
reward = max(0,reward-fee)
rewards += reward
fees += fee
if not reward == Decimal((int(5e9) >> (nBlk // 210000))/1e8):
print('Block:',nBlk,'Reward:',reward, flush=True)
elif nBlk % 50000 == 0:
print('Block:', nBlk, datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"), rewards, unspent, fees, flush=True)
nBlk += 1
print('\nDone', datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
print('\nBlocks:', nBlk)
print('Total rewards:', rewards)
print('Total unspent:', unspent)
print('Total fees:', fees)