prov2bigchaindb.core package

Submodules

prov2bigchaindb.core.accounts module

class prov2bigchaindb.core.accounts.BaseAccount(account_id: str, store: prov2bigchaindb.core.local_stores.SqliteStore)[source]

Bases: object

BigchainDB Base Account

get_id() → str[source]

Get Account id

Returns:Internal id of Account
Return type:str
get_public_key() → str[source]

Get public key

Returns:Public key of Account
Return type:str
class prov2bigchaindb.core.accounts.DocumentConceptAccount(account_id: str, store: prov2bigchaindb.core.local_stores.SqliteStore)[source]

Bases: prov2bigchaindb.core.accounts.BaseAccount

BigchainDB Document Concept Account

save_asset(asset: dict, bdb_connection: bigchaindb_driver.driver.BigchainDB) → str[source]

Write asset to BigchainDB

Parameters:
  • asset (dict) – Dictonary with asset data
  • bdb_connection (BigchainDB) – Connection object for BigchainDB
Returns:

Transaction Id

Return type:

str

class prov2bigchaindb.core.accounts.GraphConceptAccount(prov_element: prov.model.ProvElement, prov_relations: dict, id_mapping: dict, namespaces: list, store: prov2bigchaindb.core.local_stores.SqliteStore = <prov2bigchaindb.core.local_stores.SqliteStore object>)[source]

Bases: prov2bigchaindb.core.accounts.BaseAccount

BigchainDB Graph Concept Account

get_tx_id() → str[source]

Get the tx_id that describes the account in BigchainDB

Returns:Transaction id of account
Return type:str
has_relations_with_id() → bool[source]

Indicates whether an account has relation with ids or not :return: True if one or more relation does have ids :rtype: bool

has_relations_without_id() → bool[source]

Indicates whether an account has relation without ids or not :return: True if one or more relation does have ids :rtype: bool

save_relations_with_ids(bdb_connection: bigchaindb_driver.driver.BigchainDB) → list[source]

Writes all assets with relations (having ids) to BigchainDB

Parameters:bdb_connection (BigchainDB) – Connection object for BigchainDB
Returns:Transactions ids of all relations
Return type:list
save_relations_without_ids(bdb_connection: bigchaindb_driver.driver.BigchainDB) → list[source]

Write all assets with relations to BigchainDB

Parameters:bdb_connection (BigchainDB) – Connection object for BigchainDB
Returns:Transactions ids of all relations
Return type:list
save_instance_asset(bdb_connection: bigchaindb_driver.driver.BigchainDB) → str[source]

Write provenance describing the account to BigchainDB

Parameters:bdb_connection (BigchainDB) – Connection object for BigchainDB
Returns:Transactions id of instance
Return type:str
class prov2bigchaindb.core.accounts.RoleConceptAccount(agent: prov.model.ProvAgent, relations: list, elements: dict, id_mapping: dict, namespaces: list, store: prov2bigchaindb.core.local_stores.SqliteStore = <prov2bigchaindb.core.local_stores.SqliteStore object>)[source]

Bases: prov2bigchaindb.core.accounts.BaseAccount

BigchainDB Graph Concept Account

get_tx_id() → str[source]

Get the tx_id that describes the account in BigchainDB

Returns:Transaction id of account
Return type:str
save_elements(bdb_connection: bigchaindb_driver.driver.BigchainDB) → list[source]

Writes all elements with assets to BigchainDB

Parameters:bdb_connection (BigchainDB) – Connection object for BigchainDB
Returns:Transactions ids of all relations
Return type:list
save_instance_asset(bdb_connection: bigchaindb_driver.driver.BigchainDB) → str[source]

Write provenance describing the account to BigchainDB

Parameters:bdb_connection (BigchainDB) – Connection object for BigchainDB
Returns:Transactions id of instance
Return type:str

prov2bigchaindb.core.clients module

class prov2bigchaindb.core.clients.BaseClient(host: str = '0.0.0.0', port: int = 9984, num_connections: int = 5, local_store: prov2bigchaindb.core.local_stores.SqliteStore = <prov2bigchaindb.core.local_stores.SqliteStore object>)[source]

Bases: object

BigchainDB Base Client

