Repository navigation
Expand file tree
/
Copy pathfaucet.go
More file actions
74 lines (56 loc) · 1.54 KB
/
Copy pathfaucet.go
File metadata and controls
74 lines (56 loc) · 1.54 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
package stack
import (
"log/slog"
"github.com/ethereum-optimism/optimism/op-service/apis"
"github.com/ethereum-optimism/optimism/op-service/eth"
)
// FaucetID identifies a Faucet by name and chainID, is type-safe, and can be value-copied and used as map key.
type FaucetID idWithChain
var _ IDWithChain = (*FaucetID)(nil)
const FaucetKind Kind = "Faucet"
func NewFaucetID(key string, chainID eth.ChainID) FaucetID {
return FaucetID{
key: key,
chainID: chainID,
}
}
func (id FaucetID) String() string {
return idWithChain(id).string(FaucetKind)
}
func (id FaucetID) ChainID() eth.ChainID {
return idWithChain(id).chainID
}
func (id FaucetID) Kind() Kind {
return FaucetKind
}
func (id FaucetID) Key() string {
return id.key
}
func (id FaucetID) LogValue() slog.Value {
return slog.StringValue(id.String())
}
func (id FaucetID) MarshalText() ([]byte, error) {
return idWithChain(id).marshalText(FaucetKind)
}
func (id *FaucetID) UnmarshalText(data []byte) error {
return (*idWithChain)(id).unmarshalText(FaucetKind, data)
}
func SortFaucetIDs(ids []FaucetID) []FaucetID {
return copyAndSort(ids, func(a, b FaucetID) bool {
return lessIDWithChain(idWithChain(a), idWithChain(b))
})
}
func SortFaucets(elems []Faucet) []Faucet {
return copyAndSort(elems, func(a, b Faucet) bool {
return lessIDWithChain(idWithChain(a.ID()), idWithChain(b.ID()))
})
}
var _ FaucetMatcher = FaucetID{}
func (id FaucetID) Match(elems []Faucet) []Faucet {
return findByID(id, elems)
}
type Faucet interface {
Common
ID() FaucetID
API() apis.Faucet
}