This Python3 library implements support for Litecoin transactions.
It builds on top, and is intended to be used along with python-bitcointx library.
- python-bitcointx (version >= 1.0.0)
With contextual switch to Litecoin parameters:
importosimportlitecointxfrombitcointximportChainParams, get_current_chain_paramsfrombitcointx.walletimport (
CCoinKey, CCoinExtKey, P2WPKHCoinAddress, CCoinAddress
)
withChainParams('litecoin'):
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))
assertCCoinAddress(str(a)) ==aWith global switch to Litecoin parameters:
fromlitecointximportLitecoinMainnetParamsfrombitcointximportselect_chain_paramsselect_chain_params('litecoin')
# or, using the chain params class directlyselect_chain_params(LitecoinMainnetParams)Without the switch of chain parameters:
fromlitecointx.walletimportP2SHLitecoinLegacyAddress, P2SHLitecoinAddresslegacy_adr=P2SHLitecoinLegacyAddress('3F1c6UWAs9RLN2Mbt5bAJue12VhVCorXzs')
canonical_adr=P2SHLitecoinAddress.from_scriptPubKey(legacy_adr.to_scriptPubKey())
assertstr(canonical_adr) =='MMDkQMv8pGGmAXdVyxaW8YtQMCHw7eouma'With special parameter that makes CCoinAddress to decode legacy p2sh addresses:
frombitcointximportselect_chain_paramsfrombitcointx.walletimportCCoinAddressfromlitecointx.walletimportP2SHLitecoinLegacyAddressselect_chain_params('litecoin', allow_legacy_p2sh=True)
legacy_adr=CCoinAddress('3F1c6UWAs9RLN2Mbt5bAJue12VhVCorXzs')
assertisinstance(legacy_adr, P2SHLitecoinLegacyAddress)this also works with ChainParams context manager.