github graphprotocol/graph-tooling v0.11.0

latest releases: @graphprotocol/graph-cli@0.77.0, @graphprotocol/graph-cli@0.76.0, @graphprotocol/graph-cli@0.75.0...
5 years ago

Block, transaction and call handlers

Until now, the only triggers for indexing were events. This release adds support for triggering based on blocks and transactions/calls in the form of blockHandlers and callHandlers (in addition to the existing eventHandlers).

From the documentation:

Call Handlers

While events provide an effective way to collect relevant changes to the state of a contract, many contracts avoid generating logs to optimize gas costs. In these cases, a subgraph can subscribe to calls made to the data source contract. This is achieved by defining call handlers referencing the function signature and the mapping handler that will process calls to this function. To process these calls, the mapping handler will receive an EthereumCall as an argument with the typed inputs to and outputs from the call. Calls made at any depth in a transaction's call chain will trigger the mapping, allowing activity with the data source contract through proxy contracts to be captured.

To define a call handler in your manifest simply add a callHandlers array under the data source you would like to subscribe to.

callHandlers:
  - function: createGravatar(string,string)
    handler: handleCreateGravatar

For all applicable functions in contract ABIs, graph codegen now generates dedicated classes, e.g. CreateGravatarCall. These provide access to the address of the contract that was called, the block and transaction that the call happened in as well as typed inputs and outputs for function parameters and return values.

On block handlers:

Block Handlers

In addition to subscribing to contract events or function calls, a subgraph may want to update its data as new blocks are appended to the chain. To achieve this a subgraph can run a function after every block or after blocks that match a predefined filter.

The absense of a filter for a block handler will ensure that the handler is called every block.

A data source can only contain one block handler for each filter type.

blockHandlers:
  - handler: handleBlock
  - handler: handleBlockWithCallToContract
    filter:
      kind: call

For more information about how to define and write call and block handlers, please refer to the documentation.

Note: This feature requires Parity archive nodes with the trace API enabled.

Other changes

  • Fix graph init being called with --abi (#255, #256).
  • Disambiguate event, function, input, output and tuple member names in generated code (#168, #260).
  • Bump graph-ts in subgraphs created by graph init to 0.11.0 (#257).

Don't miss a new graph-tooling release

NewReleases is sending notifications on new releases.