Browse Source

network: rename _send_http_on_proxy and make it part of public API

patch-4
SomberNight 3 years ago
parent
commit
5b0aad5084
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 14
      electrum/network.py
  2. 8
      electrum/submarine_swaps.py

14
electrum/network.py

@ -1291,9 +1291,15 @@ class Network(Logger, NetworkRetryManager[ServerAddr]):
await asyncio.sleep(0.1)
@classmethod
async def _send_http_on_proxy(cls, method: str, url: str, params: str = None,
body: bytes = None, json: dict = None, headers=None,
on_finish=None, timeout=None):
async def async_send_http_on_proxy(
cls, method: str, url: str, *,
params: str = None,
body: bytes = None,
json: dict = None,
headers=None,
on_finish=None,
timeout=None,
):
async def default_on_finish(resp: ClientResponse):
resp.raise_for_status()
return await resp.text()
@ -1326,7 +1332,7 @@ class Network(Logger, NetworkRetryManager[ServerAddr]):
loop = network.asyncio_loop
else:
loop = util.get_asyncio_loop()
coro = asyncio.run_coroutine_threadsafe(cls._send_http_on_proxy(method, url, **kwargs), loop)
coro = asyncio.run_coroutine_threadsafe(cls.async_send_http_on_proxy(method, url, **kwargs), loop)
# note: _send_http_on_proxy has its own timeout, so no timeout here:
return coro.result()

8
electrum/submarine_swaps.py

@ -290,7 +290,7 @@ class SwapManager(Logger):
"invoice": invoice,
"refundPublicKey": pubkey.hex()
}
response = await self.network._send_http_on_proxy(
response = await self.network.async_send_http_on_proxy(
'post',
self.api_url + '/createswap',
json=request_data,
@ -386,7 +386,7 @@ class SwapManager(Logger):
"preimageHash": preimage_hash.hex(),
"claimPublicKey": pubkey.hex()
}
response = await self.network._send_http_on_proxy(
response = await self.network.async_send_http_on_proxy(
'post',
self.api_url + '/createswap',
json=request_data,
@ -470,8 +470,8 @@ class SwapManager(Logger):
self._swaps_by_lockup_address[swap.lockup_address] = swap
async def get_pairs(self) -> None:
assert self.network
response = await self.network._send_http_on_proxy(
from .network import Network
response = await Network.async_send_http_on_proxy(
'get',
self.api_url + '/getpairs',
timeout=30)

Loading…
Cancel
Save