⚰️ DipDup 6.5 branch is no longer supported. Please, follow the⠀Migration Guide⠀to update to the latest version.
Operation group in BCD explorer `operation` index config

operation index

Operation index allows you to query only operations related to your dapp and match them with handlers by content. A single contract call consists of implicit operation and, optionally, internal operations. For each of them, you can specify a handler that will be called when the operation group matches. As a result, you get something like an event log for your dapp.

Handlers

Each operation handler contains two required fields:

  • callback — a name of async function with a particular signature; DipDup will search for it in <package>.handlers.<callback> module.
  • pattern — a non-empty list of items that need to be matched.
indexes:
  my_index:
    kind: operation
    datasource: tzkt
    contracts:
      - some_contract
    handlers:
      - callback: on_call
        pattern:
          - destination: some_contract
            entrypoint: transfer

You can think of the operation pattern as a regular expression on a sequence of operations (both external and internal) with a global flag enabled (there can be multiple matches). Multiple operation parameters can be used for matching (source, destination, etc.).

You will get slightly different callback argument types depending on whether pattern item is typed or not. If so, DipDup will generate the dataclass for a particular entrypoint/storage, otherwise you will have to handle untyped parameters/storage updates stored in OperationData model.

Matching originations

namedescriptionsupportedtyped
originated_contract.addressOrigination of exact contract.
originated_contract.code_hashOriginations of all contracts having the same code.
source.addressSpecial cases only. This filter is very slow and doesn't support strict typing. Usually, originated_contract.code_hash suits better.
source.code_hashCurrently not supported.
similar_to.addressCompatibility alias to originated_contract.code_hash. Can be removed some day.➡️➡️
similar_to.code_hashCompatibility alias to originated_contract.code_hash. Can be removed some day.➡️➡️

Matching transactions

namedescriptionsupportedtyped
source.addressSent by exact address.N/A
source.code_hashSent by any contract having this code hashN/A
destination.addressInvoked contract address
destination.code_hashInvoked contract code hash
destination.entrypointEntrypoint called

Optional items

Pattern items have optional field to continue matching even if this item is not found. It's usually unnecessary to match the entire operation content; you can skip external/internal calls that are not relevant. However, there is a limitation: optional items cannot be followed by operations ignored by the pattern.

pattern:
  # Implicit transaction
  - destination: some_contract
    entrypoint: mint

  # Internal transactions below
  - destination: another_contract
    entrypoint: transfer

  - source: some_contract
    type: transaction

Specifying contracts to index

DipDup will try to guess the list of used contracts by handlers' signatures. If you want to specify it explicitly, use contracts field:

indexes:
  my_index:
    kind: operation
    datasource: tzkt
    contracts:
      - foo
      - bar

Specifying operation types

By default, DipDup processes only transactions, but you can enable other operation types you want to process (currently, transaction, origination, and migration are supported).

indexes:
  my_index:
    kind: operation
    datasource: tzkt
    types:
      - transaction
      - origination
      - migration