Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic Event Sub #39

Closed
ggwpez opened this issue Apr 8, 2021 · 0 comments · Fixed by #36
Closed

Generic Event Sub #39

ggwpez opened this issue Apr 8, 2021 · 0 comments · Fixed by #36
Labels
feature New Feature

Comments

@ggwpez
Copy link
Contributor

ggwpez commented Apr 8, 2021

Location: New Package [backend/eth/glue]

Motivation: As part of #19 we need a generic event subscription. It will then be used to build the generic reorg resistant event subscription.

Design: The current prototype implementation looks like this:
uml
uml.txt
EventFactory is defined as func() EventType since otherwise i would need to use reflections to clone the EventType.

Possible extensions:

  • Gas bumper
  • Rebroadcasting
  • Receipt polling
  • Persistence

Usage: Subscribing to all ERC20Approval events of the token contract would look like this:

factory := func() glue.EventType {
	return glue.EventType{
		Name: "Approval",
		Data: new(peruntoken.ERC20Approval),
	}
}

sub, _ := glue.NewEventSub(token.Contract(), factory, nil /* Start block is 0 */) // Error handling omitted
defer sub.Close()
sink := make(chan *glue.Event, 1)
go sub.Read(ctx, sink) // Error handling omitted

for _event := range sink {
	event := _event.Data.(*peruntoken.ERC20Approval)
	// Use event…
}

Testing: I already have a test to check that emitted events are received. This should be enough in combination with the additional reorg tests that i added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New Feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant