From: genjix Date: Sun, 25 Mar 2012 18:10:47 +0000 (+0100) Subject: transaction.broadcast X-Git-Url: https://git.novaco.in/?p=electrum-server.git;a=commitdiff_plain;h=4b4f24ca62b26dba7099c627e72f6f88d956f8d4 transaction.broadcast --- diff --git a/modules/python_bitcoin/__init__.py b/modules/python_bitcoin/__init__.py index db104df..259b7f1 100644 --- a/modules/python_bitcoin/__init__.py +++ b/modules/python_bitcoin/__init__.py @@ -164,9 +164,28 @@ class LibbitcoinProcessor(stratum.Processor): elif request["method"] == "server.banner": session.push_response({"id": request["id"], "result": "libbitcoin using python-bitcoin bindings"}) + elif request["method"] == "transaction.broadcast": + self.broadcast_transaction(session, request) # Execute and when ready, you call # session.push_response(response) + def broadcast_transaction(self, session, request): + raw_tx = bitcoin.data_chunk(str(request["params"])) + exporter = bitcoin.satoshi_exporter() + try: + tx = exporter.load_transaction(raw_tx) + except RuntimeError: + response = {"id": request["id"], "result": None, + "error": {"message": + "Exception while parsing the transaction data.", + "code": -4}} + else: + # TODO: actually broadcast - bindings need to be made for that + # method + tx_hash = str(bitcoin.hash_transaction(tx)) + response = {"id": request["id"], "result": tx_hash} + session.push_response(response) + def run(stratum): print "Warning: pre-alpha prototype. Full of bugs." processor = LibbitcoinProcessor()