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