diff --git a/electrumx/server/session/electrumx_session.py b/electrumx/server/session/electrumx_session.py index 6b44deec..9fd9080d 100644 --- a/electrumx/server/session/electrumx_session.py +++ b/electrumx/server/session/electrumx_session.py @@ -8,7 +8,7 @@ from electrumx.server.daemon import DaemonError from electrumx.server.session.session_base import SessionBase from electrumx.server.session.util import * -from electrumx.version import electrumx_version, electrumx_version_short +from electrumx.version import electrumx_version, electrumx_version_short, get_server_info class ElectrumX(SessionBase): @@ -124,6 +124,13 @@ async def _notify_inner(self, touched, height_changed): def set_request_handlers(self, protocols): self.protocol_tuple: Tuple[int, ...] = protocols handlers = { + # 'server.banner': self.banner, + 'server.donation_address': self.ss.donation_address, + 'server.features': self.server_features_async, + 'server.info': get_server_info, + # 'server.peers.subscribe': self.peers_subscribe, + # 'server.ping': self.ss.ping, + # 'server.version': self.server_version, 'blockchain.headers.subscribe': self.ss.headers_subscribe, 'blockchain.block.header': self.ss.block_header, 'blockchain.block.headers': self.ss.block_headers, @@ -140,12 +147,6 @@ def set_request_handlers(self, protocols): 'blockchain.transaction.get_merkle': self.ss.transaction_merkle, 'blockchain.transaction.id_from_pos': self.ss.transaction_id_from_pos, 'mempool.get_fee_histogram': self.ss.compact_fee_histogram, - # 'server.banner': self.banner, - 'server.donation_address': self.ss.donation_address, - 'server.features': self.server_features_async, - # 'server.peers.subscribe': self.peers_subscribe, - # 'server.ping': self.ss.ping, - # 'server.version': self.server_version, # The Atomicals era has begun # 'blockchain.atomicals.validate': self.ss.transaction_broadcast_validate, 'blockchain.atomicals.get_ft_balances_scripthash': self.ss.atomicals_get_ft_balances, diff --git a/electrumx/server/session/http_session.py b/electrumx/server/session/http_session.py index b4bb4c13..0ab28c8a 100644 --- a/electrumx/server/session/http_session.py +++ b/electrumx/server/session/http_session.py @@ -2,6 +2,7 @@ import json from decimal import Decimal +from typing import Awaitable import aiorpcx from aiohttp import web @@ -10,7 +11,7 @@ from electrumx.server.http_middleware import success_resp, error_resp from electrumx.server.session.shared_session import SharedSession from electrumx.server.session.util import * -from electrumx.version import electrumx_version +from electrumx.version import electrumx_version, get_server_info class DecimalEncoder(json.JSONEncoder): @@ -30,7 +31,9 @@ async def formatted_request(request, call): else: params = [] try: - result = await call(*params) + result = call(*params) + if isinstance(result, Awaitable): + result = await result return success_resp(result) except Exception as e: return error_resp(500, e) @@ -68,6 +71,13 @@ def __init__(self, session_mgr, db, mempool, peer_mgr, kind): async def add_endpoints(self, router, protocols): handlers = { 'health': self.health, + # 'server.banner': self.ss.banner, + 'server.donation_address': self.ss.donation_address, + 'server.features': self.server_features_async, + 'server.info': get_server_info, + # 'server.peers.subscribe': self.ss.peers_subscribe, + # 'server.ping': self.ss.ping, + # 'server.version': self.server_version, 'blockchain.headers.subscribe': self.ss.headers_subscribe, 'blockchain.block.header': self.ss.block_header, 'blockchain.block.headers': self.ss.block_headers, @@ -84,12 +94,6 @@ async def add_endpoints(self, router, protocols): 'blockchain.transaction.get_merkle': self.ss.transaction_merkle, 'blockchain.transaction.id_from_pos': self.ss.transaction_id_from_pos, 'mempool.get_fee_histogram': self.ss.compact_fee_histogram, - # 'server.banner': self.ss.banner, - 'server.donation_address': self.ss.donation_address, - 'server.features': self.server_features_async, - # 'server.peers.subscribe': self.ss.peers_subscribe, - # 'server.ping': self.ss.ping, - # 'server.version': self.server_version, # The Atomicals era has begun # 'blockchain.atomicals.validate': self.ss.transaction_broadcast_validate, 'blockchain.atomicals.get_ft_balances_scripthash': self.ss.atomicals_get_ft_balances, diff --git a/electrumx/server/session/shared_session.py b/electrumx/server/session/shared_session.py index 9a009d54..50301c5c 100644 --- a/electrumx/server/session/shared_session.py +++ b/electrumx/server/session/shared_session.py @@ -49,6 +49,18 @@ def __init__( ################################################################################################################ + async def donation_address(self): + """Return the donation address as a string, empty if there is none.""" + self.bump_cost(0.1) + return self.env.donation_address + + async def ping(self): + """Serves as a connection keep-alive mechanism and for the client to + confirm the server is still responding. + """ + self.bump_cost(0.1) + return None + async def block_header(self, height, cp_height=0): """Return a raw block header as a hexadecimal string, or as a dictionary with a merkle proof.""" @@ -181,18 +193,6 @@ async def compact_fee_histogram(self): self.bump_cost(1.0) return await self.mempool.compact_fee_histogram() - async def donation_address(self): - """Return the donation address as a string, empty if there is none.""" - self.bump_cost(0.1) - return self.env.donation_address - - async def ping(self): - """Serves as a connection keep-alive mechanism and for the client to - confirm the server is still responding. - """ - self.bump_cost(0.1) - return None - async def atomicals_get_ft_balances(self, scripthash): """Return the FT balances for a scripthash address""" hash_x = scripthash_to_hashX(scripthash) diff --git a/electrumx/version.py b/electrumx/version.py index 77cdc88b..32c13602 100644 --- a/electrumx/version.py +++ b/electrumx/version.py @@ -1,3 +1,13 @@ -__version__ = "1.4.2.0" +__version__ = "1.5.0.0" electrumx_version = f'ElectrumX {__version__}' electrumx_version_short = __version__ + +__aip__ = [1, 3] +aip_implemented = __aip__ + + +def get_server_info(): + return { + 'aip_implemented': aip_implemented, + 'version': electrumx_version_short, + }