Library Reference

Plugin

class coalaip_bigchaindb.Plugin(*nodes)[source]

BigchainDB ledger plugin for COALA IP’s Python reference implementation.

Plugs in a BigchainDB instance as the persistence layer for COALA IP related actions.

__init__(*nodes)[source]

Initialize a Plugin instance and connect to one or more BigchainDB nodes.

Parameters:*nodes (str) – One or more URLs of BigchainDB nodes to connect to as the persistence layer
generate_user()[source]

Create a new public/private keypair for use with BigchainDB.

Returns:A dict containing a new user’s public and private keys:
{
    'public_key': (str),
    'private_key': (str),
}
Return type:dict
get_history(persist_id)[source]

Get the transaction history of an COALA IP entity on BigchainDB.

Parameters:

persist_id (str) – Asset id of the entity on the connected BigchainDB instance

Returns:

The ownership history of the entity, sorted starting from the beginning of the entity’s history (i.e. creation). Each dict is of the form:

{
    'user': A dict holding only the user's public key
            (the private key is omitted as None).
    'event_id': The transaction id for the ownership event
}

Return type:

list of dict

Raises:
  • coalaip.EntityNotFoundError – If no asset whose id matches persist_id could be found in the connected BigchainDB instance
  • PersistenceError – If any other unhandled error from the BigchainDB driver occurred.
get_status(persist_id)[source]

Get the status of an COALA IP entity on BigchainDB.

Parameters:

persist_id (str) – Asset id of the entity on the connected BigchainDB instance

Returns:

the status of the entity; one of:

'valid': the transaction has been written in a validated block
'invalid': the block the transaction was in was voted invalid
'undecided': the block the transaction is in is still undecided
'backlog': the transaction is still in the backlog

Return type:

str

Raises:
  • coalaip.EntityNotFoundError – If no transaction whose ‘uuid’ matches persist_id could be found in the connected BigchainDB instance
  • PersistenceError – If any other unhandled error from the BigchainDB driver occurred.
is_same_user(user_a, user_b)[source]

Check if user_a represents the same user as user_b on BigchainDB by comparing their public keys.

load(persist_id)[source]

Load the data of the entity associated with the persist_id from BigchainDB.

Parameters:

persist_id (str) – Asset id of the entity being loaded on the connected BigchainDB instance

Returns:

The persisted data of the entity

Return type:

dict

Raises:
  • coalaip.EntityNotFoundError – If no asset whose id
  • matches persist_id could be found in the connected
  • BigchainDB instance
  • PersistenceError – If any other unhandled error from the BigchainDB driver occurred.
save(entity_data, *, user)[source]

Create and assign a new entity with the given data to the given user’s public key on BigchainDB.

Parameters:
  • entity_data (dict) – A dict holding the entity’s data that will be saved in a new asset’s asset definition
  • user (dict, keyword) –

    The user to assign the created entity to on BigchainDB. A dict containing:

    {
        'public_key': (str),
        'private_key': (str),
    }
    

    where ‘public_key’ and ‘private_key’ are the user’s respective public and private keys.

Returns:

Asset id of the new entity

Return type:

str

Raises:
  • coalaip.EntityCreationError – If the creation transaction fails
  • PersistenceError – If any other unhandled error from the BigchainDB driver occurred.
transfer(persist_id, transfer_payload=None, *, from_user, to_user)[source]

Transfer the entity matching the given persist_id from the current owner (from_user) to a new owner (to_user).

Parameters:
  • persist_id (str) – Asset id of the entity on the connected BigchainDB instance
  • transfer_payload (dict, optional) – A dict holding the transfer’s payload
  • from_user (dict, keyword) – A dict holding the current owner’s public key and private key (see generate_user())
  • to_user (dict, keyword) – A dict holding the new owner’s public key and private key (see generate_user())
Returns:

Id of the transaction transferring the entity from from_user to to_user

Return type:

str

Raises:
  • coalaip.EntityNotFoundError – If no asset whose id matches persist_id could be found in the connected BigchainDB instance
  • coalaip.EntityTransferError – If the transfer transaction fails
  • PersistenceError – If any other unhandled error from the BigchainDB driver occurred.
type

str – the type of this plugin ('BigchainDB')