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