mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 20:12:57 +01:00
merge bitcoin#24324: refactor: remove unneeded bytes<->hex conversions in byte_to_base58
This commit is contained in:
parent
473ee8ef18
commit
51e1170f8f
@ -25,17 +25,15 @@ chars = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
|
|||||||
|
|
||||||
def byte_to_base58(b, version):
|
def byte_to_base58(b, version):
|
||||||
result = ''
|
result = ''
|
||||||
str = b.hex()
|
b = bytes([version]) + b # prepend version
|
||||||
str = chr(version).encode('latin-1').hex() + str
|
b += hash256(b)[:4] # append checksum
|
||||||
checksum = hash256(bytes.fromhex(str)).hex()
|
value = int.from_bytes(b, 'big')
|
||||||
str += checksum[:8]
|
|
||||||
value = int('0x' + str, 0)
|
|
||||||
while value > 0:
|
while value > 0:
|
||||||
result = chars[value % 58] + result
|
result = chars[value % 58] + result
|
||||||
value //= 58
|
value //= 58
|
||||||
while (str[:2] == '00'):
|
while b[0] == 0:
|
||||||
result = chars[0] + result
|
result = chars[0] + result
|
||||||
str = str[2:]
|
b = b[1:]
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user