-
Notifications
You must be signed in to change notification settings - Fork 7
/
getHistory.py
62 lines (53 loc) · 1.99 KB
/
getHistory.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
import requests
from decimal import Decimal
import json
import time
from rpcclient import *
import sys
def getHistory(addr, pid=31, offset=0):
bal=getbalance_MP(addr,pid)['result']
info=getinfo()['result']
bal=Decimal(bal['balance'])
print "Generating Address balance report for "+str(addr)
print "Note: This will take a while. Please be patient"
print ""
print "Block "+str(info['blocks'])+" - Date: "+str(time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(time.time())))+" - Balance: "+str(bal)
sys.stdout.flush()
s=time.time() - 10
while True:
while (time.time() - s) < 10:
time.sleep(1)
r=requests.get("https://blockchain.info/rawaddr/"+str(addr)+"?offset="+str(offset))
s=time.time()
if r.status_code != 200:
print r
break
resp=r.json()
for tx in resp['txs']:
for o in tx['out']:
if o['script'][:11]=="6a146f6d6e69" or (o.get("addr")!=None and o['addr']=='1EXoDusjGwvnjZUyKkxZ4UHEf77z6A5S4P'):
rawtx=gettransaction_MP(tx['hash'])['result']
if rawtx['valid'] and rawtx['propertyid']==pid:
if rawtx['sendingaddress']==addr:
amount = Decimal(rawtx['amount'])
else:
amount = -Decimal(rawtx['amount'])
block = rawtx['block']
td = str(time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(rawtx['blocktime'])))
print "Block "+str(block)+" | TxHash: "+str(tx['hash'])+" | Date: "+str(td)+"\t| Balance: "+str(bal)+" ("+str(amount)+" transfered)"
#print ""+str(block)+"|"+str(tx['hash'])+"|"+str(td)+"|"+str(bal)+"|"+str(amount)+""
sys.stdout.flush()
bal += amount
break
offset += len(resp['txs'])
if offset >= resp['n_tx']:
break
if __name__ == "__main__":
if len(sys.argv) != 3:
print "Invalid number of arguments"
print "Call with: python getHistory.py address propertyid"
sys.stdout.flush()
exit(0)
addr=str(sys.argv[1])
pid=int(sys.argv[2])
getHistory(addr,pid)