Documentation ¶
Index ¶
- Constants
- Variables
- func GetSourceID(chainId *big.Int, sourceAddr common.Address, contractType string, ...) string
- type Backend
- type BlockHeadProducer
- type ClientFactory
- type EventHandler
- type EventIterator
- type EventTransformer
- type EventWatcher
- type EventWatcherOpts
- type FailureRetryOpts
- type FinalisedEventWatcher
- type GPACTEventTransformer
- type GPACTFinalisedEventWatcher
- type GPACTRealtimeEventWatcher
- type GpactRootEventIterator
- type GpactSegmentEventIterator
- type GpactStartEventIterator
- type LogEventHandler
- type MessageEnqueueHandler
- type MessageHandler
- type MultiSourceObserver
- func (o *MultiSourceObserver) IsRunning() bool
- func (o *MultiSourceObserver) Start() error
- func (o *MultiSourceObserver) StartObservation(chainID *big.Int, chainAP string, contractType string, ...) error
- func (o *MultiSourceObserver) Stop()
- func (o *MultiSourceObserver) StopObservation(chainID *big.Int, contractType string, contractAddr common.Address, ...) error
- type Observer
- type SFCCrossCallFinalisedEventWatcher
- type SFCCrossCallRealtimeEventWatcher
- type SFCEventTransformer
- type SimpleEventHandler
- type SingleSourceObserver
- func NewGPACTFinalisedObserver(chainId *big.Int, sourceAddr common.Address, contract *functioncall.Gpact, ...) (*SingleSourceObserver, error)
- func NewGPACTRealtimeObserver(chainId *big.Int, sourceAddr common.Address, contract *functioncall.Gpact, ...) (*SingleSourceObserver, error)
- func NewSFCFinalisedObserver(chainId *big.Int, sourceAddr common.Address, contract *functioncall.Sfc, ...) (*SingleSourceObserver, error)
- func NewSFCRealtimeObserver(chainId *big.Int, sourceAddr common.Address, contract *functioncall.Sfc, ...) (*SingleSourceObserver, error)
- type WatcherProgressDsOpts
- type WatcherType
Constants ¶
const MessageIDPattern = "%s-%#x-%d-%d-%d"
Variables ¶
var DefaultRetryOptions = FailureRetryOpts{ RetryAttempts: 5, RetryDelay: 300 * time.Millisecond, }
Functions ¶
func GetSourceID ¶
Types ¶
type Backend ¶
type Backend interface { ethereum.ChainReader bind.ContractBackend }
type BlockHeadProducer ¶
type ClientFactory ¶
type EventHandler ¶
type EventHandler interface {
Handle(event interface{})
}
type EventIterator ¶
type EventIterator interface { Next() bool GetEvent() interface{} }
type EventTransformer ¶
type EventWatcher ¶
type EventWatcher interface { // Watch starts the listening to relevant events Watch() error // StopWatcher stops the listening to events StopWatcher() }
EventWatcher listens to blockchain events
type EventWatcherOpts ¶
type EventWatcherOpts struct { // Start is the block number to start watching from. This might be superseded by a saved checkpoint if one is available. Start uint64 // EventHandler the handler that will process each blockchain event EventHandler EventHandler Context context.Context }
EventWatcherOpts encapsulates common options used to configure an EventWatcher
type FailureRetryOpts ¶
type FinalisedEventWatcher ¶
type FinalisedEventWatcher struct { EventWatcherOpts WatcherProgressOpts WatcherProgressDsOpts // EventHandleRetryOpts specifies how retries will be attempted if fetching or processing events fails EventHandleRetryOpts FailureRetryOpts // contains filtered or unexported fields }
FinalisedEventWatcher listens to events from a bridge and processes them only once they are 'finalised'. An event is considered 'finalised' once it receives a configurable number of block confirmations. An event has one block confirmation the instant it is mined into a block.
func (*FinalisedEventWatcher) GetNextBlockToProcess ¶
func (l *FinalisedEventWatcher) GetNextBlockToProcess() uint64
func (*FinalisedEventWatcher) GetSavedProgress ¶
func (l *FinalisedEventWatcher) GetSavedProgress() (uint64, error)
GetSavedProgress fetches the last processed block number that has been persisted to the datastore. This value is updated in the datastore each time the watcher processes new blocks ( see `processFinalisedEvents(...)`). returns an error if querying the datastore or deserialising the result fails.
func (*FinalisedEventWatcher) StopWatcher ¶
func (l *FinalisedEventWatcher) StopWatcher()
func (*FinalisedEventWatcher) Watch ¶
func (l *FinalisedEventWatcher) Watch() error
Watch subscribes and starts listening to 'CrossCall' events from a given 'Simple Function Call' contract. Once an events receives sufficient block confirmations, it is passed to an event handler for processing.
type GPACTEventTransformer ¶
func NewGPACTEventTransformer ¶
func NewGPACTEventTransformer(chainId *big.Int, contractAddress common.Address) *GPACTEventTransformer
type GPACTFinalisedEventWatcher ¶
type GPACTFinalisedEventWatcher struct { FinalisedEventWatcher Contract *functioncall.Gpact }
GPACTFinalisedEventWatcher listens to events from a `Gpact` bridge contract and processes them only once they are 'finalised'. It specifically listens to three types of GPACT events: `GpactStart`, `GpactSegment` and `GpactRoot` events. An event is considered 'finalised' once it receives a configurable number of block confirmations. An event has one block confirmation the instant it is mined into a block.
func NewGPACTFinalisedEventWatcher ¶
func NewGPACTFinalisedEventWatcher(watcherOpts EventWatcherOpts, watchProgressDbOpts WatcherProgressDsOpts, handlerRetryOpts FailureRetryOpts, confirmsForFinality uint64, contract *functioncall.Gpact, client BlockHeadProducer) (*GPACTFinalisedEventWatcher, error)
NewGPACTFinalisedEventWatcher creates a GPACTFinalisedEventWatcher instance that processes events only once they receive sufficient number of confirmations.The first block confirmation is achieved when the event is mined. Throws an error if the provided number of confirmations is 0
type GPACTRealtimeEventWatcher ¶
type GPACTRealtimeEventWatcher struct { EventWatcherOpts RemovedEventHandler EventHandler GpactContract *functioncall.Gpact // contains filtered or unexported fields }
GPACTRealtimeEventWatcher subscribes and listens to three types of GPACT events: `GpactStart`, `GpactSegment` and `GpactRoot` events. The events produced by this watcher are generated the instant they are mined (i.e. 1 confirmation). The progress of this watcher is not persisted, and will always start from either EventWatcherOps.Start block if provided or the latest block if not. The watcher does not check to see if the event is affected by any reorgs.
func NewGPACTRealtimeEventWatcher ¶
func NewGPACTRealtimeEventWatcher(watcherOpts EventWatcherOpts, removedEventHandler EventHandler, contract *functioncall.Gpact) (*GPACTRealtimeEventWatcher, error)
NewGPACTRealtimeEventWatcher creates an instance of GPACTRealtimeEventWatcher Throws an error if the provided even handler or the removed event handler is nil.
func (*GPACTRealtimeEventWatcher) StopWatcher ¶
func (l *GPACTRealtimeEventWatcher) StopWatcher()
func (*GPACTRealtimeEventWatcher) Watch ¶
func (l *GPACTRealtimeEventWatcher) Watch() error
Watch subscribes and starts listening to `GpactStart`, `GpactSegment` and `GpactRoot` events from a given `Gpact` bridge contract. Events received are passed to an event handler for processing. The method fails if subscribing to the event with the underlying network fails.
type GpactRootEventIterator ¶
type GpactRootEventIterator struct {
*functioncall.GpactRootIterator
}
func (*GpactRootEventIterator) GetEvent ¶
func (e *GpactRootEventIterator) GetEvent() interface{}
type GpactSegmentEventIterator ¶
type GpactSegmentEventIterator struct {
*functioncall.GpactSegmentIterator
}
func (*GpactSegmentEventIterator) GetEvent ¶
func (e *GpactSegmentEventIterator) GetEvent() interface{}
type GpactStartEventIterator ¶
type GpactStartEventIterator struct {
*functioncall.GpactStartIterator
}
func (*GpactStartEventIterator) GetEvent ¶
func (e *GpactStartEventIterator) GetEvent() interface{}
type LogEventHandler ¶
type LogEventHandler struct {
LogMessagePrefix string
}
LogEventHandler logs the details of a given event at an `Info` level
func NewLogEventHandler ¶
func NewLogEventHandler(logPrefix string) *LogEventHandler
func (*LogEventHandler) Handle ¶
func (h *LogEventHandler) Handle(event interface{})
type MessageEnqueueHandler ¶
type MessageEnqueueHandler struct { MQ mqserver.MessageQueue FailureRetryOpts }
MessageEnqueueHandler enqueues relayer messages onto a configured message queue server
func NewMessageEnqueueHandler ¶
func NewMessageEnqueueHandler(qServer mqserver.MessageQueue, retryOpts FailureRetryOpts) *MessageEnqueueHandler
func (*MessageEnqueueHandler) Handle ¶
func (h *MessageEnqueueHandler) Handle(m *v1.Message)
Handle sends the provided message to the configured message queue. If sending the message fails, it is retried `MessageEnqueueHandler.retryAttempts` times. The method assumes that the message queue is configured and started.
type MessageHandler ¶
MessageHandler processes relayer messages
type MultiSourceObserver ¶
type MultiSourceObserver struct {
// contains filtered or unexported fields
}
MultiSourceObserver is an observer that can observe multiple different event sources. It creates and manages distinct SingleSourceObserver instances for each event source. The contract persists the list of event sources it tracks. In the event of a restart, the observer resumes observation of the persisted sources.
func NewMultiSourceObserver ¶
func NewMultiSourceObserver(dsPath string, mq mqserver.MessageQueue, clientFactory ClientFactory) (*MultiSourceObserver, error)
NewMultiSourceObserver creates a new MultiSourceObserver instance
func (*MultiSourceObserver) IsRunning ¶
func (o *MultiSourceObserver) IsRunning() bool
func (*MultiSourceObserver) Start ¶
func (o *MultiSourceObserver) Start() error
Start starts the multisource observer. If there are past observations stored in the database, this function creates and starts observers for each of those observations.
func (*MultiSourceObserver) StartObservation ¶
func (o *MultiSourceObserver) StartObservation(chainID *big.Int, chainAP string, contractType string, contractAddr common.Address, watcherType WatcherType) error
StartObservation starts a new observer for the provided event source If an observer associated with the event source already exists, the method ensures it is started.
func (*MultiSourceObserver) Stop ¶
func (o *MultiSourceObserver) Stop()
Stop stops all observers that the multi-source observer manages
func (*MultiSourceObserver) StopObservation ¶
func (o *MultiSourceObserver) StopObservation(chainID *big.Int, contractType string, contractAddr common.Address, watcherType WatcherType) error
StopObservation stops the observer associated with the given event source if one exists and is currently running.
type Observer ¶
type Observer interface { // Start starts the observer's routine. Start() error // Stop safely stops the observer. Stop() // StartObservation starts a new observer for the specified source StartObservation(chainID *big.Int, chainAP string, contractType string, contractAddr common.Address) error // StopObserve stops observe. StopObserve() error // IsRunning returns true if the observer is running IsRunning() bool }
Observer is an interface for the observer.
type SFCCrossCallFinalisedEventWatcher ¶
type SFCCrossCallFinalisedEventWatcher struct { FinalisedEventWatcher Contract *functioncall.Sfc }
SFCCrossCallFinalisedEventWatcher listens to events from a `Sfc`( Simple Function Call) bridge contract and processes them only once they are 'finalised'. An event is considered 'finalised' once it receives a configurable number of block confirmations. An event has one block confirmation the instant it is mined into a block.
func NewSFCCrossCallFinalisedEventWatcher ¶
func NewSFCCrossCallFinalisedEventWatcher(watcherOpts EventWatcherOpts, watchProgressDbOpts WatcherProgressDsOpts, handlerRetryOpts FailureRetryOpts, confirmsForFinality uint64, contract *functioncall.Sfc, client BlockHeadProducer) (*SFCCrossCallFinalisedEventWatcher, error)
NewSFCCrossCallFinalisedEventWatcher creates an `SFCCrossCall` event watcher that processes events only once they receive sufficient confirmations. The first block confirmation is achieved when the event is mined.
type SFCCrossCallRealtimeEventWatcher ¶
type SFCCrossCallRealtimeEventWatcher struct { EventWatcherOpts // RemovedEventHandler handles events that have been affected by a reorg and are no longer a part of the canonical chain RemovedEventHandler EventHandler SfcContract *functioncall.Sfc // contains filtered or unexported fields }
SFCCrossCallRealtimeEventWatcher subscribes and listens to events from a `Sfc`(Simple Function Call) bridge contract. The events produced by this watcher are generated the instant they are mined (i.e. 1 confirmation). The progress of this watcher is not persisted, and will always start from either EventWatcherOps.Start block if provided or the latest block if not. The watcher does not check to see if the event is affected by any reorgs.
func NewSFCCrossCallRealtimeEventWatcher ¶
func NewSFCCrossCallRealtimeEventWatcher(watcherOpts EventWatcherOpts, removedEventHandler EventHandler, contract *functioncall.Sfc) (*SFCCrossCallRealtimeEventWatcher, error)
NewSFCCrossCallRealtimeEventWatcher creates an instance of SFCCrossCallRealtimeEventWatcher. Throws an error if the provided even handler or the removed event handler is nil.
func (*SFCCrossCallRealtimeEventWatcher) StopWatcher ¶
func (l *SFCCrossCallRealtimeEventWatcher) StopWatcher()
func (*SFCCrossCallRealtimeEventWatcher) Watch ¶
func (l *SFCCrossCallRealtimeEventWatcher) Watch() error
Watch subscribes and starts listening to 'CrossCall' events from a given `Sfc`(Simple Function Call) contract. Events received are passed to an event handler for processing. The method fails if subscribing to the event with the underlying network fails.
type SFCEventTransformer ¶
SFCEventTransformer converts events from a simple-function-call bridge contract to relayer messages
func NewSFCEventTransformer ¶
func NewSFCEventTransformer(chainId *big.Int, sourceAddr common.Address) *SFCEventTransformer
func (*SFCEventTransformer) ToMessage ¶
func (t *SFCEventTransformer) ToMessage(event interface{}) (*v1.Message, error)
ToMessage converts a 'CrossCall' event emited from a simple-function-call bridge contract to relayer message It returns an error if the event contains an invalid timestamp or destination information It panics if the event is not of an sfc.SfcCrossCall type
type SimpleEventHandler ¶
type SimpleEventHandler struct { // EventTransformer transforms a given event to a relayer message (v1.Message) EventTransformer EventTransformer // MessageHandler processes a relayer message that has been created from a event MessageHandler MessageHandler }
SimpleEventHandler first transforms an event to a relayer message then passes it to a message handler to process
func NewSimpleEventHandler ¶
func NewSimpleEventHandler(transformer EventTransformer, sender MessageHandler) *SimpleEventHandler
func (*SimpleEventHandler) Handle ¶
func (h *SimpleEventHandler) Handle(event interface{})
Handle transforms the provided event to a message then forwards it to a message handler to process.
type SingleSourceObserver ¶
type SingleSourceObserver struct { SourceId string SourceNetworkId *big.Int EventWatcher EventWatcher EventHandler EventHandler // contains filtered or unexported fields }
SingleSourceObserver is an Observer that listens to events from a given source contract, transforms them into Relayer messages and then enqueues them onto a message queue for further processing by the Relayer core component.
func NewGPACTFinalisedObserver ¶
func NewGPACTFinalisedObserver(chainId *big.Int, sourceAddr common.Address, contract *functioncall.Gpact, mq mqserver.MessageQueue, confirmationsForFinality uint64, watcherProgressOpts WatcherProgressDsOpts, client BlockHeadProducer) ( *SingleSourceObserver, error)
NewGPACTFinalisedObserver creates an instance of SingleSourceObserver that monitors a gpact-function-call bridge contract events. The observer processes events only once they receive a configured number of confirmations.
func NewGPACTRealtimeObserver ¶
func NewGPACTRealtimeObserver(chainId *big.Int, sourceAddr common.Address, contract *functioncall.Gpact, mq mqserver.MessageQueue) (*SingleSourceObserver, error)
NewGPACTRealtimeObserver creates an instance of SingleSourceObserver that monitors a GPACT bridge contract. The observer processes events as they are emitted (realtime), without awaiting finalisation.
func NewSFCFinalisedObserver ¶
func NewSFCFinalisedObserver(chainId *big.Int, sourceAddr common.Address, contract *functioncall.Sfc, mq mqserver.MessageQueue, confirmationsForFinality uint64, watcherProgressOpts WatcherProgressDsOpts, client BlockHeadProducer) ( *SingleSourceObserver, error)
NewSFCFinalisedObserver creates an instance of SingleSourceObserver that monitors a simple-function-call bridge contract events. The observer processes events only once they receive a configured number of confirmations.
func NewSFCRealtimeObserver ¶
func NewSFCRealtimeObserver(chainId *big.Int, sourceAddr common.Address, contract *functioncall.Sfc, mq mqserver.MessageQueue) (*SingleSourceObserver, error)
NewSFCRealtimeObserver creates an instance of SingleSourceObserver that monitors a simple-function-call bridge contract events. The observer processes events as they are emitted (realtime), without awaiting finalisation.
func (*SingleSourceObserver) IsRunning ¶
func (o *SingleSourceObserver) IsRunning() bool
IsRunning returns true if the observer is running
func (*SingleSourceObserver) Start ¶
func (o *SingleSourceObserver) Start() error
Start starts the observer monitoring of the assigned source.
func (*SingleSourceObserver) Stop ¶
func (o *SingleSourceObserver) Stop()
Stop stops the observer monitoring the assigned source.
type WatcherProgressDsOpts ¶
type WatcherProgressDsOpts struct { FailureRetryOpts // configuration for how retries will be performed if persisting progress fails // contains filtered or unexported fields }
WatcherProgressDsOpts encapsulates configuration details for persisting the progress of a watcher
type WatcherType ¶
type WatcherType string
const ( RealtimeWatcher WatcherType = "realtime" FinalisedWatcher WatcherType = "finalised" )