bitcoinlib.db_cache module

class bitcoinlib.db_cache.DbCache(db_uri=None)[source]

Bases: object

Cache Database object. Initialize database and open session when creating database object.

Create new database if is doesn’t exist yet

drop_db()[source]
class bitcoinlib.db_cache.DbCacheAddress(**kwargs)[source]

Bases: Base

Address Cache Table

Stores transactions and unspent outputs (UTXO’s) per address

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

address

Address string base32 or base58 encoded

balance

Total balance of UTXO’s linked to this key

last_block

Number of last updated block

last_txid

Transaction ID of latest transaction in cache

n_txs

Total number of transactions for this address

n_utxos

Total number of UTXO’s for this address

network_name

Blockchain network name of this transaction

class bitcoinlib.db_cache.DbCacheBlock(**kwargs)[source]

Bases: Base

Block Cache Table

Stores block headers

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

bits

Encoding for proof-of-work, used to determine target and difficulty

block_hash

Hash of this block

height

Height or sequence number for this block

merkle_root

Merkle root used to validate transaction in block

network_name

Blockchain network name

nonce

Nonce (number used only once or n-once) is used to create different block hashes

prev_block

Block hash of previous block

time

Timestamp to indicated when block was created

tx_count

Number of transactions included in this block

version

Block version to specify which features are used (hex)

class bitcoinlib.db_cache.DbCacheTransaction(**kwargs)[source]

Bases: Base

Transaction Cache Table

Database which stores transactions received from service providers as cache

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

block_height

Height of block this transaction is included in

confirmations

Number of confirmation when this transaction is included in a block. Default is 0: unconfirmed

date

Date when transaction was confirmed and included in a block

fee

Transaction fee

locktime

Transaction level locktime. Locks the transaction until a specified block (value from 1 to 5 million) or until a certain time (Timestamp in seconds after 1-jan-1970). Default value is 0 for transactions without locktime

network_name

Blockchain network name of this transaction

nodes

List of all inputs and outputs as DbCacheTransactionNode objects

order_n

Order of transaction in block

txid

Hexadecimal representation of transaction hash or transaction ID

version

Tranaction version. Default is 1 but some wallets use another version number

witness_type

Transaction type enum: legacy or segwit

class bitcoinlib.db_cache.DbCacheTransactionNode(**kwargs)[source]

Bases: Base

Link table for cache transactions and addresses

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

address

Address string base32 or base58 encoded

index_n

Order of input/output in this transaction

is_input

True if input, False if output

output_n()[source]
prev_txid()[source]
ref_index_n

Index number of transaction input which spends this output

ref_txid

Transaction hash of input which spends this output

script

Locking or unlocking script

sequence

Transaction sequence number. Used for timelock transaction inputs

spending_index_n()[source]
spending_txid()[source]
spent

Is output spent?

transaction

Related transaction object

txid
value

Value of transaction input

witnesses

Witnesses (signatures) used in Segwit transaction inputs

class bitcoinlib.db_cache.DbCacheVars(**kwargs)[source]

Bases: Base

Table to store various blockchain related variables

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

expires

Datetime value when variable expires

network_name

Blockchain network name of this transaction

type

Type of variable: int, string or float

value

Value of variable

varname

Variable unique name

class bitcoinlib.db_cache.WitnessTypeTransactions(value)[source]

Bases: Enum

An enumeration.

legacy = 'legacy'
segwit = 'segwit'