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: Dict[str, Datasource], config: DipDupConfig, callbacks: CallbackManager, transactions: TransactionManager)

Common execution context for handler and hook callbacks.

Parameters:
  • datasources – Mapping of available datasources

  • config – DipDup configuration

  • logger – Context-aware logger instance

async add_contract(name: str, address: str, typename: Optional[str] = None) None

Adds contract to the inventory.

Parameters:
  • name – Contract name

  • address – Contract address

  • typename – Alias for the contract script

async add_index(name: str, template: str, values: Dict[str, Any], state: Optional[Index] = None) None

Adds a new contract to the inventory.

Parameters:
  • name – Index name

  • template – Index template to use

  • values – Mapping of values to fill template with

async execute_sql(name: str) None

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 – File or directory within project’s sql directory

async fire_hook(name: str, fmt: Optional[str] = None, wait: bool = True, *args, **kwargs: Any) None

Fire hook with given name and arguments.

Parameters:
  • name – Hook name

  • fmt – Format string for ctx.logger messages

  • wait – Wait for hook to finish or fire and forget

get_coinbase_datasource(name: str) CoinbaseDatasource

Get coinbase datasource by name

get_http_datasource(name: str) HttpDatasource

Get http datasource by name

get_ipfs_datasource(name: str) IpfsDatasource

Get ipfs datasource by name

get_metadata_datasource(name: str) MetadataDatasource

Get metadata datasource by name

get_tzkt_datasource(name: str) TzktDatasource

Get tzkt datasource by name

async reindex(reason: Optional[Union[str, ReindexingReason]] = None, **context) None

Drops the entire database and starts the indexing process from scratch.

Parameters:
  • reason – Reason for reindexing in free-form string

  • context – Additional information to include in exception message

async restart() None

Restart process and continue indexing.

async update_contract_metadata(network: str, address: str, metadata: Dict[str, Any]) None

Inserts or updates corresponding rows in the internal dipdup_contract_metadata table to provide a generic metadata interface (see docs).

Parameters:
  • network – Network name (e.g. mainnet)

  • address – Contract address

  • metadata – Contract metadata to insert/update

async update_token_metadata(network: str, address: str, token_id: str, metadata: Dict[str, Any]) None

Inserts or updates corresponding rows in the internal dipdup_token_metadata table to provide a generic metadata interface (see docs).

Parameters:
  • network – Network name (e.g. mainnet)

  • address – Contract address

  • token_id – Token ID

  • metadata – Token metadata to insert/update

class dipdup.context.HandlerContext(datasources: Dict[str, Datasource], config: DipDupConfig, callbacks: CallbackManager, transactions: TransactionManager, logger: FormattedLogger, handler_config: HandlerConfig, datasource: TzktDatasource)

Execution context of handler callbacks.

Parameters:
  • handler_config – Configuration of current handler

  • datasource – Index datasource instance

class dipdup.context.HookContext(datasources: Dict[str, Datasource], config: DipDupConfig, callbacks: CallbackManager, transactions: TransactionManager, logger: FormattedLogger, hook_config: HookConfig)

Execution context of hook callbacks.

Parameters:

hook_config – Configuration of current hook

async rollback(index: str, from_level: int, to_level: int) None

Rollback index to a given level reverting all changes made since that level.

Parameters:
  • index – Index name

  • from_level – Level to rollback from

  • to_level – Level to rollback to