bitcoincash¶
bitcoincash
¶
-
class
bitcoincash.
MainParams
[source]¶ Bases:
bitcoincash.core.CoreMainParams
- DB_MAGIC: Magic bytes used as separator in block storage. Previously named
- MESSAGE_START.
- NETWORK_MAGIC: Prefix for messages in the P2P protocol. Previously named
- MESSAGE_START and had the same value as DB_MAGIC.
-
BASE58_PREFIXES
= {'PUBKEY_ADDR': 0, 'SCRIPT_ADDR': 5, 'SECRET_KEY': 128}¶
-
CASHADDR_PREFIX
= 'bitcoincash'¶
-
DB_MAGIC
= b'\xf9\xbe\xb4\xd9'¶
-
DEFAULT_PORT
= 8333¶
-
DNS_SEEDS
= (('bitcoinunlimited.info', 'btccash-seeder.bitcoinunlimited.info'), ('bitcoinabc.org', 'seed.bitcoinabc.org'), ('bitcoinforks.org', 'seed-abc.bitcoinforks.org'), ('deadalnix.me', 'seed.deadalnix.me'))¶
-
NETWORK_MAGIC
= b'\xe3\xe1\xf3\xe8'¶
-
RPC_PORT
= 8332¶
-
class
bitcoincash.
RegTestParams
[source]¶ Bases:
bitcoincash.core.CoreRegTestParams
- DB_MAGIC: Magic bytes used as separator in block storage. Previously named
- MESSAGE_START.
- NETWORK_MAGIC: Prefix for messages in the P2P protocol. Previously named
- MESSAGE_START and had the same value as DB_MAGIC.
-
BASE58_PREFIXES
= {'PUBKEY_ADDR': 111, 'SCRIPT_ADDR': 196, 'SECRET_KEY': 239}¶
-
CASHADDR_PREFIX
= 'bchreg'¶
-
DB_MAGIC
= b'\xfa\xbf\xb5\xda'¶
-
DEFAULT_PORT
= 18444¶
-
DNS_SEEDS
= ()¶
-
NETWORK_MAGIC
= b'\xda\xb5\xbf\xfa'¶
-
RPC_PORT
= 18443¶
-
bitcoincash.
SelectParams
(name)[source]¶ Select the chain parameters to use
name is one of ‘mainnet’, ‘testnet’, or ‘regtest’
Default chain is ‘mainnet’
-
class
bitcoincash.
TestNetParams
[source]¶ Bases:
bitcoincash.core.CoreTestNetParams
- DB_MAGIC: Magic bytes used as separator in block storage. Previously named
- MESSAGE_START.
- NETWORK_MAGIC: Prefix for messages in the P2P protocol. Previously named
- MESSAGE_START and had the same value as DB_MAGIC.
-
BASE58_PREFIXES
= {'PUBKEY_ADDR': 111, 'SCRIPT_ADDR': 196, 'SECRET_KEY': 239}¶
-
CASHADDR_PREFIX
= 'bchtest'¶
-
DB_MAGIC
= b'\x0b\x11\t\x07'¶
-
DEFAULT_PORT
= 18333¶
-
DNS_SEEDS
= (('bitcoinabc.org', 'testnet-seed.bitcoinabc.org'), ('bitcoinforks.org', 'testnet-seed-abc.bitcoinforks.org'), ('bitcoinunlimited.info', 'testnet-seed.bitcoinunlimited.info'), ('deadalnix.me', 'testnet-seed.deadalnix.me'))¶
-
NETWORK_MAGIC
= b'\xf4\xe5\xf3\xf4'¶
-
RPC_PORT
= 18332¶
base58
¶
Base58 encoding and decoding
-
exception
bitcoincash.base58.
InvalidBase58Error
[source]¶ Bases:
bitcoincash.base58.Base58Error
Raised on generic invalid base58 data, such as bad characters.
Checksum failures raise Base58ChecksumError specifically.
-
exception
bitcoincash.base58.
Base58ChecksumError
[source]¶ Bases:
bitcoincash.base58.Base58Error
Raised on Base58 checksum errors
-
class
bitcoincash.base58.
CBase58Data
(s)[source]¶ Bases:
bytes
Base58-encoded data
Includes a version and checksum.
Initialize from base58-encoded string
Note: subclasses put your initialization routines here, but ignore the argument - that’s handled by __new__(), and .from_bytes() will call __init__() with None in place of the string.
bloom
¶
Bloom filter support
-
bitcoincash.bloom.
MurmurHash3
(x86_32)[source]¶ Used for bloom filters. See http://code.google.com/p/smhasher/source/browse/trunk/MurmurHash3.cpp
-
class
bitcoincash.bloom.
CBloomFilter
(nElements, nFPRate, nTweak, nFlags)[source]¶ Bases:
bitcoincash.core.serialize.Serializable
Create a new bloom filter
The filter will have a given false-positive rate when filled with the given number of elements.
Note that if the given parameters will result in a filter outside the bounds of the protocol limits, the filter created will be as close to the given parameters as possible within the protocol limits. This will apply if nFPRate is very low or nElements is unreasonably high.
nTweak is a constant which is added to the seed value passed to the hash function It should generally always be a random value (and is largely only exposed for unit testing)
nFlags should be one of the UPDATE_* enums (but not _MASK)
-
MAX_BLOOM_FILTER_SIZE
= 36000¶
-
MAX_HASH_FUNCS
= 50¶
-
UPDATE_ALL
= 1¶
-
UPDATE_MASK
= 3¶
-
UPDATE_NONE
= 0¶
-
UPDATE_P2PUBKEY_ONLY
= 2¶
-
cashaddr
¶
-
class
bitcoincash.cashaddr.
CashAddrData
(s)[source]¶ Bases:
bytes
CashAddr-encoded data
Initialize from cashaddr-encoded string
Note: subclasses put your initialization routines here, but ignore the argument - that’s handled by __new__(), and .from_bytes() will call __init__() with None in place of the string.
-
bitcoincash.cashaddr.
decode
(address)[source]¶ Given a cashaddr address, return a triple
(prefix, kind, hash)
messages
¶
-
class
bitcoincash.messages.
msg_version
(protover=60002)[source]¶ Bases:
bitcoincash.messages.MsgSerializable
-
command
= b'version'¶
-
-
class
bitcoincash.messages.
msg_verack
(protover=60002)[source]¶ Bases:
bitcoincash.messages.MsgSerializable
-
command
= b'verack'¶
-
-
class
bitcoincash.messages.
msg_addr
(protover=60002)[source]¶ Bases:
bitcoincash.messages.MsgSerializable
-
command
= b'addr'¶
-
-
class
bitcoincash.messages.
msg_alert
(protover=60002)[source]¶ Bases:
bitcoincash.messages.MsgSerializable
-
command
= b'alert'¶
-
-
class
bitcoincash.messages.
msg_inv
(protover=60002)[source]¶ Bases:
bitcoincash.messages.MsgSerializable
-
command
= b'inv'¶
-
-
class
bitcoincash.messages.
msg_getdata
(protover=60002)[source]¶ Bases:
bitcoincash.messages.MsgSerializable
-
command
= b'getdata'¶
-
-
class
bitcoincash.messages.
msg_getblocks
(protover=60002)[source]¶ Bases:
bitcoincash.messages.MsgSerializable
-
command
= b'getblocks'¶
-
-
class
bitcoincash.messages.
msg_getheaders
(protover=60002)[source]¶ Bases:
bitcoincash.messages.MsgSerializable
-
command
= b'getheaders'¶
-
-
class
bitcoincash.messages.
msg_headers
(protover=60002)[source]¶ Bases:
bitcoincash.messages.MsgSerializable
-
command
= b'headers'¶
-
-
class
bitcoincash.messages.
msg_tx
(protover=60002)[source]¶ Bases:
bitcoincash.messages.MsgSerializable
-
command
= b'tx'¶
-
-
class
bitcoincash.messages.
msg_block
(protover=60002)[source]¶ Bases:
bitcoincash.messages.MsgSerializable
-
command
= b'block'¶
-
-
class
bitcoincash.messages.
msg_getaddr
(protover=60002)[source]¶ Bases:
bitcoincash.messages.MsgSerializable
-
command
= b'getaddr'¶
-
-
class
bitcoincash.messages.
msg_ping
(protover=60002, nonce=0)[source]¶ Bases:
bitcoincash.messages.MsgSerializable
-
command
= b'ping'¶
-
-
class
bitcoincash.messages.
msg_pong
(protover=60002, nonce=0)[source]¶ Bases:
bitcoincash.messages.MsgSerializable
-
command
= b'pong'¶
-
net
¶
-
class
bitcoincash.net.
CInv
[source]¶ Bases:
bitcoincash.core.serialize.Serializable
-
typemap
= {0: 'Error', 1: 'TX', 2: 'Block', 3: 'FilteredBlock'}¶
-
rpc
¶
Bitcoin Core RPC support
By default this uses the standard library json
module. By monkey patching,
a different implementation can be used instead, at your own risk:
>>> import simplejson
>>> import bitcoincash.rpc
>>> bitcoincash.rpc.json = simplejson
(simplejson
is the externally maintained version of the same module and
thus better optimized but perhaps less stable.)
-
exception
bitcoincash.rpc.
JSONRPCError
[source]¶ Bases:
Exception
JSON-RPC protocol error base class
Subclasses of this class also exist for specific types of errors; the set of all subclasses is by no means complete.
-
SUBCLS_BY_CODE
= {-28: <class 'bitcoincash.rpc.InWarmupError'>, -27: <class 'bitcoincash.rpc.VerifyAlreadyInChainError'>, -26: <class 'bitcoincash.rpc.VerifyRejectedError'>, -25: <class 'bitcoincash.rpc.VerifyError'>, -8: <class 'bitcoincash.rpc.InvalidParameterError'>, -5: <class 'bitcoincash.rpc.InvalidAddressOrKeyError'>, -2: <class 'bitcoincash.rpc.ForbiddenBySafeModeError'>}¶
-
-
exception
bitcoincash.rpc.
ForbiddenBySafeModeError
[source]¶ Bases:
bitcoincash.rpc.JSONRPCError
-
RPC_ERROR_CODE
= -2¶
-
-
exception
bitcoincash.rpc.
InvalidAddressOrKeyError
[source]¶ Bases:
bitcoincash.rpc.JSONRPCError
-
RPC_ERROR_CODE
= -5¶
-
-
exception
bitcoincash.rpc.
InvalidParameterError
[source]¶ Bases:
bitcoincash.rpc.JSONRPCError
-
RPC_ERROR_CODE
= -8¶
-
-
exception
bitcoincash.rpc.
VerifyError
[source]¶ Bases:
bitcoincash.rpc.JSONRPCError
-
RPC_ERROR_CODE
= -25¶
-
-
exception
bitcoincash.rpc.
VerifyRejectedError
[source]¶ Bases:
bitcoincash.rpc.JSONRPCError
-
RPC_ERROR_CODE
= -26¶
-
-
exception
bitcoincash.rpc.
VerifyAlreadyInChainError
[source]¶ Bases:
bitcoincash.rpc.JSONRPCError
-
RPC_ERROR_CODE
= -27¶
-
-
exception
bitcoincash.rpc.
InWarmupError
[source]¶ Bases:
bitcoincash.rpc.JSONRPCError
-
RPC_ERROR_CODE
= -28¶
-
-
class
bitcoincash.rpc.
RawProxy
(service_url=None, service_port=None, btc_conf_file=None, timeout=30, **kwargs)[source]¶ Bases:
bitcoincash.rpc.BaseProxy
Low-level proxy to a bitcoin JSON-RPC service
Unlike
Proxy
, no conversion is done besides parsing JSON. As far as Python is concerned, you can call any method;JSONRPCError
will be raised if the server does not recognize it.
-
class
bitcoincash.rpc.
Proxy
(service_url=None, service_port=None, btc_conf_file=None, timeout=30, **kwargs)[source]¶ Bases:
bitcoincash.rpc.BaseProxy
Proxy to a bitcoin RPC service
Unlike
RawProxy
, data is passed asbitcoincash.core
objects or packed bytes, rather than JSON or hex strings. Not all methods are implemented yet; you can usecall
to access missing ones in a forward-compatible way. Assumes Bitcoin Core version >= v0.16.0; older versions mostly work, but there are a few incompatibilities.Create a proxy object
If
service_url
is not specified, the username and password are read out of the filebtc_conf_file
. Ifbtc_conf_file
is not specified,~/.bitcoin/bitcoin.conf
or equivalent is used by default. The default port is set according to the chain parameters in use: mainnet, testnet, or regtest.Usually no arguments to
Proxy()
are needed; the local bitcoind will be used.timeout
- timeout in seconds before the HTTP interface times out-
fundrawtransaction
(tx, include_watching=False)[source]¶ Add inputs to a transaction until it has enough in value to meet its out value.
include_watching - Also select inputs which are watch only
Returns dict:
- {‘tx’: Resulting tx,
- ‘fee’: Fee the resulting transaction pays, ‘changepos’: Position of added change output, or -1,
}
-
generate
(numblocks)[source]¶ DEPRECATED (will be removed in bitcoin-core v0.19)
Mine blocks immediately (before the RPC call returns)
numblocks - How many blocks are generated immediately.
Returns iterable of block hashes generated.
-
generatetoaddress
(numblocks, addr)[source]¶ Mine blocks immediately (before the RPC call returns) and allocate block reward to passed address. Replaces deprecated “generate(self,numblocks)” method.
numblocks - How many blocks are generated immediately. addr - Address to receive block reward (CBitcoinAddress instance)
Returns iterable of block hashes generated.
-
getaccountaddress
(account=None)[source]¶ Return the current Bitcoin address for receiving payments to this account.
-
getbalance
(account='*', minconf=1, include_watchonly=False)[source]¶ Get the balance
account - The selected account. Defaults to “*” for entire wallet. It may be the default account using “”.
minconf - Only include transactions confirmed at least this many times. (default=1)
include_watchonly - Also include balance in watch-only addresses (see ‘importaddress’) (default=False)
-
getblockhash
(height)[source]¶ Return hash of block in best-block-chain at height.
Raises IndexError if height is not valid.
-
getblockheader
(block_hash, verbose=False)[source]¶ Get block header <block_hash>
- verbose - If true a dict is returned with the values returned by
- getblockheader that are not in the block header itself (height, nextblockhash, etc.)
Raises IndexError if block_hash is not valid.
-
getnewaddress
(account=None)[source]¶ Return a new Bitcoin address for receiving payments.
If account is not None, it is added to the address book so payments received with the address will be credited to account.
-
getrawchangeaddress
()[source]¶ Returns a new Bitcoin address, for receiving change.
This is for use with raw transactions, NOT normal use.
-
getrawtransaction
(txid, verbose=False)[source]¶ Return transaction with hash txid
Raises IndexError if transaction not found.
verbose - If true a dict is returned instead with additional information on the transaction.
Note that if all txouts are spent and the transaction index is not enabled the transaction may not be available.
-
getreceivedbyaddress
(addr, minconf=1)[source]¶ Return total amount received by given a (wallet) address
Get the amount received by <address> in transactions with at least [minconf] confirmations.
Works only for addresses in the local wallet; other addresses will always show zero.
addr - The address. (CBitcoinAddress instance)
minconf - Only include transactions confirmed at least this many times. (default=1)
-
gettransaction
(txid)[source]¶ Get detailed information about in-wallet transaction txid
Raises IndexError if transaction not found in the wallet.
FIXME: Returned data types are not yet converted.
-
gettxout
(outpoint, includemempool=True)[source]¶ Return details about an unspent transaction output.
Raises IndexError if outpoint is not found or was spent.
includemempool - Include mempool txouts
-
importaddress
(addr, label='', rescan=True)[source]¶ Adds an address or pubkey to wallet without the associated privkey.
-
listunspent
(minconf=0, maxconf=9999999, addrs=None)[source]¶ Return unspent transaction outputs in wallet
Outputs will have between minconf and maxconf (inclusive) confirmations, optionally filtered to only include txouts paid to addresses in addrs.
-
sendmany
(fromaccount, payments, minconf=1, comment='', subtractfeefromamount=[])[source]¶ Send amount to given addresses.
payments - dict with {address: amount}
-
sendrawtransaction
(tx, allowhighfees=False)[source]¶ Submit transaction to local node and network.
allowhighfees - Allow even if fees are unreasonably high.
-
sendtoaddress
(addr, amount, comment='', commentto='', subtractfeefromamount=False)[source]¶ Send amount to a given address
-
signrawtransactionwithwallet
(tx, *args)[source]¶ - Sign inputs for transaction
- bicoincore >= 0.17.x
FIXME: implement options
-
submitblock
(block, params=None)[source]¶ Submit a new block to the network.
params is optional and is currently ignored by bitcoind. See https://en.bitcoin.it/wiki/BIP_0022 for full specification.
-
signature
¶
signmessage
¶
-
class
bitcoincash.signmessage.
BitcoinMessage
(message='', magic='Bitcoin Signed Message:n')[source]¶ Bases:
bitcoincash.core.serialize.ImmutableSerializable
-
magic
¶
-
message
¶
-
wallet
¶
Wallet-related functionality
Includes things like representing addresses and converting them to/from scriptPubKeys; currently there is no actual wallet support implemented.
-
exception
bitcoincash.wallet.
CBitcoinAddressError
[source]¶ Bases:
Exception
Raised when an invalid Bitcoin address is encountered
-
class
bitcoincash.wallet.
CBitcoinAddress
(s)[source]¶ Bases:
bitcoincash.cashaddr.CashAddrData
A Bitcoin address
Initialize from cashaddr-encoded string
Note: subclasses put your initialization routines here, but ignore the argument - that’s handled by __new__(), and .from_bytes() will call __init__() with None in place of the string.
-
classmethod
from_scriptPubKey
(scriptPubKey)[source]¶ Convert a scriptPubKey to a CBitcoinAddress
Returns a CBitcoinAddress subclass, either P2SHBitcoinAddress or P2PKHBitcoinAddress. If the scriptPubKey is not recognized CBitcoinAddressError will be raised.
-
to_scriptHash
(*, hashfunc='sha256')[source]¶ A script hash is the hash of the binary bytes of the locking script (ScriptPubKey), expressed as a hexadecimal string. Like for block and transaction hashes, when converting the big-endian binary hash to a hexadecimal string the least-significant byte appears first, and the most-significant byte last.
This representation of an address is used in the Electrum protocol.
-
classmethod
-
class
bitcoincash.wallet.
P2SHBitcoinAddress
(s)[source]¶ Bases:
bitcoincash.wallet.CBitcoinAddress
Initialize from cashaddr-encoded string
Note: subclasses put your initialization routines here, but ignore the argument - that’s handled by __new__(), and .from_bytes() will call __init__() with None in place of the string.
-
classmethod
from_redeemScript
(redeemScript)[source]¶ Convert a redeemScript to a P2SH address
Convenience function: equivalent to P2SHBitcoinAddress.from_scriptPubKey(redeemScript.to_p2sh_scriptPubKey())
-
classmethod
-
class
bitcoincash.wallet.
P2PKHBitcoinAddress
(s)[source]¶ Bases:
bitcoincash.wallet.CBitcoinAddress
Initialize from cashaddr-encoded string
Note: subclasses put your initialization routines here, but ignore the argument - that’s handled by __new__(), and .from_bytes() will call __init__() with None in place of the string.
-
classmethod
from_pubkey
(pubkey, accept_invalid=False)[source]¶ Create a P2PKH bitcoin address from a pubkey
Raises CBitcoinAddressError if pubkey is invalid, unless accept_invalid is True.
The pubkey must be a bytes instance; CECKey instances are not accepted.
-
classmethod
from_scriptPubKey
(scriptPubKey, accept_non_canonical_pushdata=True, accept_bare_checksig=True)[source]¶ Convert a scriptPubKey to a P2PKH address
Raises CBitcoinAddressError if the scriptPubKey isn’t of the correct form.
accept_non_canonical_pushdata - Allow non-canonical pushes (default True)
accept_bare_checksig - Treat bare-checksig as P2PKH scriptPubKeys (default True)
-
classmethod
-
class
bitcoincash.wallet.
CKey
(secret, compressed=True)[source]¶ Bases:
object
An encapsulated secp256k1 private key
Attributes:
pub - The corresponding CPubKey for this private key
is_compressed - True if compressed
-
is_compressed
¶
-
-
class
bitcoincash.wallet.
CBitcoinSecret
(s)[source]¶ Bases:
bitcoincash.base58.CBase58Data
,bitcoincash.wallet.CKey
A base58-encoded secret key