erigon-pulse/ethdb/remote/remotedbserver/events.go
Igor Mandrigin 393c9965ae
rpcdaemon: subscriptions, newHeads (#1359)
* fix `make grpc` on new checkouts

* update proto files

* add some stub

* prototype with fake events

* notifying about events

* pass events

* events are being sent

* transfer headers to filters

* create the “filters” struct

* implement new heads

* PoC of New Heads subscription

* fix keep alive

* fixups for the client

* add “type” to the event

* support header event type on client

* better stage refactor

* fixup for the eth backend

* fixups

* fix tests

* fix tests

* fix linters

* address comments

* remove unused log
2020-11-17 19:13:41 +00:00

36 lines
606 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 {
headerSubscription HeaderSubscription
}
func NewEvents() *Events {
return &Events{}
}
func (e *Events) AddHeaderSubscription(s HeaderSubscription) {
e.headerSubscription = s
}
func (e *Events) OnNewHeader(newHeader *types.Header) {
if e.headerSubscription == nil {
return
}
err := e.headerSubscription(newHeader)
if err != nil {
e.headerSubscription = nil
}
}