forked from smartcontractkit/chainlink
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlabeled_addresses.go
More file actions
45 lines (37 loc) · 1.09 KB
/
Copy pathlabeled_addresses.go
File metadata and controls
45 lines (37 loc) · 1.09 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
package deployment
import cldf "github.com/smartcontractkit/chainlink-deployments-framework/deployment"
// LabeledAddresses is an alias to a map whose keys are contract addresses
type LabeledAddresses map[string]cldf.TypeAndVersion
// And filters the LabeledAddresses to only include those entries that contain all
// labels. If labels is empty, then only unlabeled entries are returned.
func (la LabeledAddresses) And(labels ...string) LabeledAddresses {
var (
filtered = make(LabeledAddresses)
selectUnlabeled = len(labels) == 0
filterByLabels = len(labels) > 0
)
for addr, tv := range la {
// ignore labeled contracts by default
if selectUnlabeled && !tv.Labels.IsEmpty() {
continue
}
// ingore unlabeled contracts if labels are received
if filterByLabels && tv.Labels.IsEmpty() {
continue
}
if selectUnlabeled && tv.Labels.IsEmpty() {
filtered[addr] = tv
continue
}
if filterByLabels {
keep := true
for _, label := range labels {
keep = keep && tv.Labels.Contains(label)
}
if keep {
filtered[addr] = tv
}
}
}
return filtered
}