silverback icon indicating copy to clipboard operation
silverback copied to clipboard

feat: event arg filtering

Open mikeshultz opened this issue 1 year ago • 6 comments

What I did

Adds event filtering by event argument. For example:

@app.on_(USDC.Transfer, start_block=18588777, to="0x0000000000000000000000000000000000000000")
def handle_burn(log):
    return {"burned": log.value}

Will only handle USDC burn events.

fixes: #54 fixes: SBK-417

How I did it

Expands taskiq task definitions to be input arg & value specific by hashing the inputs and using it as a name suffix. When an event is received, it's checked against known event handlers and their filters (if they exist) before sending them along.

How to verify it

Run the example app. Burn events are not uncommon.

Checklist

  • [X] Passes all linting checks (pre-commit and CI jobs)
  • [ ] New test cases have been added and are passing
  • [x] Documentation has been updated
  • [x] PR title follows Conventional Commit standard (will be automatically included in the changelog)

mikeshultz avatar Feb 22 '24 06:02 mikeshultz

Tested this and got pretty good results!

Add some test cases, and this is probably close to merge

fubuloubu avatar Feb 23 '24 02:02 fubuloubu

Add some test cases, and this is probably close to merge

There are no tests yet in this repo. Perhaps that should be a separate project?

mikeshultz avatar Feb 23 '24 07:02 mikeshultz

One issue noted during testing: if you have multiple tasks against the same event/filter arg combo (same named filter arg but different filter values) the second one does not appear to function

This can be potentially resolved in another PR (breaking change) that should make it so there can be multiple handlers defined for a specific subscription (will make this an issue but the previous problem should be solved in some way here)

fubuloubu avatar Mar 04 '24 18:03 fubuloubu

PR #66 resolves the "no duplicate handlers" situation, which makes it easier to solve the issue I noted of missing task registrations

fubuloubu avatar Apr 08 '24 21:04 fubuloubu

Rebased and made updates to use new stateless TaskData setup

TODO:

  • [ ] figure out why it keeps failing to start

fubuloubu avatar May 31 '24 22:05 fubuloubu

replaced by #233

fubuloubu avatar Apr 24 '25 00:04 fubuloubu