diff options
author | MarcoFalke <falke.marco@gmail.com> | 2022-02-15 09:31:56 +0100 |
---|---|---|
committer | MarcoFalke <falke.marco@gmail.com> | 2022-02-15 09:31:58 +0100 |
commit | 7164e00e1bc4e30e69b38a7ba9c557d4fc5d5f87 (patch) | |
tree | 59f9fed6275bc279892cfc93903da62de646606c /test/functional | |
parent | 566df80624b0a4bd77a2184c0a7ca43c514d80cd (diff) | |
parent | f11dad22a506e10fbbfbcb6ccf32754bf8e72b72 (diff) |
Merge bitcoin/bitcoin#24324: test: refactor: remove unneeded bytes<->hex conversions in `byte_to_base58`
f11dad22a506e10fbbfbcb6ccf32754bf8e72b72 test: refactor: remove unneeded bytes<->hex conversions in `byte_to_base58` (Sebastian Falbesoner)
Pull request description:
It seems like the only reason for using hex strings in this method was to have a convenient way to convert to an integer from the input data interpreted as big-endian. In Python3 we have `int.from_bytes(..., 'big')` for that purpose, hence there is no need for that anymore and we can simply operate on bytes only.
ACKs for top commit:
laanwj:
Code review ACK f11dad22a506e10fbbfbcb6ccf32754bf8e72b72
Tree-SHA512: 9b1563010066ca74d85139c3b9259e9a5bb49e1f141c30b6506a0445afddb2bde7fd421fdd917dc516956e66f93610e2c21d720817640daee8f57f803be76ee4
Diffstat (limited to 'test/functional')
-rw-r--r-- | test/functional/test_framework/address.py | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/test/functional/test_framework/address.py b/test/functional/test_framework/address.py index 013522a5e1..c7fbf679b6 100644 --- a/test/functional/test_framework/address.py +++ b/test/functional/test_framework/address.py @@ -55,17 +55,15 @@ def create_deterministic_address_bcrt1_p2tr_op_true(): def byte_to_base58(b, version): result = '' - str = b.hex() - str = chr(version).encode('latin-1').hex() + str - checksum = hash256(bytes.fromhex(str)).hex() - str += checksum[:8] - value = int('0x' + str, 0) + b = bytes([version]) + b # prepend version + b += hash256(b)[:4] # append checksum + value = int.from_bytes(b, 'big') while value > 0: result = chars[value % 58] + result value //= 58 - while (str[:2] == '00'): + while b[0] == 0: result = chars[0] + result - str = str[2:] + b = b[1:] return result |