@@ -84,7 +84,7 @@ async def connect(self):
8484 logger .error (f"[client] ERROR: Connection error to { self .host } :{ self .port } - { e .strerror } " )
8585 self .session = None
8686 except Exception as e :
87- logger .error ("[client] ERROR: Error connecting!" , e )
87+ logger .error ("[client] ERROR: Error connecting! " + str ( e ) )
8888 self .session = None
8989
9090 async def reconnect_if_closing (self ):
@@ -105,7 +105,7 @@ async def send_message(self, command, message, timeout=30):
105105 "[client] ERROR: Could not connect! Is the Electrum X server running on port " + str (self .port ) + "?" )
106106 return OS_ERROR
107107 except Exception as e :
108- logger .error ("[client] ERROR: Error sending request!" , e )
108+ logger .error ("[client] ERROR: Error sending request! " + str ( e ) )
109109 return OTHER_EXCEPTION
110110
111111 async def send_batch (self , command , message = None , timeout = 30 ):
@@ -126,7 +126,7 @@ async def send_batch(self, command, message=None, timeout=30):
126126 "[client] ERROR: Could not connect! Is the Electrum X server running on port " + str (self .port ) + "?" )
127127 return OS_ERROR
128128 except Exception as e :
129- logger .error ("[client] ERROR: Error sending request!" , e )
129+ logger .error ("[client] ERROR: Error sending request! " + str ( e ) )
130130 return OTHER_EXCEPTION
131131
132132
@@ -173,7 +173,7 @@ def TimestampMillisec64():
173173def parse_response (response : list ):
174174 refined_result = []
175175
176- logger .info ("[server] response: " + str (response ))
176+ logger .debug ("[server] response: " + str (response ))
177177 try :
178178 for utxos in response :
179179 for item in utxos :
@@ -248,7 +248,8 @@ async def getutxos(params):
248248 return None
249249
250250 timestart = TimestampMillisec64 ()
251- logger .info ("[server] " + str (timestart ) + " " + "xrmgetutxos: " + currency + " - " + str (addresses ))
251+ logger .info ("[server] " + str (timestart ) + " " + "xrmgetutxos: " + currency )
252+ #+ " - " + str(addresses))
252253
253254 if currency not in coins .keys ():
254255 logger .warning ("[client] ERROR: Attempted to get UTXOs from unsupported coin " + currency )
@@ -606,92 +607,10 @@ async def get_plugin_fees(currency):
606607
607608 if res == OS_ERROR or res == OTHER_EXCEPTION :
608609 return None
609-
610+
610611 return res
611612
612613
613- # gethistory with caching part, not working in state
614- async def gethistory_alt (params ):
615- currency = params [0 ]
616- try :
617- addresses = json .loads (params [1 ])
618- except TypeError as e :
619- addresses = params [1 ]
620- except JSONDecodeError as e :
621- addresses = params [1 ]
622-
623- if type (addresses ) == str :
624- addresses = addresses .split (',' )
625-
626- if len (addresses ) == 0 or type (addresses ) != list :
627- return json .dumps ({})
628-
629- timestart = TimestampMillisec64 ()
630- logger .debug ("[server] " + str (timestart ) + " " + "xrmgethistory: " + currency + " - " + str (addresses ))
631-
632- if currency not in coins .keys ():
633- logger .warning ("[client] ERROR: Attempted to get history from unsupported coin " + currency )
634- return json .dumps ({})
635-
636- socket = coins [currency ]['socket' ]
637-
638- if type (addresses ) == str :
639- addresses = [addresses ]
640-
641- hashX_list = []
642- if type (addresses ) == list :
643- for addr in addresses :
644- print (addr )
645- if addr in hashx_cache :
646- hashX_list .append (hashx_cache [addr ])
647- else :
648- hashx = await socket .send_message ("gethashx" , [addr ], timeout = 15 )
649- logger .info (hashx )
650- hashx_cache [addr ] = hashx [0 ]
651- hashX_list .append (hashx [0 ])
652- else :
653- if addresses in hashx_cache :
654- print (addresses )
655- hashX_list .append (hashx_cache [addresses ])
656- else :
657- print (addresses )
658- hashx = await socket .send_message ("gethashx" , [addresses ], timeout = 15 )
659- logger .info (hashx )
660- hashx_cache [addresses ] = hashx [0 ]
661- hashX_list .append (hashx [0 ])
662-
663- # logger.info(hashX_list)
664- logging .info ("[server]*** gethistory, gethistoryhashx: [" + str (hashX_list ) + "]" )
665- res = await socket .send_message ("gethistoryhashx" , [hashX_list ], timeout = 15 )
666- logging .info ("[server]*** gethistory, res: " + str (res ) + " *** " + str (type (res )))
667- try :
668- json .loads (res )
669- valid_data = True
670- except Exception :
671- valid_data = False
672-
673- retries = 0
674- while valid_data is False and retries <= 3 :
675- logging .info ("[server] gethistory failed for coin: " + currency )
676-
677- retries += 1
678- res = await socket .send_message ("gethistoryhashx" , [hashX_list ], timeout = 15 )
679-
680- if res is None or res == OS_ERROR or res == OTHER_EXCEPTION or 'ERROR:' in res :
681- time .sleep (1 )
682- continue
683- else :
684- break
685-
686- if res is None or res == OS_ERROR or res == OTHER_EXCEPTION :
687- return json .dumps ({})
688-
689- logger .debug ("DEBUG MESSAGE: " + str (res ))
690- logger .info ("[server-end gethistory] completion time: {}ms" .format (TimestampMillisec64 () - timestart ))
691-
692- return json .dumps (res )
693-
694-
695614async def gethistory (params ):
696615 # VERSION WITHOUT CACHING
697616 currency = params [0 ]
@@ -709,7 +628,8 @@ async def gethistory(params):
709628 return json .dumps ([])
710629
711630 timestart = TimestampMillisec64 ()
712- logger .info ("[server] " + str (timestart ) + " " + "xrmgethistory: " + currency + " - " + str (addresses ))
631+ logger .info ("[server] " + str (timestart ) + " " + "xrmgethistory: " + currency )
632+ # + " - " + str(addresses))
713633
714634 if currency not in coins .keys ():
715635 logger .warning ("[client] ERROR: Attempted to get history from unsupported coin " + currency )
@@ -735,51 +655,6 @@ async def gethistory(params):
735655 return json .dumps (res )
736656
737657
738- # address_get_history(params), no more used, replaced by gethistory
739- async def address_get_history (params ):
740- currency = params [0 ]
741- try :
742- addresses = json .loads (params [1 ])
743- except TypeError as e :
744- addresses = params [1 ]
745- except JSONDecodeError as e :
746- addresses = params [1 ]
747-
748- if type (addresses ) == str :
749- addresses = addresses .split (',' )
750-
751- if len (addresses ) == 0 or type (addresses ) != list :
752- return None
753-
754- timestart = TimestampMillisec64 ()
755- logger .info ("[server] " + str (timestart ) + " " + "xrmgetaddresshistory: " + currency + " - " + str (addresses ))
756-
757- if currency not in coins .keys ():
758- logger .warning ("[client] ERROR: Attempted to get address history from unsupported coin " + currency )
759- return None
760-
761- socket = coins [currency ]['socket' ]
762-
763- try :
764- res = await socket .send_batch ("blockchain.address.get_history" , addresses , timeout = 60 )
765- except Exception :
766- logging .exception ("Exception occured while obtaining history" )
767-
768- return []
769-
770- if res is None or res == OS_ERROR or res == OTHER_EXCEPTION :
771- logging .info ("[server] getaddresshistory failed for coin: " + currency )
772-
773- return []
774-
775- if len (res ) == 1 :
776- res = res [0 ]
777-
778- logger .debug ("DEBUG MESSAGE: " + str (res ))
779- logger .info ("[server-end getaddresshistory] completion time: {}ms" .format (TimestampMillisec64 () - timestart ))
780-
781- return json .dumps (res )
782-
783658async def switchcase (requestjson ):
784659 switcher = {
785660 'getutxos' : getutxos (requestjson ['params' ]),
0 commit comments