Skip to content

Commit 7164e00

Browse files
author
MarcoFalke
committed
Merge bitcoin#24324: test: refactor: remove unneeded bytes<->hex conversions in byte_to_base58
f11dad2 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 f11dad2 Tree-SHA512: 9b1563010066ca74d85139c3b9259e9a5bb49e1f141c30b6506a0445afddb2bde7fd421fdd917dc516956e66f93610e2c21d720817640daee8f57f803be76ee4
2 parents 566df80 + f11dad2 commit 7164e00

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

test/functional/test_framework/address.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,15 @@ def create_deterministic_address_bcrt1_p2tr_op_true():
5555

5656
def byte_to_base58(b, version):
5757
result = ''
58-
str = b.hex()
59-
str = chr(version).encode('latin-1').hex() + str
60-
checksum = hash256(bytes.fromhex(str)).hex()
61-
str += checksum[:8]
62-
value = int('0x' + str, 0)
58+
b = bytes([version]) + b # prepend version
59+
b += hash256(b)[:4] # append checksum
60+
value = int.from_bytes(b, 'big')
6361
while value > 0:
6462
result = chars[value % 58] + result
6563
value //= 58
66-
while (str[:2] == '00'):
64+
while b[0] == 0:
6765
result = chars[0] + result
68-
str = str[2:]
66+
b = b[1:]
6967
return result
7068

7169

0 commit comments

Comments
 (0)