use WalletVerifier.add() method to register transactions
This commit is contained in:
parent
e20e40829d
commit
ee4de40c37
4
electrum
4
electrum
|
@ -207,8 +207,8 @@ if __name__ == '__main__':
|
||||||
if not found:
|
if not found:
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
verifier = WalletVerifier(interface, config, wallet.get_tx_hashes)
|
verifier = WalletVerifier(interface, config)
|
||||||
wallet.verifier = verifier
|
wallet.set_verifier(verifier)
|
||||||
verifier.start()
|
verifier.start()
|
||||||
|
|
||||||
gui.main(url)
|
gui.main(url)
|
||||||
|
|
|
@ -26,12 +26,12 @@ from bitcoin import *
|
||||||
|
|
||||||
class WalletVerifier(threading.Thread):
|
class WalletVerifier(threading.Thread):
|
||||||
|
|
||||||
def __init__(self, interface, config, get_transactions):
|
def __init__(self, interface, config):
|
||||||
threading.Thread.__init__(self)
|
threading.Thread.__init__(self)
|
||||||
self.daemon = True
|
self.daemon = True
|
||||||
self.config = config
|
self.config = config
|
||||||
self.interface = interface
|
self.interface = interface
|
||||||
self.get_transactions = get_transactions
|
self.transactions = [] # monitored transactions
|
||||||
self.interface.register_channel('verifier')
|
self.interface.register_channel('verifier')
|
||||||
self.verified_tx = config.get('verified_tx',{})
|
self.verified_tx = config.get('verified_tx',{})
|
||||||
self.merkle_roots = config.get('merkle_roots',{}) # hashed by me
|
self.merkle_roots = config.get('merkle_roots',{}) # hashed by me
|
||||||
|
@ -45,6 +45,11 @@ class WalletVerifier(threading.Thread):
|
||||||
def get_confirmations(self, tx):
|
def get_confirmations(self, tx):
|
||||||
return (self.local_height - self.verified_tx[tx] + 1) if tx in self.verified_tx else 0
|
return (self.local_height - self.verified_tx[tx] + 1) if tx in self.verified_tx else 0
|
||||||
|
|
||||||
|
def add(self, tx):
|
||||||
|
with self.lock:
|
||||||
|
if tx not in self.transactions:
|
||||||
|
self.transactions.append(tx)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
requested_merkle = []
|
requested_merkle = []
|
||||||
requested_chunks = []
|
requested_chunks = []
|
||||||
|
@ -75,8 +80,7 @@ class WalletVerifier(threading.Thread):
|
||||||
requested_headers.append(i)
|
requested_headers.append(i)
|
||||||
|
|
||||||
# request missing tx merkle
|
# request missing tx merkle
|
||||||
txlist = self.get_transactions()
|
for tx in self.transactions:
|
||||||
for tx in txlist:
|
|
||||||
if tx not in self.verified_tx:
|
if tx not in self.verified_tx:
|
||||||
if tx not in requested_merkle:
|
if tx not in requested_merkle:
|
||||||
requested_merkle.append(tx)
|
requested_merkle.append(tx)
|
||||||
|
|
|
@ -80,6 +80,9 @@ class Wallet:
|
||||||
self.was_updated = True
|
self.was_updated = True
|
||||||
self.banner = ''
|
self.banner = ''
|
||||||
|
|
||||||
|
# spv
|
||||||
|
self.verifier = None
|
||||||
|
|
||||||
# there is a difference between wallet.up_to_date and interface.is_up_to_date()
|
# there is a difference between wallet.up_to_date and interface.is_up_to_date()
|
||||||
# interface.is_up_to_date() returns true when all requests have been answered and processed
|
# interface.is_up_to_date() returns true when all requests have been answered and processed
|
||||||
# wallet.up_to_date is true when the wallet is synchronized (stronger requirement)
|
# wallet.up_to_date is true when the wallet is synchronized (stronger requirement)
|
||||||
|
@ -498,11 +501,6 @@ class Wallet:
|
||||||
lines = sorted(lines, key=operator.itemgetter("timestamp"))
|
lines = sorted(lines, key=operator.itemgetter("timestamp"))
|
||||||
return lines
|
return lines
|
||||||
|
|
||||||
def get_tx_hashes(self):
|
|
||||||
with self.lock:
|
|
||||||
hashes = self.tx_history.keys()
|
|
||||||
return hashes
|
|
||||||
|
|
||||||
def get_transactions_at_height(self, height):
|
def get_transactions_at_height(self, height):
|
||||||
with self.lock:
|
with self.lock:
|
||||||
values = self.tx_history.values()[:]
|
values = self.tx_history.values()[:]
|
||||||
|
@ -522,6 +520,7 @@ class Wallet:
|
||||||
tx_hash = tx['tx_hash']
|
tx_hash = tx['tx_hash']
|
||||||
line = self.tx_history.get(tx_hash)
|
line = self.tx_history.get(tx_hash)
|
||||||
if not line:
|
if not line:
|
||||||
|
if self.verifier: self.verifier.add(tx_hash)
|
||||||
self.tx_history[tx_hash] = copy.copy(tx)
|
self.tx_history[tx_hash] = copy.copy(tx)
|
||||||
line = self.tx_history.get(tx_hash)
|
line = self.tx_history.get(tx_hash)
|
||||||
else:
|
else:
|
||||||
|
@ -816,6 +815,13 @@ class Wallet:
|
||||||
self.config.set_key(k,v)
|
self.config.set_key(k,v)
|
||||||
self.config.save()
|
self.config.save()
|
||||||
|
|
||||||
|
def set_verifier(self, verifier):
|
||||||
|
self.verifier = verifier
|
||||||
|
with self.lock:
|
||||||
|
for tx in self.tx_history.keys():
|
||||||
|
self.verifier.add(tx)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue