Callback context (ctx
)
An instance of the HandlerContext
class is passed to every handler providing a set of helper methods and read-only properties.
Reference
- class dipdup.context.DipDupContext(datasources, config, callbacks, transactions)¶
Common execution context for handler and hook callbacks.
- Parameters:
datasources (dict[str, dipdup.datasources.datasource.Datasource]) – Mapping of available datasources
config (DipDupConfig) – DipDup configuration
logger – Context-aware logger instance
callbacks (CallbackManager) –
transactions (TransactionManager) –
- class dipdup.context.HandlerContext(datasources, config, callbacks, transactions, logger, handler_config, datasource)¶
Execution context of handler callbacks.
- Parameters:
handler_config (HandlerConfig) – Configuration of the current handler
datasource (TzktDatasource) – Index datasource instance
datasources (dict[str, dipdup.datasources.datasource.Datasource]) –
config (DipDupConfig) –
callbacks (CallbackManager) –
transactions (TransactionManager) –
logger (FormattedLogger) –
- class dipdup.context.HookContext(datasources, config, callbacks, transactions, logger, hook_config)¶
Execution context of hook callbacks.
- Parameters:
hook_config (HookConfig) – Configuration of the current hook
datasources (dict[str, dipdup.datasources.datasource.Datasource]) –
config (DipDupConfig) –
callbacks (CallbackManager) –
transactions (TransactionManager) –
logger (FormattedLogger) –
- async DipDupContext.add_contract(name, address=None, typename=None, code_hash=None)¶
Adds contract to the inventory.
- Parameters:
name (str) – Contract name
address (str | None) – Contract address
typename (str | None) – Alias for the contract script
code_hash (str | int | None) – Contract code hash
- Return type:
None
- async DipDupContext.add_index(name, template, values, first_level=0, last_level=0, state=None)¶
Adds a new contract to the inventory.
- Parameters:
name (str) – Index name
template (str) – Index template to use
values (dict[str, Any]) – Mapping of values to fill template with
first_level (int) –
last_level (int) –
state (Index | None) –
- Return type:
None
- async DipDupContext.execute_sql(name, *args, **kwargs)¶
Executes SQL script(s) with given name.
If the name path is a directory, all .sql scripts within it will be executed in alphabetical order.
- Parameters:
name (str) – File or directory within project’s sql directory
args (Any) –
kwargs (Any) –
- Return type:
None
- async DipDupContext.execute_sql_query(name, *args)¶
Executes SQL query with given name
- Parameters:
name (str) – SQL query name within <project>/sql directory
args (Any) –
- Return type:
Any
- async DipDupContext.fire_hook(name, fmt=None, wait=True, *args, **kwargs)¶
Fire hook with given name and arguments.
- Parameters:
name (str) – Hook name
fmt (str | None) – Format string for ctx.logger messages
wait (bool) – Wait for hook to finish or fire and forget
args (Any) –
kwargs (Any) –
- Return type:
None
- DipDupContext.get_coinbase_datasource(name)¶
Get coinbase datasource by name
- Parameters:
name (str) –
- Return type:
CoinbaseDatasource
- DipDupContext.get_http_datasource(name)¶
Get http datasource by name
- Parameters:
name (str) –
- Return type:
HttpDatasource
- DipDupContext.get_ipfs_datasource(name)¶
Get ipfs datasource by name
- Parameters:
name (str) –
- Return type:
IpfsDatasource
- DipDupContext.get_metadata_datasource(name)¶
Get metadata datasource by name
- Parameters:
name (str) –
- Return type:
MetadataDatasource
- DipDupContext.get_tzkt_datasource(name)¶
Get tzkt datasource by name
- Parameters:
name (str) –
- Return type:
TzktDatasource
- async DipDupContext.reindex(reason=None, **context)¶
Drops the entire database and starts the indexing process from scratch.
- Parameters:
reason (str | ReindexingReason | None) – Reason for reindexing in free-form string
context (Any) – Additional information to include in exception message
- Return type:
None
- async DipDupContext.restart()¶
Restart process and continue indexing.
- Return type:
None
- async DipDupContext.update_contract_metadata(network, address, metadata)¶
Inserts or updates corresponding rows in the internal dipdup_contract_metadata table to provide a generic metadata interface (see docs).
- Parameters:
network (str) – Network name (e.g. mainnet)
address (str) – Contract address
metadata (dict[str, Any]) – Contract metadata to insert/update
- Return type:
None
- async DipDupContext.update_token_metadata(network, address, token_id, metadata)¶
Inserts or updates corresponding rows in the internal dipdup_token_metadata table to provide a generic metadata interface (see docs).
- Parameters:
network (str) – Network name (e.g. mainnet)
address (str) – Contract address
token_id (str) – Token ID
metadata (dict[str, Any]) – Token metadata to insert/update
- Return type:
None
- async HookContext.rollback(index, from_level, to_level)¶
Rollback index to a given level reverting all changes made since that level.
- Parameters:
index (str) – Index name
from_level (int) – Level to rollback from
to_level (int) – Level to rollback to
- Return type:
None