erigon-pulse/ethdb/remote/remotedbserver/events.go
ledgerwatch c00f85ab6c
Simplification of eth_estimageGas (#1531)
* Simplification of eth_estimageGas

* Set GasCap by default

* Add a test

* Fix crash

Co-authored-by: Alexey Sharp <alexeysharp@Alexeys-iMac.local>
2021-03-02 22:47:44 +00:00

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