From 16e9319d5fb39ba66188281a7dba8028d3a7f4f6 Mon Sep 17 00:00:00 2001 From: navjot Date: Fri, 8 Jan 2021 17:40:38 +0530 Subject: [PATCH 1/5] add helper_addressGenerator module --- src/helper_addressGenerator.py | 37 ++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/helper_addressGenerator.py diff --git a/src/helper_addressGenerator.py b/src/helper_addressGenerator.py new file mode 100644 index 00000000..e38c83d6 --- /dev/null +++ b/src/helper_addressGenerator.py @@ -0,0 +1,37 @@ +""" +Create random address +""" + +import time + +import defaults +import queues +import state + +from bitmessageqt import account +from bitmessageqt.foldertree import AccountMixin +from bmconfigparser import BMConfigParser + + +def checkHasNormalAddress(): + """method for checking address""" + for address in account.getSortedAccounts(): + acct = account.accountClass(address) + if acct.type == AccountMixin.NORMAL and BMConfigParser().safeGetBoolean(address, 'enabled'): + return address + return False + + +def createAddressIfNeeded(label_text, streamNumberForAddress=1): + """method for creating random address""" + if not checkHasNormalAddress(): + queues.addressGeneratorQueue.put(( + 'createRandomAddress', 4, streamNumberForAddress, + label_text, + 1, "", False, + defaults.networkDefaultProofOfWorkNonceTrialsPerByte, + defaults.networkDefaultPayloadLengthExtraBytes + )) + while state.shutdown == 0 and not checkHasNormalAddress(): + time.sleep(.2) + return checkHasNormalAddress() From 14a4f42fc0ca592304e33cff9baac1cd362a9ce4 Mon Sep 17 00:00:00 2001 From: navjot Date: Fri, 8 Jan 2021 22:58:58 +0530 Subject: [PATCH 2/5] remove qt dependency --- src/helper_addressGenerator.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/helper_addressGenerator.py b/src/helper_addressGenerator.py index e38c83d6..b47512b8 100644 --- a/src/helper_addressGenerator.py +++ b/src/helper_addressGenerator.py @@ -3,21 +3,18 @@ Create random address """ import time - import defaults import queues import state -from bitmessageqt import account -from bitmessageqt.foldertree import AccountMixin from bmconfigparser import BMConfigParser def checkHasNormalAddress(): """method for checking address""" - for address in account.getSortedAccounts(): - acct = account.accountClass(address) - if acct.type == AccountMixin.NORMAL and BMConfigParser().safeGetBoolean(address, 'enabled'): + for address in BMConfigParser().addresses(): + + if BMConfigParser().safeGetBoolean(address, 'enabled'): return address return False @@ -32,6 +29,9 @@ def createAddressIfNeeded(label_text, streamNumberForAddress=1): defaults.networkDefaultProofOfWorkNonceTrialsPerByte, defaults.networkDefaultPayloadLengthExtraBytes )) + start_time = time.time() while state.shutdown == 0 and not checkHasNormalAddress(): time.sleep(.2) + if int(time.time() - start_time) > 8: + break return checkHasNormalAddress() From ac23a397a1f049d64adfc3627cfa16bd632c373d Mon Sep 17 00:00:00 2001 From: navjot Date: Wed, 13 Jan 2021 14:14:26 +0530 Subject: [PATCH 3/5] added timer of less then 10 seconds --- src/helper_addressGenerator.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/helper_addressGenerator.py b/src/helper_addressGenerator.py index b47512b8..39e96fd0 100644 --- a/src/helper_addressGenerator.py +++ b/src/helper_addressGenerator.py @@ -30,8 +30,6 @@ def createAddressIfNeeded(label_text, streamNumberForAddress=1): defaults.networkDefaultPayloadLengthExtraBytes )) start_time = time.time() - while state.shutdown == 0 and not checkHasNormalAddress(): + while int(time.time() - start_time) < 10 and state.shutdown == 0 and not checkHasNormalAddress(): time.sleep(.2) - if int(time.time() - start_time) > 8: - break return checkHasNormalAddress() From 5fb8692eb686f9765d3acc5c9283790d1f25b336 Mon Sep 17 00:00:00 2001 From: navjot Date: Mon, 28 Sep 2020 15:28:40 +0530 Subject: [PATCH 4/5] ignoring ValueError from proofofwork module --- src/proofofwork.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/proofofwork.py b/src/proofofwork.py index e43e0f02..5b915017 100644 --- a/src/proofofwork.py +++ b/src/proofofwork.py @@ -291,7 +291,6 @@ def init(): global bitmsglib, bmpow openclpow.initCL() - if sys.platform == "win32": if ctypes.sizeof(ctypes.c_voidp) == 4: bitmsglib = 'bitmsghash32.dll' @@ -305,8 +304,7 @@ def init(): bmpow.restype = ctypes.c_ulonglong _doCPoW(2**63, "") logger.info("Successfully tested C PoW DLL (stdcall) %s", bitmsglib) - except: - logger.error("C PoW test fail.", exc_info=True) + except ValueError: try: # MinGW bso = ctypes.CDLL(os.path.join(paths.codePath(), "bitmsghash", bitmsglib)) @@ -315,8 +313,8 @@ def init(): bmpow.restype = ctypes.c_ulonglong _doCPoW(2**63, "") logger.info("Successfully tested C PoW DLL (cdecl) %s", bitmsglib) - except: - logger.error("C PoW test fail.", exc_info=True) + except Exception as e: + logger.error("Error: %s", e, exc_info=True) bso = None else: try: From 09439b4a0da1ed66de314d4a45adb418bb3b0fea Mon Sep 17 00:00:00 2001 From: navjot Date: Tue, 12 Jan 2021 23:10:03 +0530 Subject: [PATCH 5/5] added general exception handler --- src/proofofwork.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/proofofwork.py b/src/proofofwork.py index 5b915017..f170aa5f 100644 --- a/src/proofofwork.py +++ b/src/proofofwork.py @@ -316,6 +316,9 @@ def init(): except Exception as e: logger.error("Error: %s", e, exc_info=True) bso = None + except Exception as e: + logger.error("Error: %s", e, exc_info=True) + bso = None else: try: bso = ctypes.CDLL(os.path.join(paths.codePath(), "bitmsghash", bitmsglib))