From 23422dfd7ff1efad0c3e8b245355bd1704a1d5be Mon Sep 17 00:00:00 2001 From: shekhar-cis Date: Mon, 27 Jun 2022 18:12:12 +0530 Subject: [PATCH] Add common methods for backend --- src/backend/address_generator.py | 49 ++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/backend/address_generator.py diff --git a/src/backend/address_generator.py b/src/backend/address_generator.py new file mode 100644 index 00000000..39220e01 --- /dev/null +++ b/src/backend/address_generator.py @@ -0,0 +1,49 @@ +""" +Common methods and functions for kivy and qt. +""" + +import queues +from bmconfigparser import config +from defaults import ( + networkDefaultProofOfWorkNonceTrialsPerByte, + networkDefaultPayloadLengthExtraBytes +) + + +class AddressGenerator(object): + """"Base class for address generation and validation""" + def __init__(self): + pass + + @staticmethod + def random_address_generation( + label, streamNumberForAddress=1, eighteenByteRipe=False, + nonceTrialsPerByte=networkDefaultProofOfWorkNonceTrialsPerByte, + payloadLengthExtraBytes=networkDefaultPayloadLengthExtraBytes + ): + """Start address generation and return whether validation was successful""" + + labels = [config.get(obj, 'label') + for obj in config.addresses()] + if label and label not in labels: + queues.addressGeneratorQueue.put(( + 'createRandomAddress', 4, streamNumberForAddress, label, 1, + "", eighteenByteRipe, nonceTrialsPerByte, + payloadLengthExtraBytes)) + return True + return False + + @staticmethod + def address_validation(instance, label): + """Checking address validation while creating""" + labels = [config.get(obj, 'label') for obj in config.addresses()] + if label in labels: + instance.error = True + instance.helper_text = 'it is already exist you'\ + ' can try this Ex. ( {0}_1, {0}_2 )'.format( + label) + elif label: + instance.error = False + else: + instance.error = True + instance.helper_text = 'This field is required'