graph-node icon indicating copy to clipboard operation
graph-node copied to clipboard

[Feature] Allow getting and setting of indexed arguments / topic filters within handlers

Open sandbochs opened this issue 1 year ago • 0 comments

Description

The new indexed arguments filter is a big step forward in reducing indexing times when sifting through a large amount of events. This feature could be even more powerful as a dynamic datasource, similar to how templates operate. Ideally we could set the topic filter for a specific datasource at handler runtime. Alternatively, if we could specify templates with arguments, we could also create a new datasource and specify the topic.

Without understanding how the implementation actually works, being able to update an existing datasource seems like a more elegant solution (and a better solution for my use case). Three things would need to be exposed by graph-ts: Get Datasource, Read Topic Values, Set Topic Values. The API could look something like this:

// Since datasource names should be unique, these can be auto generated
import { DatasourceName } from '../generated'
import { Event } from '../generated/Contract/Contract'

export function handleEvent(event: Contract) {
  const eventHandlers = DatasourceName.getEventHandlers();
  const transferHandler = eventHandlers.filter(event => event.abi === 'Transfer(indexed address,indexed 
  address,uint256)');
  const topics = transferHandler.topics;
  transferHandler.topics = topics.concat([event.address.toHexString()]);
  transferHandler.save();
}

Are you aware of any blockers that must be resolved before implementing this feature? If so, which? Link to any relevant GitHub issues.

No response

Some information to help us out

  • [ ] Tick this box if you plan on implementing this feature yourself.
  • [X] I have searched the issue tracker to make sure this issue is not a duplicate.

sandbochs avatar Jul 31 '24 23:07 sandbochs