erigon-pulse/ethdb/remote/remotedbserver/events.go
2021-02-12 16:46:50 +00:00

35 lines
718 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
e.headerSubscriptions = append(e.headerSubscriptions[:i], e.headerSubscriptions[i+1:]...)
}
}
}