X-Git-Url: https://git.novaco.in/?p=electrum-server.git;a=blobdiff_plain;f=backends%2Flibbitcoin%2F__init__.py;fp=modules%2Flibbitcoin%2F__init__.py;h=e28132a673a86e4abbb9f2b6ca0657b7cf2275d7;hp=97440ce794ecd409de1c9db19fff663597cefd5f;hb=2e3252aa7976d1ddd11b333a1c5c5fa4fb3bb338;hpb=036b0bc5d32a841a56c304a6da79668944d714a4 diff --git a/modules/libbitcoin/__init__.py b/backends/libbitcoin/__init__.py similarity index 88% rename from modules/libbitcoin/__init__.py rename to backends/libbitcoin/__init__.py index 97440ce..e28132a 100644 --- a/modules/libbitcoin/__init__.py +++ b/backends/libbitcoin/__init__.py @@ -113,7 +113,8 @@ class NumblocksSubscribe: def reorganize(self, ec, fork_point, arrivals, replaced): latest = fork_point + len(arrivals) self.latest.set(latest) - self.processor.push_response({"method":"numblocks.subscribe", "result": latest}) + response = {"method": "numblocks.subscribe", "result": latest} + self.processor.push_response(response) self.backend.blockchain.subscribe_reorganize(self.reorganize) @@ -129,7 +130,9 @@ class AddressGetHistory: bitcoin.bind(self.respond, request, bitcoin._1)) def respond(self, request, result): - self.processor.push_response({"id": request["id"], "method":request["method"], "params":request["params"], "result": result}) + response = {"id": request["id"], "method": request["method"], + "params": request["params"], "result": result} + self.processor.push_response(response) class BlockchainProcessor(Processor): @@ -144,19 +147,17 @@ class BlockchainProcessor(Processor): self.backend.stop() def process(self, request): - print "New request (lib)", request if request["method"] == "numblocks.subscribe": self.numblocks_subscribe.subscribe(session, request) elif request["method"] == "address.get_history": self.address_get_history.get(request) elif request["method"] == "server.banner": - self.push_response({"id": request["id"], "method": request["method"], "params":request["params"], + self.push_response({"id": request["id"], + "method": request["method"], "params": request["params"], "result": "libbitcoin using python-bitcoin bindings"}) elif request["method"] == "transaction.broadcast": self.broadcast_transaction(request) - # Execute and when ready, you call - # self.push_response(response) def broadcast_transaction(self, request): raw_tx = bitcoin.data_chunk(str(request["params"])) @@ -164,18 +165,19 @@ class BlockchainProcessor(Processor): try: tx = exporter.load_transaction(raw_tx) except RuntimeError: - response = {"id": request["id"], "method": request["method"], "params":request["params"], "result": None, - "error": {"message": - "Exception while parsing the transaction data.", - "code": -4}} + response = {"id": request["id"], "method": request["method"], + "params": request["params"], "result": None, + "error": {"message": + "Exception while parsing the transaction data.", + "code": -4}} else: self.backend.protocol.broadcast_transaction(tx) tx_hash = str(bitcoin.hash_transaction(tx)) - response = {"id": request["id"], "method": request["method"], "params":request["params"], "result": tx_hash} + response = {"id": request["id"], "method": request["method"], + "params": request["params"], "result": tx_hash} self.push_response(response) 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)