test_transaction(tx: dict) → bool[source]

Validate a transaction against BigchainDB

Parameters:tx (dict) – Transaction to test
Returns:True or Exception
Return type:bool
save_document(document: object) → object[source]

Abstract method to store a document

Parameters:document (object) – Document to save
Returns:id
Return type:object
get_document(document_id: object) → prov.model.ProvDocument[source]

Abstract method to retrieve a document

Parameters:document_id (object) – Document to save
Return type:ProvDocument
class prov2bigchaindb.core.clients.DocumentConceptClient(account_id: str = None, host: str = '0.0.0.0', port: int = 9984, num_connections: int = 1, local_store: prov2bigchaindb.core.local_stores.SqliteStore = <prov2bigchaindb.core.local_stores.SqliteStore object>)[source]

Bases: prov2bigchaindb.core.clients.BaseClient

save_document(document: str) → str[source]

Write a document into BigchainDB

Parameters:document (str or bytes or ProvDocument) – Document as JSON/XML/PROVN
Returns:Transaction id of document
Return type:str
get_document(tx_id: str) → prov.model.ProvDocument[source]

Retrieve a document by transaction id from BigchainDB

Parameters:tx_id (str) – Transaction Id of Document
Returns:Document as ProvDocument object
Return type:ProvDocument
class prov2bigchaindb.core.clients.GraphConceptClient(host: str = '0.0.0.0', port: int = 9984, num_connections: int = 5, local_store: prov2bigchaindb.core.local_stores.SqliteStore = <prov2bigchaindb.core.local_stores.SqliteStore object>)[source]

Bases: prov2bigchaindb.core.clients.BaseClient

static calculate_account_data(prov_document: prov.model.ProvDocument) → list[source]

Transforms a ProvDocument into a tuple with ProvElement, list of ProvRelation and list of Namespaces

Parameters:prov_document – Document to transform
Returns:List of tuples(element, relations, namespace)
Return type:list
save_document(document: str) → list[source]

Write a document into BigchainDB

Parameters:document (str or BufferedReader or ProvDocument) – Document as JSON/XML/PROVN
Returns:List of transaction ids
Return type:list
get_document(document_tx_ids: list) → prov.model.ProvDocument[source]

Retrieve a document by a list transaction ids from BigchainDB

Parameters:document_tx_ids (list) – Transaction Ids of Document
Returns:Document as ProvDocument object
Return type:ProvDocument
class prov2bigchaindb.core.clients.RoleConceptClient(host: str = '0.0.0.0', port: int = 9984, num_connections: int = 5, local_store: prov2bigchaindb.core.local_stores.SqliteStore = <prov2bigchaindb.core.local_stores.SqliteStore object>)[source]

Bases: prov2bigchaindb.core.clients.BaseClient

static calculate_account_data(prov_document: prov.model.ProvDocument) → list[source]

Transforms a ProvDocument into a list of tuples including: ProvAgent, list of ProvRelations from agent, list of ProvElements associated to ProvAgent, list of Namespaces

Parameters:prov_document – Document to transform
Returns:List of tuples(ProvAgent, list(), list(), list())
Return type:list
save_document(document: str) → list[source]

Write a document into BigchainDB

Parameters:document (str or BufferedReader or ProvDocument) – Document as JSON/XML/PROVN
Returns:List of transaction ids
Return type:list
get_document(document_tx_ids: list) → prov.model.ProvDocument[source]

Returns a document by a list transaction ids from BigchainDB

Parameters:document_tx_ids (list) – Transaction Ids of Document
Returns:Document as ProvDocument object
Return type:ProvDocument

prov2bigchaindb.core.exceptions module

exception prov2bigchaindb.core.exceptions.Prov2BigchainDBException[source]

Bases: Exception

exception prov2bigchaindb.core.exceptions.CreateRecordException[source]

Bases: prov2bigchaindb.core.exceptions.Prov2BigchainDBException

exception prov2bigchaindb.core.exceptions.ParseException[source]

Bases: prov2bigchaindb.core.exceptions.Prov2BigchainDBException

exception prov2bigchaindb.core.exceptions.NoAccountFoundException[source]

