From 5b0aad508472614bdf75a0e225bcbfd7b9277b58 Mon Sep 17 00:00:00 2001 From: SomberNight Date: Tue, 28 Jun 2022 18:51:21 +0200 Subject: [PATCH] network: rename _send_http_on_proxy and make it part of public API --- electrum/network.py | 14 ++++++++++---- electrum/submarine_swaps.py | 8 ++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/electrum/network.py b/electrum/network.py index b38650468..2c8ecaddb 100644 --- a/electrum/network.py +++ b/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() diff --git a/electrum/submarine_swaps.py b/electrum/submarine_swaps.py index 6e04d0cff..62bf3a4f3 100644 --- a/electrum/submarine_swaps.py +++ b/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)