From d0c7ef26088596fcb75f728a02abe4d0d83ae262 Mon Sep 17 00:00:00 2001 From: "kuldeep.k@cisinlabs.com" Date: Fri, 20 Aug 2021 20:24:28 +0530 Subject: [PATCH] Added pylint ignore for nested blocks, updted some str to binary & added custom AddressGeneratorException exception Added AddressGeneratorException class doc string --- src/class_addressGenerator.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/class_addressGenerator.py b/src/class_addressGenerator.py index b78225a7..25b0c5df 100644 --- a/src/class_addressGenerator.py +++ b/src/class_addressGenerator.py @@ -20,6 +20,11 @@ from pyelliptic.openssl import OpenSSL from six.moves import configparser, queue +class AddressGeneratorException(Exception): + '''Generic AddressGenerator exception''' + pass + + class addressGenerator(StoppableThread): """A thread for creating addresses""" @@ -40,6 +45,8 @@ class addressGenerator(StoppableThread): """ # pylint: disable=too-many-locals, too-many-branches # pylint: disable=protected-access, too-many-statements + # pylint: disable=too-many-nested-blocks + while state.shutdown == 0: queueValue = queues.addressGeneratorQueue.get() nonceTrialsPerByte = 0 @@ -136,7 +143,7 @@ class addressGenerator(StoppableThread): ripe = RIPEMD160Hash(sha.digest()).digest() if ( ripe[:numberOfNullBytesDemandedOnFrontOfRipeHash] - == '\x00' * numberOfNullBytesDemandedOnFrontOfRipeHash + == b'\x00' * numberOfNullBytesDemandedOnFrontOfRipeHash ): break self.logger.info( @@ -159,13 +166,13 @@ class addressGenerator(StoppableThread): # An excellent way for us to store our keys # is in Wallet Import Format. Let us convert now. # https://en.bitcoin.it/wiki/Wallet_import_format - privSigningKey = '\x80' + potentialPrivSigningKey + privSigningKey = b'\x80' + potentialPrivSigningKey checksum = hashlib.sha256(hashlib.sha256( privSigningKey).digest()).digest()[0:4] privSigningKeyWIF = arithmetic.changebase( privSigningKey + checksum, 256, 58) - privEncryptionKey = '\x80' + potentialPrivEncryptionKey + privEncryptionKey = b'\x80' + potentialPrivEncryptionKey checksum = hashlib.sha256(hashlib.sha256( privEncryptionKey).digest()).digest()[0:4] privEncryptionKeyWIF = arithmetic.changebase( @@ -259,7 +266,7 @@ class addressGenerator(StoppableThread): ripe = RIPEMD160Hash(sha.digest()).digest() if ( ripe[:numberOfNullBytesDemandedOnFrontOfRipeHash] - == '\x00' * numberOfNullBytesDemandedOnFrontOfRipeHash + == b'\x00' * numberOfNullBytesDemandedOnFrontOfRipeHash ): break @@ -296,13 +303,13 @@ class addressGenerator(StoppableThread): # An excellent way for us to store our keys is # in Wallet Import Format. Let us convert now. # https://en.bitcoin.it/wiki/Wallet_import_format - privSigningKey = '\x80' + potentialPrivSigningKey + privSigningKey = b'\x80' + potentialPrivSigningKey checksum = hashlib.sha256(hashlib.sha256( privSigningKey).digest()).digest()[0:4] privSigningKeyWIF = arithmetic.changebase( privSigningKey + checksum, 256, 58) - privEncryptionKey = '\x80' + \ + privEncryptionKey = b'\x80' + \ potentialPrivEncryptionKey checksum = hashlib.sha256(hashlib.sha256( privEncryptionKey).digest()).digest()[0:4] @@ -392,7 +399,7 @@ class addressGenerator(StoppableThread): elif command == 'getDeterministicAddress': queues.apiAddressGeneratorReturnQueue.put(address) else: - raise Exception( + raise AddressGeneratorException( "Error in the addressGenerator thread. Thread was" + " given a command it could not understand: " + command) queues.addressGeneratorQueue.task_done()