Browse Source

myAiohttpClient: add id counter, and rename to JsonRPCClient

bip39-recovery
SomberNight 5 years ago
parent
commit
a32cb7784f
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 2
      electrum/daemon.py
  2. 4
      electrum/lnworker.py
  3. 9
      electrum/util.py

2
electrum/daemon.py

@ -104,7 +104,7 @@ def request(config: SimpleConfig, endpoint, args=(), timeout=60):
loop = asyncio.get_event_loop()
async def request_coroutine():
async with aiohttp.ClientSession(auth=auth) as session:
c = util.myAiohttpClient(session, server_url)
c = util.JsonRPCClient(session, server_url)
return await c.request(endpoint, *args)
try:
fut = asyncio.run_coroutine_threadsafe(request_coroutine(), loop)

4
electrum/lnworker.py

@ -26,7 +26,7 @@ from . import constants, util
from . import keystore
from .util import profiler
from .invoices import PR_TYPE_LN, PR_UNPAID, PR_EXPIRED, PR_PAID, PR_INFLIGHT, PR_FAILED, PR_ROUTING, LNInvoice, LN_EXPIRY_NEVER
from .util import NetworkRetryManager, myAiohttpClient
from .util import NetworkRetryManager, JsonRPCClient
from .lnutil import LN_MAX_FUNDING_SAT
from .keystore import BIP32_KeyStore
from .bitcoin import COIN
@ -533,7 +533,7 @@ class LNWallet(LNWorker):
continue
try:
async with make_aiohttp_session(proxy=self.network.proxy) as session:
watchtower = myAiohttpClient(session, watchtower_url)
watchtower = JsonRPCClient(session, watchtower_url)
watchtower.add_method('get_ctn')
watchtower.add_method('add_sweep_tx')
for chan in self.channels.values():

9
electrum/util.py

@ -1370,14 +1370,17 @@ class MySocksProxy(aiorpcx.SOCKSProxy):
return ret
class myAiohttpClient:
class JsonRPCClient:
def __init__(self, session, url):
def __init__(self, session: aiohttp.ClientSession, url: str):
self.session = session
self.url = url
self._id = 0
async def request(self, endpoint, *args):
data = '{"jsonrpc": "2.0", "id":"0", "method":"%s", "params": %s }' %(endpoint, json.dumps(args))
self._id += 1
data = ('{"jsonrpc": "2.0", "id":"%d", "method": "%s", "params": %s }'
% (self._id, endpoint, json.dumps(args)))
async with self.session.post(self.url, data=data) as resp:
if resp.status == 200:
r = await resp.json()

Loading…
Cancel
Save