mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-23 17:47:31 +00:00
document public methods of verifier
This commit is contained in:
parent
ee4de40c37
commit
ee84e5c007
2 changed files with 18 additions and 10 deletions
|
@ -25,6 +25,7 @@ from bitcoin import *
|
||||||
|
|
||||||
|
|
||||||
class WalletVerifier(threading.Thread):
|
class WalletVerifier(threading.Thread):
|
||||||
|
""" Simple Verification Protocol """
|
||||||
|
|
||||||
def __init__(self, interface, config):
|
def __init__(self, interface, config):
|
||||||
threading.Thread.__init__(self)
|
threading.Thread.__init__(self)
|
||||||
|
@ -43,9 +44,13 @@ class WalletVerifier(threading.Thread):
|
||||||
self.set_local_height()
|
self.set_local_height()
|
||||||
|
|
||||||
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 the number of confirmations of a monitored transaction. """
|
||||||
|
with self.lock:
|
||||||
|
assert tx in self.transactions
|
||||||
|
return (self.local_height - self.verified_tx[tx] + 1) if tx in self.verified_tx else 0
|
||||||
|
|
||||||
def add(self, tx):
|
def add(self, tx):
|
||||||
|
""" add a transaction to the list of monitored transactions. """
|
||||||
with self.lock:
|
with self.lock:
|
||||||
if tx not in self.transactions:
|
if tx not in self.transactions:
|
||||||
self.transactions.append(tx)
|
self.transactions.append(tx)
|
||||||
|
|
|
@ -49,7 +49,7 @@ wallet.master_public_key = config.get('electrum','mpk')
|
||||||
|
|
||||||
omg_addresses = {}
|
omg_addresses = {}
|
||||||
|
|
||||||
def electrum_input_thread(in_queue, i):
|
def electrum_input_thread(in_queue):
|
||||||
while True:
|
while True:
|
||||||
addr, amount = in_queue.get(True,1000000000)
|
addr, amount = in_queue.get(True,1000000000)
|
||||||
if addr in omg_addresses:
|
if addr in omg_addresses:
|
||||||
|
@ -57,17 +57,17 @@ def electrum_input_thread(in_queue, i):
|
||||||
else:
|
else:
|
||||||
print "subscribing to ", addr
|
print "subscribing to ", addr
|
||||||
omg_addresses[addr] = amount
|
omg_addresses[addr] = amount
|
||||||
i.send([('blockchain.address.subscribe',[addr])])
|
interface.send([('blockchain.address.subscribe',[addr])])
|
||||||
|
|
||||||
|
|
||||||
def electrum_output_thread(out_queue, i):
|
def electrum_output_thread(out_queue):
|
||||||
while True:
|
while True:
|
||||||
r = i.responses.get(True, 100000000000)
|
r = interface.responses.get(True, 100000000000)
|
||||||
method = r.get('method')
|
method = r.get('method')
|
||||||
|
|
||||||
if method == 'blockchain.address.subscribe':
|
if method == 'blockchain.address.subscribe':
|
||||||
addr = r.get('params')[0]
|
addr = r.get('params')[0]
|
||||||
i.send([('blockchain.address.get_history',[addr])])
|
interface.send([('blockchain.address.get_history',[addr])])
|
||||||
|
|
||||||
elif method == 'blockchain.address.get_history':
|
elif method == 'blockchain.address.get_history':
|
||||||
addr = r.get('params')[0]
|
addr = r.get('params')[0]
|
||||||
|
@ -156,15 +156,18 @@ if __name__ == '__main__':
|
||||||
print "using database", db_name
|
print "using database", db_name
|
||||||
conn = mdb.connect(db_instance, db_user, db_password, db_name);
|
conn = mdb.connect(db_instance, db_user, db_password, db_name);
|
||||||
|
|
||||||
i = Interface({'server':"%s:%d:t"%(electrum_server, 50001)})
|
interface = Interface({'server':"%s:%d:t"%(electrum_server, 50001)})
|
||||||
i.start()
|
interface.start()
|
||||||
|
|
||||||
|
verifier = WalletVerifier(interface, config)
|
||||||
|
verifier.start()
|
||||||
|
|
||||||
|
|
||||||
# this process detects when addresses have paid
|
# this process detects when addresses have paid
|
||||||
in_queue = Queue.Queue()
|
in_queue = Queue.Queue()
|
||||||
out_queue = Queue.Queue()
|
out_queue = Queue.Queue()
|
||||||
thread.start_new_thread(electrum_input_thread, (in_queue,i))
|
thread.start_new_thread(electrum_input_thread, (in_queue,))
|
||||||
thread.start_new_thread(electrum_output_thread, (out_queue,i))
|
thread.start_new_thread(electrum_output_thread, (out_queue,))
|
||||||
|
|
||||||
thread.start_new_thread(server_thread, (conn,))
|
thread.start_new_thread(server_thread, (conn,))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue