Repository navigation
Expand file tree
/
Copy pathl2_el.go
More file actions
77 lines (58 loc) · 1.69 KB
/
Copy pathl2_el.go
File metadata and controls
77 lines (58 loc) · 1.69 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package stack
import (
"log/slog"
"github.com/ethereum-optimism/optimism/op-service/apis"
"github.com/ethereum-optimism/optimism/op-service/eth"
)
// L2ELNodeID identifies a L2ELNode by name and chainID, is type-safe, and can be value-copied and used as map key.
type L2ELNodeID idWithChain
var _ IDWithChain = (*L2ELNodeID)(nil)
const L2ELNodeKind Kind = "L2ELNode"
func NewL2ELNodeID(key string, chainID eth.ChainID) L2ELNodeID {
return L2ELNodeID{
key: key,
chainID: chainID,
}
}
func (id L2ELNodeID) String() string {
return idWithChain(id).string(L2ELNodeKind)
}
func (id L2ELNodeID) ChainID() eth.ChainID {
return id.chainID
}
func (id L2ELNodeID) Kind() Kind {
return L2ELNodeKind
}
func (id L2ELNodeID) Key() string {
return id.key
}
func (id L2ELNodeID) LogValue() slog.Value {
return slog.StringValue(id.String())
}
func (id L2ELNodeID) MarshalText() ([]byte, error) {
return idWithChain(id).marshalText(L2ELNodeKind)
}
func (id *L2ELNodeID) UnmarshalText(data []byte) error {
return (*idWithChain)(id).unmarshalText(L2ELNodeKind, data)
}
func SortL2ELNodeIDs(ids []L2ELNodeID) []L2ELNodeID {
return copyAndSort(ids, func(a, b L2ELNodeID) bool {
return lessIDWithChain(idWithChain(a), idWithChain(b))
})
}
func SortL2ELNodes(elems []L2ELNode) []L2ELNode {
return copyAndSort(elems, func(a, b L2ELNode) bool {
return lessIDWithChain(idWithChain(a.ID()), idWithChain(b.ID()))
})
}
var _ L2ELMatcher = L2ELNodeID{}
func (id L2ELNodeID) Match(elems []L2ELNode) []L2ELNode {
return findByID(id, elems)
}
// L2ELNode is a L2 ethereum execution-layer node
type L2ELNode interface {
ID() L2ELNodeID
L2EthClient() apis.L2EthClient
L2EngineClient() apis.EngineClient
ELNode
}