From ee84e5c007d236f5087ea2dd1d2abe9eef3450b0 Mon Sep 17 00:00:00 2001 From: thomasv Date: Fri, 26 Oct 2012 10:20:47 +0200 Subject: [PATCH] document public methods of verifier --- lib/verifier.py | 7 ++++++- scripts/merchant.py | 21 ++++++++++++--------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/lib/verifier.py b/lib/verifier.py index fe0e00868..5bbcf00ce 100644 --- a/lib/verifier.py +++ b/lib/verifier.py @@ -25,6 +25,7 @@ from bitcoin import * class WalletVerifier(threading.Thread): + """ Simple Verification Protocol """ def __init__(self, interface, config): threading.Thread.__init__(self) @@ -43,9 +44,13 @@ class WalletVerifier(threading.Thread): self.set_local_height() 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): + """ add a transaction to the list of monitored transactions. """ with self.lock: if tx not in self.transactions: self.transactions.append(tx) diff --git a/scripts/merchant.py b/scripts/merchant.py index 4e8cfd355..dea005c59 100644 --- a/scripts/merchant.py +++ b/scripts/merchant.py @@ -49,7 +49,7 @@ wallet.master_public_key = config.get('electrum','mpk') omg_addresses = {} -def electrum_input_thread(in_queue, i): +def electrum_input_thread(in_queue): while True: addr, amount = in_queue.get(True,1000000000) if addr in omg_addresses: @@ -57,17 +57,17 @@ def electrum_input_thread(in_queue, i): else: print "subscribing to ", addr 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: - r = i.responses.get(True, 100000000000) + r = interface.responses.get(True, 100000000000) method = r.get('method') if method == 'blockchain.address.subscribe': 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': addr = r.get('params')[0] @@ -156,15 +156,18 @@ if __name__ == '__main__': print "using database", db_name conn = mdb.connect(db_instance, db_user, db_password, db_name); - i = Interface({'server':"%s:%d:t"%(electrum_server, 50001)}) - i.start() + interface = Interface({'server':"%s:%d:t"%(electrum_server, 50001)}) + interface.start() + + verifier = WalletVerifier(interface, config) + verifier.start() # this process detects when addresses have paid in_queue = Queue.Queue() out_queue = Queue.Queue() - thread.start_new_thread(electrum_input_thread, (in_queue,i)) - thread.start_new_thread(electrum_output_thread, (out_queue,i)) + thread.start_new_thread(electrum_input_thread, (in_queue,)) + thread.start_new_thread(electrum_output_thread, (out_queue,)) thread.start_new_thread(server_thread, (conn,))