mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2025-01-01 08:41:21 +00:00
a583f7f6ca
Co-authored-by: Alexey Sharp <alexeysharp@Alexeys-iMac.local>
39 lines
868 B
Go
39 lines
868 B
Go
package remotedbserver
|
|
|
|
import (
|
|
"github.com/ledgerwatch/turbo-geth/core/types"
|
|
)
|
|
|
|
type RpcEventType uint64
|
|
|
|
const (
|
|
EventTypeHeader = RpcEventType(iota)
|
|
)
|
|
|
|
type HeaderSubscription func(*types.Header) error
|
|
|
|
type Events struct {
|
|
headerSubscriptions []HeaderSubscription
|
|
}
|
|
|
|
func NewEvents() *Events {
|
|
return &Events{}
|
|
}
|
|
|
|
func (e *Events) AddHeaderSubscription(s HeaderSubscription) {
|
|
e.headerSubscriptions = append(e.headerSubscriptions, s)
|
|
}
|
|
|
|
func (e *Events) OnNewHeader(newHeader *types.Header) {
|
|
for i, sub := range e.headerSubscriptions {
|
|
if err := sub(newHeader); err != nil {
|
|
// remove subscription
|
|
if i == len(e.headerSubscriptions)-1 {
|
|
e.headerSubscriptions = e.headerSubscriptions[:i]
|
|
} else if i < len(e.headerSubscriptions)-1 {
|
|
e.headerSubscriptions = append(e.headerSubscriptions[:i], e.headerSubscriptions[i+1:]...)
|
|
}
|
|
}
|
|
}
|
|
}
|