From: genjix Date: Fri, 6 Apr 2012 18:43:15 +0000 (+0100) Subject: Renamed: modules -> backends X-Git-Url: https://git.novaco.in/?p=electrum-server.git;a=commitdiff_plain;h=2e3252aa7976d1ddd11b333a1c5c5fa4fb3bb338;hp=036b0bc5d32a841a56c304a6da79668944d714a4 Renamed: modules -> backends --- diff --git a/modules/__init__.py b/backends/__init__.py similarity index 100% rename from modules/__init__.py rename to backends/__init__.py diff --git a/modules/abe/__init__.py b/backends/abe/__init__.py similarity index 100% rename from modules/abe/__init__.py rename to backends/abe/__init__.py diff --git a/modules/irc/__init__.py b/backends/irc/__init__.py similarity index 100% rename from modules/irc/__init__.py rename to backends/irc/__init__.py 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) diff --git a/modules/libbitcoin/composed.py b/backends/libbitcoin/composed.py similarity index 100% rename from modules/libbitcoin/composed.py rename to backends/libbitcoin/composed.py diff --git a/server.py b/server.py index f0b2b41..1697150 100755 --- a/server.py +++ b/server.py @@ -29,7 +29,7 @@ def create_config(): config = ConfigParser.ConfigParser() # set some defaults, which will be overwritten by the config file config.add_section('server') - config.set('server','banner', 'Welcome to Electrum!') + config.set('server', 'banner', 'Welcome to Electrum!') config.set('server', 'host', 'localhost') config.set('server', 'native_port', '50000') config.set('server', 'stratum_tcp_port', '50001') @@ -80,14 +80,14 @@ if __name__ == '__main__': from transports.stratum_tcp import TcpServer from transports.native import NativeServer - from modules.irc import ServerProcessor + from backends.irc import ServerProcessor backend_name = config.get('server', 'backend') if backend_name == "libbitcoin": # NativeServer cannot be used with libbitcoin native_port = None config.set('server', 'native_port', '') try: - backend = __import__("modules." + backend_name, + backend = __import__("backends." + backend_name, fromlist=["BlockchainProcessor"]) except ImportError: sys.stderr.write('Unknown backend specified\n')