将十六进制私钥转为WIF格式私钥并使用importprivkey导入bitcoin core

import hashlib
def str_cat(pk0):
    pk1 = '80' + pk0
    pk2 = hashlib.sha256(bytes.fromhex(pk1))
    pk3 = hashlib.sha256(pk2.digest())
    checksum = pk3.digest().hex()[0:8]
    address_hex = pk1 + str(checksum)
    return address_hex

def base58(address_hex):
    alphabet = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
    b58_string = ''
    # Get the number of leading zeros
    leading_zeros = len(address_hex) - len(address_hex.lstrip('0'))
    # Convert hex to decimal
    address_int = int(address_hex, 16)
    # Append digits to the start of string
    while address_int > 0:
        digit = address_int % 58
        digit_char = alphabet[digit]
        b58_string = digit_char + b58_string
        address_int //= 58
    # Add ‘1’ for each 2 leading zeros
    ones = leading_zeros // 2
    for one in range(ones):
        b58_string = '1' + b58_string
    return b58_string

def hex2WIF(pk):
    return base58(str_cat(pk))

bitcoin.conf示例

# reduce memory cost
dbcache=20
blocksonly=1
maxorphantx=10
maxmempool=100
maxsigcachesize=4
maxconnections=4
rpcthreads=1

# boost syncing
par=7
banscore=10
listen=0

标签: none

评论已关闭