Skip to content
This repository
Browse code

fix for notifications

  • Loading branch information...
commit 0e851a5f62f631cc9b58a19798c8230f4b68f3f5 1 parent 8fc042e
thomasv authored

Showing 2 changed files with 35 additions and 8 deletions. Show diff stats Hide diff stats

  1. +27 3 lib/wallet.py
  2. +8 5 scripts/watch_address
30 lib/wallet.py
@@ -446,7 +446,7 @@ def choose_tx_inputs( self, amount, fixed_fee, from_addr = None ):
446 446 for addr in domain:
447 447 h = self.history.get(addr, [])
448 448 if h == ['*']: continue
449   - for tx_hash, tx_height, in h:
  449 + for tx_hash, tx_height in h:
450 450 tx = self.transactions.get(tx_hash)
451 451 for output in tx.get('outputs'):
452 452 if output.get('address') != addr: continue
@@ -459,7 +459,8 @@ def choose_tx_inputs( self, amount, fixed_fee, from_addr = None ):
459 459
460 460 for addr in self.prioritized_addresses:
461 461 h = self.history.get(addr, [])
462   - for tx_hash, tx_height, in h:
  462 + if h == ['*']: continue
  463 + for tx_hash, tx_height in h:
463 464 for output in tx.get('outputs'):
464 465 if output.get('address') != addr: continue
465 466 key = tx_hash + ":%d" % output.get('index')
@@ -571,7 +572,14 @@ def receive_history_callback(self, addr, hist):
571 572 if hist != ['*']:
572 573 for tx_hash, tx_height in hist:
573 574 if tx_height>0:
  575 + # add it in case it was previously unconfirmed
574 576 self.verifier.add(tx_hash, tx_height)
  577 + # set the height in case it changed
  578 + tx = self.transactions.get(tx_hash)
  579 + if tx:
  580 + if tx.get('height') != tx_height:
  581 + print_error( "changing height for tx", tx_hash )
  582 + tx['height'] = tx_height
575 583
576 584
577 585 def get_tx_history(self):
@@ -892,7 +900,8 @@ def save(self):
892 900
893 901 def set_verifier(self, verifier):
894 902 self.verifier = verifier
895   -
  903 +
  904 + # review transactions (they might not all be in history)
896 905 for tx_hash, tx in self.transactions.items():
897 906 tx_height = tx.get('height')
898 907 if tx_height <1:
@@ -909,6 +918,20 @@ def set_verifier(self, verifier):
909 918 self.set_tx_timestamp(tx_hash, timestamp)
910 919
911 920
  921 + # review existing history
  922 + for addr, hist in self.history.items():
  923 + if hist == ['*']: continue
  924 + for tx_hash, tx_height in hist:
  925 + if tx_height>0:
  926 + # add it in case it was previously unconfirmed
  927 + self.verifier.add(tx_hash, tx_height)
  928 + # set the height in case it changed
  929 + tx = self.transactions.get(tx_hash)
  930 + if tx:
  931 + if tx.get('height') != tx_height:
  932 + print_error( "changing height for tx", tx_hash )
  933 + tx['height'] = tx_height
  934 +
912 935
913 936
914 937 def set_tx_timestamp(self, tx_hash, timestamp):
@@ -1064,6 +1087,7 @@ def run(self):
1064 1087
1065 1088 elif method == 'blockchain.address.get_history':
1066 1089 addr = params[0]
  1090 + print_error("receiving history", addr, result)
1067 1091 if result == ['*']:
1068 1092 assert requested_histories.pop(addr) == '*'
1069 1093 self.wallet.receive_history_callback(addr, result)
13 scripts/watch_address
... ... @@ -1,6 +1,6 @@
1 1 #!/usr/bin/env python
2 2
3   -import sys
  3 +import sys, time
4 4 from electrum import Interface
5 5
6 6 try:
@@ -9,15 +9,18 @@ except:
9 9 print "usage: watch_address <bitcoin_address>"
10 10 sys.exit(1)
11 11
12   -i = Interface({'server':'electrum.novit.ro:50001:t'})
  12 +i = Interface({'server':'ecdsa.org:50001:t'})
13 13 i.start()
14   -i.send([('blockchain.address.subscribe',[addr])])
  14 +i.send([('blockchain.address.subscribe',[addr])] )
  15 +time.sleep(1)
15 16
16 17 while True:
17   - r = i.responses.get(True, 100000000000)
  18 + r = i.get_response()
18 19 method = r.get('method')
19 20 if method == 'blockchain.address.subscribe':
20   - i.send([('blockchain.address.get_history',[addr])])
  21 + #i.send([('blockchain.address.get_history',[addr])])
  22 + print r
  23 +
21 24 elif method == 'blockchain.address.get_history':
22 25 confirmed = unconfirmed = 0
23 26 h = r.get('result')

0 comments on commit 0e851a5

Please sign in to comment.
Something went wrong with that request. Please try again.