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: object

Base 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}
__init__(testnet=False, **kwargs)[source]
is_testnet = False
address_prefixes = ()
secondary_hashcode = None
property rpc_client

Connect to remove server

unspent(*addrs)[source]

Get unspent transactions for addresses

history(*addrs, **kwargs)[source]

Get transaction history for addresses

fetchtx(tx)[source]

Fetch a tx from the blockchain

txinputs(tx)[source]

Fetch inputs of a transaction on the blockchain

pushtx(tx)[source]

Push/ Broadcast a transaction to the blockchain

privtopub(privkey)[source]

Get public key from private key

pubtoaddr(pubkey)[source]

Get address from a pubic key

privtoaddr(privkey)[source]

Get address from a private key

electrum_address(masterkey, n, for_change=0)[source]

For old electrum seeds

is_address(addr)[source]

Check if addr is a valid address for this chain

is_p2sh(addr)[source]

Check if addr is a a pay to script address

output_script_to_address(script)[source]

Convert an output script to an address

scripttoaddr(script)[source]

Convert an input public key hash to an address

p2sh_scriptaddr(script)[source]

Convert an output p2sh script to an address

addrtoscript(addr)[source]

Convert an output address to a script

pubtop2w(pub)[source]

Convert a public key to a pay to witness public key hash address (P2WPKH, required for segwit)

privtop2w(priv)[source]

Convert a private key to a pay to witness public key hash address

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

is_segwit(priv, addr)[source]

Check if addr was generated from priv using segwit script

sign(txobj, i, priv)[source]

Sign a transaction input with index using a private key

signall(txobj, priv)[source]

Sign all inputs to a transaction using a private key

multisign(tx, i, script, pk)[source]
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

block_height(txhash)[source]
current_block_height()[source]
block_info(height)[source]
inspect(tx)[source]
merkle_prove(txhash)[source]

Prove that information an explorer returns about a transaction in the blockchain is valid. Only run on a tx with at least 1 confirmation.

encode_privkey(privkey, formt, script_type='p2pkh')[source]
wallet(seed, passphrase=None, **kwargs)[source]
watch_wallet(xpub, **kwargs)[source]
p2wpkh_p2sh_wallet(seed, passphrase=None, **kwargs)[source]
watch_p2wpkh_p2sh_wallet(xpub, **kwargs)[source]
p2wpkh_wallet(seed, passphrase=None, **kwargs)[source]
watch_p2wpkh_wallet(xpub, **kwargs)[source]
electrum_wallet(seed, passphrase=None, **kwargs)[source]
watch_electrum_wallet(xpub, **kwargs)[source]
watch_electrum_p2wpkh_wallet(xpub, **kwargs)[source]

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.Bitcoin for details.