reorgdetector

package
v0.4.0-beta2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 31, 2024 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// DBPath is the path to the database
	DBPath string `mapstructure:"DBPath"`

	// CheckReorgsInterval is the interval to check for reorgs in tracked blocks
	CheckReorgsInterval types.Duration `mapstructure:"CheckReorgsInterval"`
}

Config is the configuration for the reorg detector

func (*Config) GetCheckReorgsInterval

func (c *Config) GetCheckReorgsInterval() time.Duration

GetCheckReorgsInterval returns the interval to check for reorgs in tracked blocks

type EthClient

type EthClient interface {
	SubscribeNewHead(ctx context.Context, ch chan<- *types.Header) (ethereum.Subscription, error)
	HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error)
	HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error)
}

type EthClientMock

type EthClientMock struct {
	mock.Mock
}

EthClientMock is an autogenerated mock type for the EthClient type

func NewEthClientMock

func NewEthClientMock(t interface {
	mock.TestingT
	Cleanup(func())
}) *EthClientMock

NewEthClientMock creates a new instance of EthClientMock. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*EthClientMock) HeaderByHash

func (_m *EthClientMock) HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error)

HeaderByHash provides a mock function with given fields: ctx, hash

func (*EthClientMock) HeaderByNumber

func (_m *EthClientMock) HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error)

HeaderByNumber provides a mock function with given fields: ctx, number

func (*EthClientMock) SubscribeNewHead

func (_m *EthClientMock) SubscribeNewHead(ctx context.Context, ch chan<- *types.Header) (ethereum.Subscription, error)

SubscribeNewHead provides a mock function with given fields: ctx, ch

type ReorgDetector

type ReorgDetector struct {
	// contains filtered or unexported fields
}

func New

func New(client EthClient, cfg Config) (*ReorgDetector, error)

func (*ReorgDetector) AddBlockToTrack

func (rd *ReorgDetector) AddBlockToTrack(ctx context.Context, id string, num uint64, hash common.Hash) error

AddBlockToTrack adds a block to the tracked list for a subscriber

func (*ReorgDetector) Start

func (rd *ReorgDetector) Start(ctx context.Context) (err error)

Start starts the reorg detector

func (*ReorgDetector) Subscribe

func (rd *ReorgDetector) Subscribe(id string) (*Subscription, error)

Subscribe subscribes to reorg events

type Subscription

type Subscription struct {
	ReorgedBlock   chan uint64
	ReorgProcessed chan bool
}

Subscription is a subscription to reorg events

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL