aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorSebastian Falbesoner <sebastian.falbesoner@gmail.com>2022-02-12 02:34:03 +0100
committerSebastian Falbesoner <sebastian.falbesoner@gmail.com>2022-02-14 12:48:43 +0100
commitf11dad22a506e10fbbfbcb6ccf32754bf8e72b72 (patch)
treedea5a25ce4e11e790cb5b3b3c57f88e9f419fcee /test
parent3bb93940703e9d0f4bffda98f4fe22fb1487db34 (diff)
downloadbitcoin-f11dad22a506e10fbbfbcb6ccf32754bf8e72b72.tar.xz
test: refactor: remove unneeded bytes<->hex conversions in `byte_to_base58`
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.
Diffstat (limited to 'test')
-rw-r--r--test/functional/test_framework/address.py12
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