Documentation ¶
Overview ¶
Package subscription contains generic event subscriptions.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Event ¶
type Event struct { Name string // Name of the event. Must match the ABI definition. Data interface{} // Instance of the concrete Event type. Filter Filter // Filters Events by their body. Log types.Log // Raw original log for additional information. }
Event is a generic on-chain event.
type EventFactory ¶
type EventFactory func() *Event
EventFactory is used to create `Event`s. The `Data` and `Name` fields must be set. `Filter` is optional.
type EventSub ¶
type EventSub struct {
// contains filtered or unexported fields
}
EventSub generic event subscription. Can be used on any Contract with any Event. This EventSub does not prevent duplicates.
func NewEventSub ¶
func NewEventSub(ctx context.Context, chain ethereum.ChainReader, contract *bind.BoundContract, eFact EventFactory, pastBlocks uint64) (*EventSub, error)
NewEventSub creates a new `EventSub`. Should always be closed with `Close`. `pastBlocks` can be used to define how many blocks into the past the sub should query.
func (*EventSub) Close ¶
func (s *EventSub) Close()
Close closes the sub and frees associated resources. Can be called more than once. Is thread safe.
func (*EventSub) Read ¶
Read reads all past and future events into `sink`. Can be aborted by cancelling `ctx` or `Close()`. It is possible that the same event is read more than once. After casting the generic event to a specific type, the `Raw` log field will be nil. Use the `Log` field of the generic event instead.
func (*EventSub) ReadPast ¶
ReadPast reads all past events into `sink`. Can be aborted by cancelling `ctx` or `Close()`. It is possible that the same event is read more than once. After casting the generic event to a specific type, the `Raw` log field will be nil. Use the `Log` field of the generic event instead.
type Filter ¶
type Filter [][]interface{}
Filter can be used to filter events. Look at `TestEventSub_Filter` test or the auto generated Filter- and Watch-functions in the bindings/ folder for an example.
type ResistantEventSub ¶
type ResistantEventSub struct {
// contains filtered or unexported fields
}
ResistantEventSub wraps an `EventSub` and makes it resistant to chain reorgs. It handles `removed` and `rebirth` events and has a `finalityDepth` threshold to decide when an Event is final. It will never emit the same event twice.
func NewResistantEventSub ¶
func NewResistantEventSub(ctx context.Context, sub *EventSub, cr ethereum.ChainReader, finalityDepth uint64) (*ResistantEventSub, error)
NewResistantEventSub creates a new `ResistantEventSub` from the given `EventSub`. Closes the passed `EventSub` when done. `finalityDepth` defines in how many blocks an event needs to be included. `finalityDepth` cannot be smaller than 1. The passed `EventSub` should query more than `finalityDepth` blocks into the past.
func Subscribe ¶
func Subscribe(ctx context.Context, cr ethereum.ChainReader, contract *bind.BoundContract, eFact EventFactory, startBlockOffset, confirmations uint64) (*ResistantEventSub, error)
Subscribe is a convenience function which returns a `ResistantEventSub`. It is equivalent to manually calling `NewEventSub` and `NewResistantEventSub` with the given parameters.
func (*ResistantEventSub) Close ¶
func (s *ResistantEventSub) Close()
Close closes the sub and the underlying `EventSub`. Can be called more than once. Is thread safe.