Bases: prov2bigchaindb.core.exceptions.Prov2BigchainDBException

exception prov2bigchaindb.core.exceptions.AccountNotCreatedException[source]

Bases: prov2bigchaindb.core.exceptions.Prov2BigchainDBException

exception prov2bigchaindb.core.exceptions.NoRelationFoundException[source]

Bases: prov2bigchaindb.core.exceptions.Prov2BigchainDBException

exception prov2bigchaindb.core.exceptions.TransactionIdNotFound[source]

Bases: prov2bigchaindb.core.exceptions.Prov2BigchainDBException

exception prov2bigchaindb.core.exceptions.BlockIdNotFound[source]

Bases: prov2bigchaindb.core.exceptions.Prov2BigchainDBException

prov2bigchaindb.core.local_stores module

class prov2bigchaindb.core.local_stores.BaseStore(db_name: str = None)[source]

Bases: object

clean_tables()[source]

Delete all entries from all tables (Used for unit tests)

write_account(account_id: str, public_key: str, private_key: str, tx_id: str = None)[source]

Writes a new account entry in to the table accounts

Parameters:
  • tx_id (str) – Transactions id
  • account_id (str) – Id of account
  • public_key (str) – Public key of account
  • private_key (str) – Private key of account
get_account(account_id: str) → tuple[source]

Returns tuple of account from data by account_id

Parameters:account_id (str) – Id of account
Returns:Tuple with account_id, public_key, private_key and tx_id
Return type:tuple
write_tx_id(account_id: str, tx_id: str)[source]

Writes tx_id for given account_id

Parameters:
  • account_id (str) – Id of account
  • tx_id (str) – Transaction id, which represents the account in BigchainDB
class prov2bigchaindb.core.local_stores.SqliteStore(db_name: str = ':memory:')[source]

Bases: prov2bigchaindb.core.local_stores.BaseStore

clean_tables()[source]

Delete all entries from all tables (Used for unit tests)

write_account(account_id: str, public_key: str, private_key: str, tx_id: str = None)[source]

Writes a new account entry in to the table accounts

Parameters:
  • tx_id (str) – Transactions id
  • account_id (str) – Id of account
  • public_key (str) – Public key of account
  • private_key (str) – Private key of account
get_account(account_id: str) → tuple[source]

Returns tuple of account from data by account_id

Parameters:account_id (str) – Id of account
Returns:Tuple with account_id, public_key, private_key and tx_id
Return type:tuple
write_tx_id(account_id: str, tx_id: str)[source]

Writes tx_id for given account_id

Parameters:
  • account_id (str) – Id of account
  • tx_id (str) – Transaction id, which represents the account in BigchainDB

prov2bigchaindb.core.utils module

prov2bigchaindb.core.utils.to_prov_document(content: str) → prov.model.ProvDocument[source]

Takes a string, bytes or ProvDocument as argument and return a ProvDocument The strings or bytes can contain JSON or XML representations of PROV

Parameters:content – String or BufferedReader or ProvDocument
Returns:ProvDocument
Return type:ProvDocument
prov2bigchaindb.core.utils.wait_until_valid(tx_id: str, bdb_connection: bigchaindb_driver.driver.BigchainDB)[source]

Waits until a transaction is valid in BigchainDB

Parameters:
  • tx_id (str) – Id of transaction to wait on
  • bdb_connection (BigchainDB) – Connection object for BigchainDB
prov2bigchaindb.core.utils.is_valid_tx(tx_id: str, bdb_connection: bigchaindb_driver.driver.BigchainDB) → bool[source]

Checks once if a transaction is valid

Parameters:
  • tx_id (str) – Id of transaction to check
  • bdb_connection (BigchainDB) – Connection object for BigchainDB
Returns:

True if valid

Return type:

bool

prov2bigchaindb.core.utils.is_block_to_tx_valid(tx_id: str, bdb_connection: bigchaindb_driver.driver.BigchainDB) → bool[source]

Checks if block with transaction is valid

Parameters:
  • tx_id (str) – Id of transaction which should be included in the
  • bdb_connection (BigchainDB) – Connection object for BigchainDB
Returns:

True if transactions is in block and block is valid

Return type:

bool

Module contents