X-Git-Url: https://git.novaco.in/?p=electrum-server.git;a=blobdiff_plain;f=modules%2Fpython_bitcoin%2F__init__.py;h=6f91305ba4bd0256ea5f7034b7dbc117c096920e;hp=361b7dc4240995950df49c3c4c9a8f8165ae8713;hb=5ee042c213baa4ae8a0f538de64644ae9abe7b36;hpb=a92c552cb893495de62a2c594f3aac34ee643bb0 diff --git a/modules/python_bitcoin/__init__.py b/modules/python_bitcoin/__init__.py index 361b7dc..6f91305 100644 --- a/modules/python_bitcoin/__init__.py +++ b/modules/python_bitcoin/__init__.py @@ -96,8 +96,9 @@ class GhostValue: class NumblocksSubscribe: - def __init__(self, backend): + def __init__(self, backend, processor): self.backend = backend + self.processor = processor self.lock = threading.Lock() self.backend.blockchain.subscribe_reorganize(self.reorganize) self.backend.blockchain.fetch_last_depth(self.set_last_depth) @@ -112,14 +113,15 @@ class NumblocksSubscribe: def reorganize(self, ec, fork_point, arrivals, replaced): latest = fork_point + len(arrivals) self.latest.set(latest) - self.push_response({"method":"numblocks.subscribe", "result": latest}) + self.processor.push_response({"method":"numblocks.subscribe", "result": latest}) self.backend.blockchain.subscribe_reorganize(self.reorganize) class AddressGetHistory: - def __init__(self, backend): + def __init__(self, backend, processor): self.backend = backend + self.processor = processor def get(self, request): address = str(request["params"]) @@ -127,15 +129,16 @@ class AddressGetHistory: bitcoin.bind(self.respond, request, bitcoin._1)) def respond(self, request, result): - self.push_response({"id": request["id"], "method":request["method"], "params":request["params"], "result": result}) + self.processor.push_response({"id": request["id"], "method":request["method"], "params":request["params"], "result": result}) + class LibbitcoinProcessor(Processor): - def __init__(self): - self.backend = Backend() - self.numblocks_subscribe = NumblocksSubscribe(self.backend) - self.address_get_history = AddressGetHistory(self.backend) + def __init__(self, config): Processor.__init__(self) + self.backend = Backend() + self.numblocks_subscribe = NumblocksSubscribe(self.backend, self) + self.address_get_history = AddressGetHistory(self.backend, self) def stop(self): self.backend.stop() @@ -171,13 +174,9 @@ class LibbitcoinProcessor(Processor): response = {"id": request["id"], "method": request["method"], "params":request["params"], "result": tx_hash} self.push_response(response) - - -def run(processor): - #processor = LibbitcoinProcessor() - print "Warning: pre-alpha prototype. Full of bugs." - while not processor.shared.stopped(): - if raw_input() == "quit": - shared.stop() - time.sleep(1) + def run(self): + # this class is a thread. it does nothing in this example. + print "Warning: pre-alpha prototype. Full of bugs." + while not self.shared.stopped(): + time.sleep(1)