From edf22cbcff16dbe2726689fa4658d8bf63caa503 Mon Sep 17 00:00:00 2001 From: tryiou <73646876+tryiou@users.noreply.github.com> Date: Fri, 16 Jun 2023 10:58:38 +0200 Subject: [PATCH 1/5] Update plugin-adapter.py --- plugin-adapter.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugin-adapter.py b/plugin-adapter.py index 5007777..05df3f7 100755 --- a/plugin-adapter.py +++ b/plugin-adapter.py @@ -84,7 +84,7 @@ async def connect(self): logger.error(f"[client] ERROR: Connection error to {self.host}:{self.port} - {e.strerror}") self.session = None except Exception as e: - logger.error("[client] ERROR: Error connecting!", e) + logger.error("[client] ERROR: Error connecting!", str(e)) self.session = None async def reconnect_if_closing(self): @@ -105,7 +105,7 @@ async def send_message(self, command, message, timeout=30): "[client] ERROR: Could not connect! Is the Electrum X server running on port " + str(self.port) + "?") return OS_ERROR except Exception as e: - logger.error("[client] ERROR: Error sending request!", e) + logger.error("[client] ERROR: Error sending request!", str(e)) return OTHER_EXCEPTION async def send_batch(self, command, message=None, timeout=30): @@ -126,7 +126,7 @@ async def send_batch(self, command, message=None, timeout=30): "[client] ERROR: Could not connect! Is the Electrum X server running on port " + str(self.port) + "?") return OS_ERROR except Exception as e: - logger.error("[client] ERROR: Error sending request!", e) + logger.error("[client] ERROR: Error sending request!", str(e)) return OTHER_EXCEPTION From 3ae91bde4ed19cadae241fa826dbc7847e3c0151 Mon Sep 17 00:00:00 2001 From: tryiou <73646876+tryiou@users.noreply.github.com> Date: Fri, 16 Jun 2023 11:52:45 +0200 Subject: [PATCH 2/5] Update plugin-adapter.py --- plugin-adapter.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/plugin-adapter.py b/plugin-adapter.py index 05df3f7..cb42181 100755 --- a/plugin-adapter.py +++ b/plugin-adapter.py @@ -173,7 +173,7 @@ def TimestampMillisec64(): def parse_response(response: list): refined_result = [] - logger.info("[server] response: " + str(response)) + logger.debug("[server] response: " + str(response)) try: for utxos in response: for item in utxos: @@ -248,7 +248,8 @@ async def getutxos(params): return None timestart = TimestampMillisec64() - logger.info("[server] " + str(timestart) + " " + "xrmgetutxos: " + currency + " - " + str(addresses)) + logger.info("[server] " + str(timestart) + " " + "xrmgetutxos: " + currency ) + #+ " - " + str(addresses)) if currency not in coins.keys(): logger.warning("[client] ERROR: Attempted to get UTXOs from unsupported coin " + currency) @@ -709,7 +710,8 @@ async def gethistory(params): return json.dumps([]) timestart = TimestampMillisec64() - logger.info("[server] " + str(timestart) + " " + "xrmgethistory: " + currency + " - " + str(addresses)) + logger.info("[server] " + str(timestart) + " " + "xrmgethistory: " + currency ) + # + " - " + str(addresses)) if currency not in coins.keys(): logger.warning("[client] ERROR: Attempted to get history from unsupported coin " + currency) @@ -729,8 +731,8 @@ async def gethistory(params): # DEBUG! PURGE EMPTY LISTS IN LIST? res = [e for e in res if e] - logger.debug("DEBUG MESSAGE: " + str(res)) - logger.info("[server-end gethistory] completion time: {}ms".format(TimestampMillisec64() - timestart)) + logger.debug("xrmgethistory: " + currency +" RES=\n" + str(res)) + #logger.info("[server-end gethistory] completion time: {}ms".format(TimestampMillisec64() - timestart)) return json.dumps(res) From 458700c4b4adc8e17e4729b8e39b520ffd212356 Mon Sep 17 00:00:00 2001 From: tryiou <73646876+tryiou@users.noreply.github.com> Date: Tue, 20 Jun 2023 23:40:32 +0200 Subject: [PATCH 3/5] Update plugin-adapter.py --- plugin-adapter.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugin-adapter.py b/plugin-adapter.py index cb42181..15c66dd 100755 --- a/plugin-adapter.py +++ b/plugin-adapter.py @@ -84,7 +84,7 @@ async def connect(self): logger.error(f"[client] ERROR: Connection error to {self.host}:{self.port} - {e.strerror}") self.session = None except Exception as e: - logger.error("[client] ERROR: Error connecting!", str(e)) + logger.error("[client] ERROR: Error connecting! "+ str(e)) self.session = None async def reconnect_if_closing(self): @@ -105,7 +105,7 @@ async def send_message(self, command, message, timeout=30): "[client] ERROR: Could not connect! Is the Electrum X server running on port " + str(self.port) + "?") return OS_ERROR except Exception as e: - logger.error("[client] ERROR: Error sending request!", str(e)) + logger.error("[client] ERROR: Error sending request! "+ str(e)) return OTHER_EXCEPTION async def send_batch(self, command, message=None, timeout=30): @@ -126,7 +126,7 @@ async def send_batch(self, command, message=None, timeout=30): "[client] ERROR: Could not connect! Is the Electrum X server running on port " + str(self.port) + "?") return OS_ERROR except Exception as e: - logger.error("[client] ERROR: Error sending request!", str(e)) + logger.error("[client] ERROR: Error sending request! "+ str(e)) return OTHER_EXCEPTION From f61a928308546f224c91bc19d901bc1ebd504e3b Mon Sep 17 00:00:00 2001 From: tryiou <73646876+tryiou@users.noreply.github.com> Date: Tue, 20 Jun 2023 23:53:00 +0200 Subject: [PATCH 4/5] Update plugin-adapter.py --- plugin-adapter.py | 131 +--------------------------------------------- 1 file changed, 2 insertions(+), 129 deletions(-) diff --git a/plugin-adapter.py b/plugin-adapter.py index 15c66dd..06f8a3a 100755 --- a/plugin-adapter.py +++ b/plugin-adapter.py @@ -607,92 +607,10 @@ async def get_plugin_fees(currency): if res == OS_ERROR or res == OTHER_EXCEPTION: return None - + return res -# gethistory with caching part, not working in state -async def gethistory_alt(params): - currency = params[0] - try: - addresses = json.loads(params[1]) - except TypeError as e: - addresses = params[1] - except JSONDecodeError as e: - addresses = params[1] - - if type(addresses) == str: - addresses = addresses.split(',') - - if len(addresses) == 0 or type(addresses) != list: - return json.dumps({}) - - timestart = TimestampMillisec64() - logger.debug("[server] " + str(timestart) + " " + "xrmgethistory: " + currency + " - " + str(addresses)) - - if currency not in coins.keys(): - logger.warning("[client] ERROR: Attempted to get history from unsupported coin " + currency) - return json.dumps({}) - - socket = coins[currency]['socket'] - - if type(addresses) == str: - addresses = [addresses] - - hashX_list = [] - if type(addresses) == list: - for addr in addresses: - print(addr) - if addr in hashx_cache: - hashX_list.append(hashx_cache[addr]) - else: - hashx = await socket.send_message("gethashx", [addr], timeout=15) - logger.info(hashx) - hashx_cache[addr] = hashx[0] - hashX_list.append(hashx[0]) - else: - if addresses in hashx_cache: - print(addresses) - hashX_list.append(hashx_cache[addresses]) - else: - print(addresses) - hashx = await socket.send_message("gethashx", [addresses], timeout=15) - logger.info(hashx) - hashx_cache[addresses] = hashx[0] - hashX_list.append(hashx[0]) - - # logger.info(hashX_list) - logging.info("[server]*** gethistory, gethistoryhashx: [" + str(hashX_list) + "]") - res = await socket.send_message("gethistoryhashx", [hashX_list], timeout=15) - logging.info("[server]*** gethistory, res: " + str(res) + " *** " + str(type(res))) - try: - json.loads(res) - valid_data = True - except Exception: - valid_data = False - - retries = 0 - while valid_data is False and retries <= 3: - logging.info("[server] gethistory failed for coin: " + currency) - - retries += 1 - res = await socket.send_message("gethistoryhashx", [hashX_list], timeout=15) - - if res is None or res == OS_ERROR or res == OTHER_EXCEPTION or 'ERROR:' in res: - time.sleep(1) - continue - else: - break - - if res is None or res == OS_ERROR or res == OTHER_EXCEPTION: - return json.dumps({}) - - logger.debug("DEBUG MESSAGE: " + str(res)) - logger.info("[server-end gethistory] completion time: {}ms".format(TimestampMillisec64() - timestart)) - - return json.dumps(res) - - async def gethistory(params): # VERSION WITHOUT CACHING currency = params[0] @@ -732,56 +650,11 @@ async def gethistory(params): res = [e for e in res if e] logger.debug("xrmgethistory: " + currency +" RES=\n" + str(res)) - #logger.info("[server-end gethistory] completion time: {}ms".format(TimestampMillisec64() - timestart)) + logger.info("[server-end gethistory] completion time: {}ms".format(TimestampMillisec64() - timestart)) return json.dumps(res) -# address_get_history(params), no more used, replaced by gethistory -async def address_get_history(params): - currency = params[0] - try: - addresses = json.loads(params[1]) - except TypeError as e: - addresses = params[1] - except JSONDecodeError as e: - addresses = params[1] - - if type(addresses) == str: - addresses = addresses.split(',') - - if len(addresses) == 0 or type(addresses) != list: - return None - - timestart = TimestampMillisec64() - logger.info("[server] " + str(timestart) + " " + "xrmgetaddresshistory: " + currency + " - " + str(addresses)) - - if currency not in coins.keys(): - logger.warning("[client] ERROR: Attempted to get address history from unsupported coin " + currency) - return None - - socket = coins[currency]['socket'] - - try: - res = await socket.send_batch("blockchain.address.get_history", addresses, timeout=60) - except Exception: - logging.exception("Exception occured while obtaining history") - - return [] - - if res is None or res == OS_ERROR or res == OTHER_EXCEPTION: - logging.info("[server] getaddresshistory failed for coin: " + currency) - - return [] - - if len(res) == 1: - res = res[0] - - logger.debug("DEBUG MESSAGE: " + str(res)) - logger.info("[server-end getaddresshistory] completion time: {}ms".format(TimestampMillisec64() - timestart)) - - return json.dumps(res) - async def switchcase(requestjson): switcher = { 'getutxos': getutxos(requestjson['params']), From 7454498a48259b91528b946981dfae0e7e7b21ee Mon Sep 17 00:00:00 2001 From: tryiou <73646876+tryiou@users.noreply.github.com> Date: Tue, 20 Jun 2023 23:55:03 +0200 Subject: [PATCH 5/5] Update plugin-adapter.py --- plugin-adapter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-adapter.py b/plugin-adapter.py index 06f8a3a..4eb878b 100755 --- a/plugin-adapter.py +++ b/plugin-adapter.py @@ -649,7 +649,7 @@ async def gethistory(params): # DEBUG! PURGE EMPTY LISTS IN LIST? res = [e for e in res if e] - logger.debug("xrmgethistory: " + currency +" RES=\n" + str(res)) + logger.debug("DEBUG MESSAGE: " + str(res)) logger.info("[server-end gethistory] completion time: {}ms".format(TimestampMillisec64() - timestart)) return json.dumps(res)