Skip to content

Commit

Permalink
Fix type imply
Browse files Browse the repository at this point in the history
  • Loading branch information
wizz-wallet-dev committed May 28, 2024
1 parent 1720484 commit 6822ee5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
10 changes: 7 additions & 3 deletions electrumx/server/session/http_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import json
from decimal import Decimal
from typing import Any, Awaitable, Callable

import aiorpcx
from aiohttp import web

import electrumx.lib.util as util
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
Expand All @@ -20,7 +20,7 @@ def default(self, o):
return super(DecimalEncoder, self).default(o)


async def formatted_request(request, call: Callable[[Any], Awaitable["web.StreamResponse"]]):
async def formatted_request(request, call):
params: list
if request.method == "GET":
params = json.loads(request.query.get("params", "[]"))
Expand All @@ -29,7 +29,11 @@ async def formatted_request(request, call: Callable[[Any], Awaitable["web.Stream
params = json_data.get("params", [])
else:
params = []
return await call(*params)
try:
result = await call(*params)
return success_resp(result)
except Exception as e:
return error_resp(500, e)


class HttpHandler(object):
Expand Down
9 changes: 6 additions & 3 deletions electrumx/server/session/session_base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Optional, Tuple, Callable, Dict, TYPE_CHECKING
from typing import TYPE_CHECKING, Awaitable, Dict, Optional, Tuple

import electrumx.lib.util as util
import itertools
Expand Down Expand Up @@ -57,7 +57,7 @@ def __init__(
self.session_mgr.add_session(self)
self.recalc_concurrency() # must be called after session_mgr.add_session
self.protocol_tuple: Optional[Tuple[int, ...]] = None
self.request_handlers: Optional[Dict[str, Callable]] = None
self.request_handlers: Optional[Dict[str, Awaitable]] = None
# Use the sharing session to manage handlers.
self.ss = SharedSession(
self.logger,
Expand Down Expand Up @@ -129,7 +129,10 @@ async def handle_request(self, request):

self.session_mgr.method_counts[method] += 1
coro = handler_invocation(handler, request)()
return await coro
if isinstance(coro, Awaitable):
return await coro
else:
return coro


class LocalRPC(SessionBase):
Expand Down
2 changes: 1 addition & 1 deletion electrumx/server/session/shared_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from electrumx.server.session.session_manager import SessionManager


class SharedSession:
class SharedSession(object):
def __init__(
self,
logger: LoggerAdapter,
Expand Down

0 comments on commit 6822ee5

Please sign in to comment.