用于 python-bitcointx 的 Dash 模块
项目描述
这个 Python3 库实现了对 Dash 交易的支持。
它建立在上面,旨在与 python-bitcointx 库一起使用。
要求
- python-bitcointx (版本 >= 1.0.0)
用法:
通过上下文切换到 Dash 参数:
import os
import dashtx
from bitcointx import ChainParams, get_current_chain_params
from bitcointx.wallet import (
CCoinKey, CCoinExtKey, P2WPKHCoinAddress, CCoinAddress
)
with ChainParams('dash'):
k = CCoinExtKey.from_seed(os.urandom(32))
a = P2WPKHCoinAddress.from_pubkey(k.derive_path("m/0h/0h/1").pub)
print('example {} address: {}'.format(get_current_chain_params().NAME, a))
assert CCoinAddress(str(a)) == a
全局切换到 Dash 参数:
from dashtx import DashMainnetParams
from bitcointx import select_chain_params
select_chain_params('dash')
# or, using the chain params class directly
select_chain_params(DashMainnetParams)
不切换链参数:
from dashtx.wallet import P2SHDashAddress
p2sh_addr = P2SHDashAddress('7UHUEqN8EwpHFJjf7U83YAUhEinxYt1MAK')
p2sh_addr = P2SHDashAddress.from_scriptPubKey(p2sh_addr.to_scriptPubKey())
assert str(p2sh_addr) == '7UHUEqN8EwpHFJjf7U83YAUhEinxYt1MAK'
from bitcointx import select_chain_params
from bitcointx.wallet import CCoinAddress
from dashtx.wallet import P2SHDashAddress
select_chain_params('dash')
p2sh_addr = CCoinAddress('7UHUEqN8EwpHFJjf7U83YAUhEinxYt1MAK')
assert isinstance(p2sh_addr, P2SHDashAddress)
这也适用于 ChainParams 上下文管理器。