sawtooth.client module

class sawtooth.client.TransactionStatus[source]

Bases: enum.IntEnum

committed = 200
pending = 302
not_found = 404
internal_server_error = 500
server_busy = 503
__eq__ = <method-wrapper '__eq__' of type object at 0x904b40>
__ge__ = <method-wrapper '__ge__' of type object at 0x904b40>
__gt__ = <method-wrapper '__gt__' of type object at 0x904b40>
__hash__
__le__ = <method-wrapper '__le__' of type object at 0x904b40>
__lt__ = <method-wrapper '__lt__' of type object at 0x904b40>
__ne__ = <method-wrapper '__ne__' of type object at 0x904b40>
class sawtooth.client.UpdateBatch(client)[source]

Bases: object

Helper object to allow group updates submission using

sawtooth client.

the block
try:
client.start_batch() client.send_txn(...) client.send_txn(...) client.send_batch()
except:
client.reset_batch()

becomes:

with UpdateBatch(client) as _:
client.send_txn() client.send_txn()
class sawtooth.client.SawtoothClient(base_url, store_name=None, name='SawtoothClient', txntype_name=None, msgtype_name=None, keystring=None, keyfile=None, disable_client_validation=False)[source]

Bases: object

base_url
last_transaction_id
start_batch()[source]

Start a batch of updates to be sent in a single transaction to the validator.

Returns:None
reset_batch()[source]

Abandon the current batch.

Returns:None
send_batch()[source]

Sends the current batch of transactions to the Validator.

Returns:transaction_id of the update transaction
send_update(updates, dependencies=None)[source]

Send an update or list of updates to the validator or add them to an existing batch.

Parameters:
  • updates – single update or list of updates to be sent.
  • dependencies – ids of transactions dependencies.
Returns:

transaction_id if update is sent, None if it is added to a batch.

sendtxn(txntype_name, msgtype_name, minfo)[source]

Build a transaction for the update, wrap it in a message with all of the appropriate signatures and post it to the validator. Will not work with UpdatesTransaction txn families but will work with txn families in Arcade.

get_status(timeout=30)[source]

Get the status for a validator

Parameters:timeout – Number of seconds to wait for response before determining reqeuest has timed out

Returns: A dictionary of status items

get_store_list()[source]

Get the list of stores on the validator.

Returns: A list of store names

get_store_by_name(txn_type_or_name, key=None, block_id=None, delta=False)[source]

Generic store retrieval method of any named store. This allows complete flexibility in specifying the parameters to the HTTP request.

This function is used when the client has not been configured, on construction, to use a specific store or you wish to access a different store than the object was initially configured to use.

This function should only be used when you need absolute control over the HTTP request being made to the store. Otherwise, the store convenience methods should be used instead.

Parameters:
  • txn_type_or_name – A transaction class or object (i.e., derived from transaction.Transaction) that can be used to infer the store name or a string with the store name.
  • key – (optional) The object to retrieve from the store. If None, will returns keys instead of objects.
  • block_id – (optional) The block ID to use as ending or starting point of retrieval.
  • delta – (optional) A flag to indicate of only a delta should be returned. If key is None, this is ignored.
Returns:

Either a list of keys, a dictionary of name/value pairs that represent one or more objects, or a delta representation of the store.

Notes

Reference the Sawtooth Lake Web API documentation for the behavior for the key/block_id/delta combinations.

get_store(key=None, block_id=None, delta=False)[source]

Generic store retrieval method. This allows complete flexibility in specifying the parameters to the HTTP request.

This function should only be used when you need absolute control over the HTTP request being made to the store. Otherwise, the store convenience methods should be used instead.

Parameters:
  • key – (optional) The object to retrieve from the store. If None, will returns keys instead of objects.
  • block_id – (optional) The block ID to use as ending or starting point of retrieval.
  • delta – (optional) A flag to indicate of only a delta should be returned. If key is None, this is ignored.
Returns:

Either a list of keys, a dictionary of name/value pairs that represent one or more objects, or a delta representation of the store.

Notes

Reference the Sawtooth Lake Web API documentation for the behavior for the key/block_id/delta combinations.

Raises ClientException if the client object was not created with a store name or transaction type.

get_store_keys()[source]

Retrieve the list of keys (object IDs) from the store.

Returns: A list of keys for the store

Raises ClientException if the client object was not created with a store name or transaction type.

get_all_store_objects()[source]

Retrieve all of the objects for a particular store

Returns: A dictionary mapping object keys to objects (dictionaries
of key/value pairs).

Raises ClientException if the client object was not created with a store name or transaction type.

get_store_object_for_key(key)[source]

Retrieves the object from the store corresponding to the key

Parameters:key – The object to retrieve from the store
Returns:A dictionary of name/value pairs that represent the object associated with the key provided.

Raises ClientException if the client object was not created with a store name or transaction type.

get_store_delta_for_block(block_id)[source]

Retrieves the store for just the block provided.

Parameters:block_id – The ID of the block for which store should be returned.
Returns:A dictionary that represents the store.

Raises ClientException if the client object was not created with a store name or transaction type.

get_store_objects_through_block(block_id)[source]

Retrieve all of the objects for a particular store up through the block requested.

Parameters:block_id – The ID of the last block to look for objects.
Returns: A dictionary mapping object keys to objects (dictionaries
of key/value pairs).

Raises ClientException if the client object was not created with a store name or transaction type.

get_block_list(count=None)[source]

Retrieve the list of block IDs, ordered from newest to oldest.

Parameters:count – (optional) If not None, specifies the maximum number of blocks to return.

Returns: A list of block IDs.

get_block(block_id, field=None)[source]

Retrieve information about a specific block, returning all information or, if provided, a specific field from the block.

Parameters:
  • block_id – The ID of the block to retrieve
  • field – (optional) If not None, specifies the name of the field to retrieve from the block.
Returns:

A dictionary of block data, if field is None The value for the field, if field is not None

get_transaction_list(block_count=None)[source]

Retrieve the list of transaction IDs, ordered from newest to oldest.

Parameters:block_count – (optional) If not None, specifies the maximum number of blocks to return transaction IDs for.

Returns: A list of transaction IDs.

get_transaction(transaction_id, field=None)[source]

Retrieve information about a specific transaction, returning all information or, if provided, a specific field from the transaction.

Parameters:
  • transaction_id – The ID of the transaction to retrieve
  • field – (optional) If not None, specifies the name of the field to retrieve from the transaction.
Returns:

A dictionary of transaction data, if field is None The value for the field, if field is not None

get_transaction_status(transaction_id)[source]

Retrieves that status of a transaction.

Parameters:transaction_id – The ID of the transaction to check.
Returns:One of the TransactionStatus values (committed, etc.)
forward_message(msg)[source]

Post a gossip message to the ledger with the intent of having the receiving validator forward it to all of its peers.

Parameters:msg – The message to send.
Returns: The parsed response, which is typically the encoding of
the original message.
wait_for_commit(txnid=None, timetowait=5, iterations=12)[source]

Wait until a specified transaction shows up in the ledger’s committed transaction list

Parameters:
  • txnid (id) – the transaction to wait for, the last transaction by default
  • timetowait (int) – time to wait between polling the ledger
  • iterations (int) – number of iterations to wait before giving up