Plugin

PluginContext

class trinity.extensibility.plugin.PluginContext(endpoint: trinity.endpoint.TrinityEventBusEndpoint, boot_info: trinity.extensibility.plugin.TrinityBootInfo)

The PluginContext holds valuable contextual information and APIs to be used by a plugin. This includes the parsed arguments that were used to launch Trinity as well as an Endpoint that the plugin can use to connect to the event bus.

The PluginContext is set during startup and is guaranteed to exist by the time that a plugin receives its on_ready() call.

args

Return the parsed arguments that were used to launch the application

event_bus

Return the Endpoint that the plugin uses to connect to the event bus

trinity_config

Return the TrinityConfig

BasePlugin

class trinity.extensibility.plugin.BasePlugin
configure_parser(arg_parser: argparse.ArgumentParser, subparser: argparse._SubParsersAction) → None

Give the plugin a chance to amend the Trinity CLI argument parser. This hook is called before on_ready()

do_start() → None

Perform the actual plugin start routine. In the case of a BaseIsolatedPlugin this method will be called in a separate process.

This method should usually be overwritten by subclasses with the exception of plugins that set func on the ArgumentParser to redefine the entire host program.

event_bus

Get the Endpoint that this plugin uses to connect to the event bus

logger

Get the Logger for this plugin.

name

Describe the name of the plugin.

normalized_name

The normalized (computer readable) name of the plugin

on_ready(manager_eventbus: trinity.endpoint.TrinityEventBusEndpoint) → None

Notify the plugin that it is ready to bootstrap itself. Plugins can rely on the PluginContext to be set after this method has been called. The manager_eventbus refers to the instance of the Endpoint that the PluginManager uses which may or may not be the same Endpoint as the plugin uses depending on the type of the plugin. The plugin should use this Endpoint instance to listen for events before the plugin has started.

ready(manager_eventbus: trinity.endpoint.TrinityEventBusEndpoint) → None

Set the status to PluginStatus.READY and delegate to on_ready()

running

Return True if the status is PluginStatus.STARTED, otherwise return False.

set_context(context: trinity.extensibility.plugin.PluginContext) → None

Set the PluginContext for this plugin.

start() → None

Delegate to do_start() and set running to True. Broadcast a PluginStartedEvent on the event bus and hence allow other plugins to act accordingly.

status

Return the current PluginStatus of the plugin.

BaseAsyncStopPlugin

class trinity.extensibility.plugin.BaseAsyncStopPlugin

A BaseAsyncStopPlugin unwinds asynchronoulsy, hence needs to be awaited.

coroutine do_stop() → None

Asynchronously stop the plugin. Should be overwritten by subclasses.

coroutine stop() → None

Delegate to do_stop() causing the plugin to stop asynchronously and setting running to False.

BaseMainProcessPlugin

class trinity.extensibility.plugin.BaseMainProcessPlugin

A BaseMainProcessPlugin overtakes the whole main process early before any of the subsystems started. In that sense it redefines the whole meaning of the trinity command.

BaseIsolatedPlugin

class trinity.extensibility.plugin.BaseIsolatedPlugin

A BaseIsolatedPlugin runs in an isolated process and hence provides security and flexibility by not making assumptions about its internal operations.

Such plugins are free to use non-blocking asyncio as well as synchronous calls. When an isolated plugin is stopped it does first receive a SIGINT followed by a SIGTERM soon after. It is up to the plugin to handle these signals accordingly.

process

Return the Process created by the isolated plugin.

start() → None

Prepare the plugin to get started and eventually call do_start in a separate process.

stop() → None

Set the status to STOPPED` but rely on the PluginManager to tear down the process. This allows isolated plugins to be taken down concurrently without depending on a running event loop.