Skip to content

Commit 51e1170

Browse files
committed
merge bitcoin#24324: refactor: remove unneeded bytes<->hex conversions in byte_to_base58
1 parent 473ee8e commit 51e1170

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
@@ -25,17 +25,15 @@
2525

2626
def byte_to_base58(b, version):
2727
result = ''
28-
str = b.hex()
29-
str = chr(version).encode('latin-1').hex() + str
30-
checksum = hash256(bytes.fromhex(str)).hex()
31-
str += checksum[:8]
32-
value = int('0x' + str, 0)
28+
b = bytes([version]) + b # prepend version
29+
b += hash256(b)[:4] # append checksum
30+
value = int.from_bytes(b, 'big')
3331
while value > 0:
3432
result = chars[value % 58] + result
3533
value //= 58
36-
while (str[:2] == '00'):
34+
while b[0] == 0:
3735
result = chars[0] + result
38-
str = str[2:]
36+
b = b[1:]
3937
return result
4038

4139

0 commit comments

Comments
 (0)