cryptnoxpro.lib.cryptos.coins package
Submodules
cryptnoxpro.lib.cryptos.coins.base module
Base classes and shared logic for UTXO-based coin implementations.
- class cryptnoxpro.lib.cryptos.coins.base.BaseCoin(testnet=False, **kwargs)[source]
Bases:
objectBase implementation of crypto coin class All child coins must follow same pattern.
- coin_symbol = None
- display_name = None
- enabled = True
- segwit_supported = None
- magicbyte = None
- script_magicbyte = None
- segwit_hrp = None
- client_kwargs = {'host': None, 'loop': None, 'max_servers': 5, 'port': 50001, 'server_file': 'bitcoin.json', 'servers': (), 'timeout': 15}
- testnet_overrides = {}
- hashcode = 1
- hd_path = 0
- wif_prefix = 128
- wif_script_types = {'p2pkh': 0, 'p2sh': 5, 'p2wpkh': 1, 'p2wpkh-p2sh': 2, 'p2wsh': 6, 'p2wsh-p2sh': 7}
- xprv_headers = {'p2pkh': 76066276, 'p2wpkh': 78791436, 'p2wpkh-p2sh': 77428856, 'p2wsh': 44726937, 'p2wsh-p2sh': 43364357}
- xpub_headers = {'p2pkh': 76067358, 'p2wpkh': 78792518, 'p2wpkh-p2sh': 77429938, 'p2wsh': 44728019, 'p2wsh-p2sh': 43365439}
- electrum_xprv_headers = {'p2pkh': 76066276, 'p2wpkh': 78791436, 'p2wpkh-p2sh': 77428856, 'p2wsh': 44726937, 'p2wsh-p2sh': 43364357}
- electrum_xpub_headers = {'p2pkh': 76067358, 'p2wpkh': 78792518, 'p2wpkh-p2sh': 77429938, 'p2wsh': 44728019, 'p2wsh-p2sh': 43365439}
- is_testnet = False
- address_prefixes = ()
- secondary_hashcode = None
- property rpc_client
Connect to remove server
- pubtop2w(pub)[source]
Convert a public key to a pay to witness public key hash address (P2WPKH, required for segwit)
- hash_to_segwit_addr(hash)[source]
Convert a hash to the new segwit address format outlined in BIP-0173
- privtosegwit(privkey)[source]
Convert a private key to the new segwit address format outlined in BIP01743
- pubtosegwit(pubkey)[source]
Convert a public key to the new segwit address format outlined in BIP01743
- script_to_p2wsh(script)[source]
Convert a script to the new segwit address format outlined in BIP01743
- mk_multsig_address(*args)[source]
- Parameters:
args – List of public keys to used to create multisig and M, the number of signatures required to spend
- Returns:
multisig script
- mktx(*args)[source]
[in0, in1…],[out0, out1…] or in0, in1 … out0 out1 …
Make an unsigned transaction from inputs and outputs. Change is not automatically included so any difference in value between inputs and outputs will be given as a miner’s fee (transactions with too high fees will normally be blocked by the explorers)
For Bitcoin Cash and other hard forks using SIGHASH_FORKID, ins must be a list of dicts with each containing the outpoint and value of the input.
Inputs originally received with segwit must be a dict in the format: {‘outpoint’: “txhash:index”, value:0, “segwit”: True}
For other transactions, inputs can be dicts containing only outpoints or strings in the outpoint format. Outpoint format: txhash:index
- mksend(*args, segwit=False)[source]
[in0, in1…],[out0, out1…] or in0, in1 … out0 out1 …
Make an unsigned transaction from inputs, outputs change address and fee. A change output will be added with change sent to the change address.
For Bitcoin Cash and other hard forks using SIGHASH_FORKID and segwit, ins must be a list of dicts with each containing the outpoint and value of the input.
For other transactions, inputs can be dicts containing only outpoints or strings in the outpoint format. Outpoint format: txhash:index
- preparesignedtx(privkey, to, value, fee=10000, change_addr=None, segwit=False, addr=None)[source]
Prepare a tx with a specific amount from address belonging to private key to another address, returning change to the from address or change address, if set. Requires private key, target address, value and optionally the change address and fee segwit paramater specifies that the inputs belong to a segwit address addr, if provided, will explicity set the from address, overriding the auto-detection of the address from the private key.It will also be used, along with the privkey, to automatically detect a segwit transaction for coins which support segwit, overriding the segwit kw
- send(privkey, to, value, fee=10000, change_addr=None, segwit=False, addr=None)[source]
Send a specific amount from address belonging to private key to another address, returning change to the from address or change address, if set. Requires private key, target address, value and optionally the change address and fee segwit paramater specifies that the inputs belong to a segwit address addr, if provided, will explicity set the from address, overriding the auto-detection of the address from the private key.It will also be used, along with the privkey, to automatically detect a segwit transaction for coins which support segwit, overriding the segwit kw
- preparesignedmultitx(privkey, *args, change_addr=None, segwit=False, addr=None)[source]
Prepare transaction with multiple outputs, with change sent back to from addrss Requires private key, address:value pairs and optionally the change address and fee segwit paramater specifies that the inputs belong to a segwit address addr, if provided, will explicity set the from address, overriding the auto-detection of the address from the private key.It will also be used, along with the privkey to automatically detect a segwit transaction for coins which support segwit, overriding the segwit kw
- sendmultitx(privkey, *args, change_addr=None, segwit=False, addr=None)[source]
Send transaction with multiple outputs, with change sent back to from addrss Requires private key, address:value pairs and optionally the change address and fee segwit paramater specifies that the inputs belong to a segwit address addr, if provided, will explicity set the from address, overriding the auto-detection of the address from the private key.It will also be used, along with the privkey to automatically detect a segwit transaction for coins which support segwit, overriding the segwit kw
- preparetx(frm, to, value, fee, change_addr=None, segwit=False)[source]
Prepare a transaction using from and to addresses, value and a fee, with change sent back to from address
- preparemultitx(frm, *args, change_addr=None, segwit=False)[source]
Prepare transaction with multiple outputs, with change sent to from address Requires from address, to_address:value pairs and fees
cryptnoxpro.lib.cryptos.coins.bitcoin module
Bitcoin-specific constants, scripts, and address helpers.
- class cryptnoxpro.lib.cryptos.coins.bitcoin.Bitcoin(testnet=False, **kwargs)[source]
Bases:
BaseCoin- coin_symbol = 'BTC'
- display_name = 'Bitcoin'
- segwit_supported = True
- magicbyte = 0
- script_magicbyte = 5
- segwit_hrp = 'bc'
- client_kwargs = {'server_file': 'bitcoin.json'}
- testnet_overrides = {'client_kwargs': {'server_file': 'bitcoin_testnet.json'}, 'coin_symbol': 'BTCTEST', 'display_name': 'Bitcoin Testnet', 'hd_path': 1, 'magicbyte': 111, 'script_magicbyte': 196, 'segwit_hrp': 'tb', 'wif_prefix': 239, 'xprv_headers': {'p2pkh': 70615956, 'p2wpkh': 70615956, 'p2wpkh-p2sh': 71978536, 'p2wsh': 44726937, 'p2wsh-p2sh': 43364357}, 'xpub_headers': {'p2pkh': 70617039, 'p2wpkh': 70617039, 'p2wpkh-p2sh': 71979618, 'p2wsh': 44728019, 'p2wsh-p2sh': 43365439}}
Module contents
Re-exports available coin implementations for convenience.
- class cryptnoxpro.lib.cryptos.coins.Bitcoin(testnet=False, **kwargs)[source]
Bases:
BaseCoin- client_kwargs = {'server_file': 'bitcoin.json'}
- coin_symbol = 'BTC'
- display_name = 'Bitcoin'
- magicbyte = 0
- script_magicbyte = 5
- segwit_hrp = 'bc'
- segwit_supported = True
- testnet_overrides = {'client_kwargs': {'server_file': 'bitcoin_testnet.json'}, 'coin_symbol': 'BTCTEST', 'display_name': 'Bitcoin Testnet', 'hd_path': 1, 'magicbyte': 111, 'script_magicbyte': 196, 'segwit_hrp': 'tb', 'wif_prefix': 239, 'xprv_headers': {'p2pkh': 70615956, 'p2wpkh': 70615956, 'p2wpkh-p2sh': 71978536, 'p2wsh': 44726937, 'p2wsh-p2sh': 43364357}, 'xpub_headers': {'p2pkh': 70617039, 'p2wpkh': 70617039, 'p2wpkh-p2sh': 71979618, 'p2wsh': 44728019, 'p2wsh-p2sh': 43365439}}
The cryptnoxpro.lib.cryptos.coins package provides cryptocurrency coin implementations and exports:
- class cryptnoxpro.lib.cryptos.coins.Bitcoin[source]
Bitcoin cryptocurrency implementation. See
cryptnoxpro.lib.cryptos.coins.bitcoin.Bitcoinfor details.