processor package

Submodules

processor.config module

processor.config.get_config_dir()[source]

Returns the sawtooth configuration directory based on the SAWTOOTH_HOME environment variable (if set) or OS defaults.

processor.config.get_log_dir()[source]

Returns the configured data directory.

processor.config.get_log_config(filename=None)[source]

Returns the log config dictinary if it exists.

processor.config.get_processor_config(filename=None)[source]

Returns the log config dictinary if it exists.

processor.context module

class processor.context.Context(stream, context_id)[source]

Bases: object

Context provides an interface for getting, setting, and deleting validator state. All validator interactions by a handler should be through a Context instance.

Variables
  • _stream (sawtooth.client.stream.Stream) – client grpc communication

  • _context_id (str) – the context_id passed in from the validator

get_state(addresses, timeout=None)[source]

get_state queries the validator state for data at each of the addresses in the given list. The addresses that have been set are returned in a list.

Parameters
  • addresses (list) – the addresses to fetch

  • timeout – optional timeout, in seconds

Returns

a list of Entries (address, data), for the addresses that have a value

Return type

results (list)

Raises

AuthorizationException

set_state(entries, timeout=None)[source]

set_state requests that each address in the provided dictionary be set in validator state to its corresponding value. A list is returned containing the successfully set addresses.

Parameters
  • entries (dict) – dictionary where addresses are the keys and data is the value.

  • timeout – optional timeout, in seconds

Returns

a list of addresses that were set

Return type

addresses (list)

Raises

AuthorizationException

delete_state(addresses, timeout=None)[source]

delete_state requests that each of the provided addresses be unset in validator state. A list of successfully deleted addresses is returned.

Parameters
  • addresses (list) – list of addresses to delete

  • timeout – optional timeout, in seconds

Returns

a list of addresses that were deleted

Return type

addresses (list)

Raises

AuthorizationException

add_receipt_data(data, timeout=None)[source]

Add a blob to the execution result for this transaction.

Parameters

data (bytes) – The data to add.

add_event(event_type, attributes=None, data=None, timeout=None)[source]

Add a new event to the execution result for this transaction.

Parameters
  • event_type (str) – This is used to subscribe to events. It should be globally unique and describe what, in general, has occured.

  • attributes (list of (str, str) tuples) – Additional information about the event that is transparent to the validator. Attributes can be used by subscribers to filter the type of events they receive.

  • data (bytes) – Additional information about the event that is opaque to the validator.

processor.core module

class processor.core.TransactionProcessor(url)[source]

Bases: object

TransactionProcessor is a generic class for communicating with a validator and routing transaction processing requests to a registered handler. It uses ZMQ and channels to handle requests concurrently.

Parameters

url (string) – The URL of the validator

zmq_id
add_handler(handler)[source]

Adds a transaction family handler :param handler: the handler to be added :type handler: TransactionHandler

start()[source]

Connects the transaction processor to a validator and starts listening for requests and routing them to an appropriate transaction handler.

stop()[source]

Closes the connection between the TransactionProcessor and the validator.

processor.exceptions module

exception processor.exceptions.InvalidTransaction(message, extended_data=None)[source]

Bases: processor.exceptions._TpResponseError

Raised for an Invalid Transaction.

exception processor.exceptions.InternalError(message, extended_data=None)[source]

Bases: processor.exceptions._TpResponseError

Raised when an internal error occurs during transaction processing.

exception processor.exceptions.AuthorizationException[source]

Bases: Exception

Raised when a authorization error occurs.

exception processor.exceptions.LocalConfigurationError[source]

Bases: Exception

Raised when a log configuraiton error occurs.

processor.handler module

class processor.handler.TransactionHandler[source]

Bases: object

TransactionHandler is the Abstract Base Class that defines the business logic for a new transaction family.

The family_name, family_versions, and namespaces properties are used by the processor to route processing requests to the handler.

family_name

family_name should return the name of the transaction family that this handler can process, e.g. “intkey”

family_versions

family_versions should return a list of versions this transaction family handler can process, e.g. [“1.0”]

namespaces

namespaces should return a list containing all the handler’s namespaces, e.g. [“abcdef”]

apply(transaction, context)[source]

Apply is the single method where all the business logic for a transaction family is defined. The method will be called by the transaction processor upon receiving a TpProcessRequest that the handler understands and will pass in the TpProcessRequest and an initialized instance of the Context type.

processor.log module

processor.log.create_console_handler(verbose_level)[source]

Set up the console logging for a transaction processor. :param verbose_level: The log level that the console should print out :type verbose_level: int

processor.log.init_console_logging(verbose_level=2)[source]

Set up the console logging for a transaction processor. :param verbose_level: The log level that the console should print out :type verbose_level: int

processor.log.log_configuration(log_config=None, log_dir=None, name=None)[source]

Sets up the loggers for a transaction processor. :param log_config: A dictinary of log config options :type log_config: dict :param log_dir: The log directory’s path :type log_dir: string :param name: The name of the expected logging file :type name: string

Module contents

The processor module defines:

1. A TransactionHandler interface to be used to create new transaction families.

2. A high-level, general purpose TransactionProcessor to which any number of handlers can be added.

3. A Context class used to abstract getting and setting addresses in global validator state.