PyBitmessage-2021-04-27/src/helper_addressGenerator.py

38 lines
1009 B
Python
Raw Normal View History

2021-01-08 13:10:38 +01:00
"""
Create random address
"""
import time
import defaults
import queues
import state
from bmconfigparser import BMConfigParser
def checkHasNormalAddress():
"""method for checking address"""
2021-01-08 18:28:58 +01:00
for address in BMConfigParser().addresses():
if BMConfigParser().safeGetBoolean(address, 'enabled'):
2021-01-08 13:10:38 +01:00
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
))
2021-01-08 18:28:58 +01:00
start_time = time.time()
2021-01-08 13:10:38 +01:00
while state.shutdown == 0 and not checkHasNormalAddress():
time.sleep(.2)
2021-01-08 18:28:58 +01:00
if int(time.time() - start_time) > 8:
break
2021-01-08 13:10:38 +01:00
return checkHasNormalAddress()