myAiohttpClient: add id counter, and rename to JsonRPCClient
This commit is contained in:
@@ -104,7 +104,7 @@ def request(config: SimpleConfig, endpoint, args=(), timeout=60):
|
|||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
async def request_coroutine():
|
async def request_coroutine():
|
||||||
async with aiohttp.ClientSession(auth=auth) as session:
|
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)
|
return await c.request(endpoint, *args)
|
||||||
try:
|
try:
|
||||||
fut = asyncio.run_coroutine_threadsafe(request_coroutine(), loop)
|
fut = asyncio.run_coroutine_threadsafe(request_coroutine(), loop)
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ from . import constants, util
|
|||||||
from . import keystore
|
from . import keystore
|
||||||
from .util import profiler
|
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 .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 .lnutil import LN_MAX_FUNDING_SAT
|
||||||
from .keystore import BIP32_KeyStore
|
from .keystore import BIP32_KeyStore
|
||||||
from .bitcoin import COIN
|
from .bitcoin import COIN
|
||||||
@@ -533,7 +533,7 @@ class LNWallet(LNWorker):
|
|||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
async with make_aiohttp_session(proxy=self.network.proxy) as session:
|
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('get_ctn')
|
||||||
watchtower.add_method('add_sweep_tx')
|
watchtower.add_method('add_sweep_tx')
|
||||||
for chan in self.channels.values():
|
for chan in self.channels.values():
|
||||||
|
|||||||
@@ -1370,14 +1370,17 @@ class MySocksProxy(aiorpcx.SOCKSProxy):
|
|||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
class myAiohttpClient:
|
class JsonRPCClient:
|
||||||
|
|
||||||
def __init__(self, session, url):
|
def __init__(self, session: aiohttp.ClientSession, url: str):
|
||||||
self.session = session
|
self.session = session
|
||||||
self.url = url
|
self.url = url
|
||||||
|
self._id = 0
|
||||||
|
|
||||||
async def request(self, endpoint, *args):
|
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:
|
async with self.session.post(self.url, data=data) as resp:
|
||||||
if resp.status == 200:
|
if resp.status == 200:
|
||||||
r = await resp.json()
|
r = await resp.json()
|
||||||
|
|||||||
Reference in New Issue
Block a user