The BigchainDB Class¶
-
class
bigchaindb.
BigchainDB
(connection=None)[source]¶ Bigchain API
Create, read, sign, write transactions to the database
-
update_utxoset
(transaction)[source]¶ Update the UTXO set given
transaction
. That is, remove the outputs that the giventransaction
spends, and add the outputs that the giventransaction
creates.Parameters: transaction ( Transaction
) – A new transaction incoming into the system for which the UTXO set needs to be updated.
-
store_unspent_outputs
(*unspent_outputs)[source]¶ Store the given
unspent_outputs
(utxos).Parameters: *unspent_outputs ( tuple
ofdict
) – Variable length tuple or list of unspent outputs.
-
get_utxoset_merkle_root
()[source]¶ Returns the merkle root of the utxoset. This implies that the utxoset is first put into a merkle tree.
For now, the merkle tree and its root will be computed each time. This obviously is not efficient and a better approach that limits the repetition of the same computation when unnecesary should be sought. For instance, future optimizations could simply re-compute the branches of the tree that were affected by a change.
The transaction hash (id) and output index should be sufficient to uniquely identify a utxo, and consequently only that information from a utxo record is needed to compute the merkle root. Hence, each node of the merkle tree should contain the tuple (txid, output_index).
Important
The leaves of the tree will need to be sorted in some kind of lexicographical order.
Returns: Merkle root in hexadecimal form. Return type: str
-
delete_unspent_outputs
(*unspent_outputs)[source]¶ Deletes the given
unspent_outputs
(utxos).Parameters: *unspent_outputs ( tuple
ofdict
) – Variable length tuple or list of unspent outputs.
-
get_transactions_filtered
(asset_id, operation=None, last_tx=None)[source]¶ Get a list of transactions filtered on some criteria
-
get_outputs_filtered
(owner, spent=None)[source]¶ Get a list of output links filtered on some criteria
Parameters: Returns: list of
txid
s andoutput
s pointing to another transaction’s conditionReturn type: list
of TransactionLink
-
get_block
(block_id)[source]¶ Get the block with the specified block_id.
Returns the block corresponding to block_id or None if no match is found.
Parameters: block_id (int) – block id of the block to get.
-
get_block_containing_tx
(txid)[source]¶ - Retrieve the list of blocks (block ids) containing a
- transaction with transaction id txid
Parameters: txid (str) – transaction id of the transaction to query Returns: Block id list (list(int))
-
validate_transaction
(tx, current_transactions=[])[source]¶ Validate a transaction against the current status of the database.
-
text_search
(search, *, limit=0, table='assets')[source]¶ Return an iterator of assets that match the text search
Parameters: Returns: An iterator of assets that match the text search.
Return type: iter
-
get_assets
(asset_ids)[source]¶ Return a list of assets that match the asset_ids
Parameters: asset_ids ( list
ofstr
) – A list of asset_ids to retrieve from the database.Returns: The list of assets returned from the database. Return type: list
-
get_metadata
(txn_ids)[source]¶ Return a list of metadata that match the transaction ids (txn_ids)
Parameters: txn_ids ( list
ofstr
) – A list of txn_ids to retrieve from the database.Returns: The list of metadata returned from the database. Return type: list
-
store_validator_set
(height, validators)[source]¶ Store validator set at a given height. NOTE: If the validator set already exists at that height then an exception will be raised.
-
migrate_abci_chain
()[source]¶ Generate and record a new ABCI chain ID. New blocks are not accepted until we receive an InitChain ABCI request with the matching chain ID and validator set.
Chain ID is generated based on the current chain and height. chain-X => chain-X-migrated-at-height-5. chain-X-migrated-at-height-5 => chain-X-migrated-at-height-21.
If there is no known chain (we are at genesis), the function returns.
-