162c5a6d7ce98cf9c82ee49f16aa43cd11960d8e
[electrum-nvc.git] / watch_address
1 #!/usr/bin/env python
2
3 import interface, sys
4 try:
5     addr = sys.argv[1]
6 except:
7     print "usage: watch_address <bitcoin_address>"
8
9 i = interface.TcpStratumInterface('ecdsa.org', 50001)
10 i.start()
11 i.send([('blockchain.address.subscribe',[addr])])
12
13 while True:
14     r = i.responses.get(True, 100000000000)
15     method = r.get('method') 
16     if method == 'blockchain.address.subscribe':
17         i.send([('blockchain.address.get_history',[addr])])
18     elif method == 'blockchain.address.get_history':
19         confirmed = unconfirmed = 0
20         h = r.get('result')
21         if h is None:
22             continue
23         for item in h:
24             v = item['value']
25             if item['height']:
26                 confirmed += v
27             else:
28                 unconfirmed += v
29         print (confirmed+unconfirmed)/1.e8
30
31