-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
block_translator.go
37 lines (30 loc) · 1.26 KB
/
block_translator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package ocrcommon
import (
"context"
"math/big"
"github.com/smartcontractkit/chainlink/core/chains"
evmclient "github.com/smartcontractkit/chainlink/core/chains/evm/client"
evmtypes "github.com/smartcontractkit/chainlink/core/chains/evm/types"
"github.com/smartcontractkit/chainlink/core/logger"
)
// BlockTranslator converts emitted block numbers (from block.number) into a
// block number range suitable for query in FilterLogs
type BlockTranslator interface {
NumberToQueryRange(ctx context.Context, changedInL1Block uint64) (fromBlock *big.Int, toBlock *big.Int)
}
// NewBlockTranslator returns the block translator for the given chain
func NewBlockTranslator(cfg Config, client evmclient.Client, lggr logger.Logger) BlockTranslator {
switch cfg.ChainType() {
case chains.Arbitrum:
return NewArbitrumBlockTranslator(client, lggr)
case chains.XDai, chains.ExChain, chains.Optimism:
fallthrough
default:
return &l1BlockTranslator{}
}
}
type l1BlockTranslator struct{}
func (*l1BlockTranslator) NumberToQueryRange(_ context.Context, changedInL1Block uint64) (fromBlock *big.Int, toBlock *big.Int) {
return big.NewInt(int64(changedInL1Block)), big.NewInt(int64(changedInL1Block))
}
func (*l1BlockTranslator) OnNewLongestChain(context.Context, *evmtypes.Head) {}