Skip to content

Commit

Permalink
Add server.info
Browse files Browse the repository at this point in the history
  • Loading branch information
wizz-wallet-dev committed May 28, 2024
1 parent d221a98 commit 23fc428
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 28 deletions.
15 changes: 8 additions & 7 deletions electrumx/server/session/electrumx_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
20 changes: 12 additions & 8 deletions electrumx/server/session/http_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import json
from decimal import Decimal
from typing import Awaitable

import aiorpcx
from aiohttp import web
Expand All @@ -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):
Expand All @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
24 changes: 12 additions & 12 deletions electrumx/server/session/shared_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 11 additions & 1 deletion electrumx/version.py
Original file line number Diff line number Diff line change
@@ -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,
}

0 comments on commit 23fc428

Please sign in to comment.