silverback
silverback copied to clipboard
feat: event arg filtering
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)
Tested this and got pretty good results!
Add some test cases, and this is probably close to merge
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?
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)
PR #66 resolves the "no duplicate handlers" situation, which makes it easier to solve the issue I noted of missing task registrations
Rebased and made updates to use new stateless TaskData setup
TODO:
- [ ] figure out why it keeps failing to start
replaced by #233