From 9a8c598fa808b1325c184ab4969b68b9f3a7f753 Mon Sep 17 00:00:00 2001 From: Neil Booth Date: Wed, 18 Jan 2017 19:50:26 +0900 Subject: [PATCH] The session needs to handle the version command. --- server/controller.py | 14 +------------- server/session.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/server/controller.py b/server/controller.py index 76aa455..0b6e5f3 100644 --- a/server/controller.py +++ b/server/controller.py @@ -95,7 +95,7 @@ class Controller(util.LoggedClass): 'block.get_header block.get_chunk estimatefee relayfee ' 'transaction.get transaction.get_merkle utxo.get_address'), ('server', - 'banner donation_address peers.subscribe version'), + 'banner donation_address peers.subscribe'), ] self.electrumx_handlers = {'.'.join([prefix, suffix]): getattr(self, suffix.replace('.', '_')) @@ -886,15 +886,3 @@ class Controller(util.LoggedClass): Despite the name this is not currently treated as a subscription.''' return list(self.irc.peers.values()) - - async def version(self, client_name=None, protocol_version=None): - '''Returns the server version as a string. - - client_name: a string identifying the client - protocol_version: the protocol version spoken by the client - ''' - if client_name: - self.client = str(client_name)[:15] - if protocol_version is not None: - self.protocol_version = protocol_version - return VERSION diff --git a/server/session.py b/server/session.py index d646c4f..23cf9dc 100644 --- a/server/session.py +++ b/server/session.py @@ -13,6 +13,7 @@ import traceback from lib.jsonrpc import JSONRPC, RPCError from server.daemon import DaemonError +from server.version import VERSION class Session(JSONRPC): @@ -123,6 +124,7 @@ class ElectrumX(Session): 'blockchain.headers.subscribe': self.headers_subscribe, 'blockchain.numblocks.subscribe': self.numblocks_subscribe, 'blockchain.transaction.broadcast': self.transaction_broadcast, + 'server.version': self.version, } def sub_count(self): @@ -191,6 +193,18 @@ class ElectrumX(Session): self.hashX_subs[hashX] = address return status + async def version(self, client_name=None, protocol_version=None): + '''Returns the server version as a string. + + client_name: a string identifying the client + protocol_version: the protocol version spoken by the client + ''' + if client_name: + self.client = str(client_name)[:15] + if protocol_version is not None: + self.protocol_version = protocol_version + return VERSION + async def transaction_broadcast(self, raw_tx): '''Broadcast a raw transaction to the network.