def add_keypairs_from_wallet(self, tx, keypairs, password):
for txin in tx.inputs:
address = txin['address']
+ if not self.is_mine(address):
+ continue
private_keys = self.get_private_key(address, password)
for sec in private_keys:
pubkey = public_key_from_private_key(sec)
# synchronous
h = self.send_tx(tx)
self.tx_event.wait()
- return self.receive_tx(h)
+ return self.receive_tx(h, tx)
def send_tx(self, tx):
# asynchronous
self.tx_result = r.get('result')
self.tx_event.set()
- def receive_tx(self,tx_hash):
+ def receive_tx(self, tx_hash, tx):
out = self.tx_result
if out != tx_hash:
return False, "error: " + out
+ run_hook('receive_tx', tx, self)
return True, out
def start_threads(self, network):
from verifier import TxVerifier
self.network = network
- if self.network:
+ if self.network is not None:
self.verifier = TxVerifier(self.network, self.storage)
self.verifier.start()
self.set_verifier(self.verifier)
self.running = True
while self.is_running():
-
+
if not self.network.is_connected():
- print_error("synchronizer: waiting for interface")
- self.network.interface.connect_event.wait()
+ self.network.wait_until_connected()
- self.run_interface(self.network.interface)
+ self.run_interface()
- def run_interface(self, interface):
+ def run_interface(self):
- print_error("synchronizer: connected to", interface.server)
+ print_error("synchronizer: connected to", self.network.main_server())
requested_tx = []
missing_tx = []
# request missing transactions
for tx_hash, tx_height in missing_tx:
if (tx_hash, tx_height) not in requested_tx:
- interface.send([ ('blockchain.transaction.get',[tx_hash, tx_height]) ], lambda i,r: self.queue.put(r))
+ self.network.send([ ('blockchain.transaction.get',[tx_hash, tx_height]) ], lambda i,r: self.queue.put(r))
requested_tx.append( (tx_hash, tx_height) )
missing_tx = []
# detect if situation has changed
- if interface.is_up_to_date() and self.queue.empty():
+ if self.network.is_up_to_date() and self.queue.empty():
if not self.wallet.is_up_to_date():
self.wallet.set_up_to_date(True)
self.was_updated = True
self.was_updated = True
if self.was_updated:
- self.wallet.network.trigger_callback('updated')
+ self.network.trigger_callback('updated')
self.was_updated = False
# 2. get a response
except Queue.Empty:
continue
- if interface != self.network.interface:
- break
+ # see if it changed
+ #if interface != self.network.interface:
+ # break
if not r:
continue
addr = params[0]
if self.wallet.get_status(self.wallet.get_history(addr)) != result:
if requested_histories.get(addr) is None:
- interface.send([('blockchain.address.get_history', [addr])], lambda i,r:self.queue.put(r))
+ self.network.send([('blockchain.address.get_history', [addr])], lambda i,r:self.queue.put(r))
requested_histories[addr] = result
elif method == 'blockchain.address.get_history':
print_error("Error: Unknown message:" + method + ", " + repr(params) + ", " + repr(result) )
if self.was_updated and not requested_tx:
- self.wallet.network.trigger_callback('updated')
- self.wallet.network.trigger_callback("new_transaction") # Updated gets called too many times from other places as well; if we use that signal we get the notification three times
-
+ self.network.trigger_callback('updated')
+ # Updated gets called too many times from other places as well; if we use that signal we get the notification three times
+ self.network.trigger_callback("new_transaction")
self.was_updated = False