verifier: download chunks first for efficiency
[electrum-nvc.git] / scripts / watch_address
1 #!/usr/bin/env python
2
3 import sys
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':'electrum.novit.ro:50001:t'})
13 i.start()
14 i.send([('blockchain.address.subscribe',[addr])])
15
16 while True:
17     r = i.responses.get(True, 100000000000)
18     method = r.get('method') 
19     if method == 'blockchain.address.subscribe':
20         i.send([('blockchain.address.get_history',[addr])])
21     elif method == 'blockchain.address.get_history':
22         confirmed = unconfirmed = 0
23         h = r.get('result')
24         if h is None:
25             continue
26         for item in h:
27             v = item['value']
28             if item['height']:
29                 confirmed += v
30             else:
31                 unconfirmed += v
32         print (confirmed+unconfirmed)/1.e8
33
34