mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-09-11 21:20:39 +02:00
test: generalise byte_to_base58 utility function to allow more version types
Passing a version in the byte form is allowed now in addition to the integral version type. This will be helpful in the next commit.
This commit is contained in:
@@ -56,10 +56,12 @@ def create_deterministic_address_bcrt1_p2tr_op_true(explicit_internal_key=None):
|
||||
|
||||
|
||||
def byte_to_base58(b, version):
|
||||
result = ''
|
||||
b = bytes([version]) + b # prepend version
|
||||
if isinstance(version, int):
|
||||
version = bytes([version])
|
||||
b = version + b # prepend version
|
||||
b += hash256(b)[:4] # append checksum
|
||||
value = int.from_bytes(b, 'big')
|
||||
result = ''
|
||||
while value > 0:
|
||||
result = b58chars[value % 58] + result
|
||||
value //= 58
|
||||
|
||||
Reference in New Issue
Block a user