-
Notifications
You must be signed in to change notification settings - Fork 672
/
masked_iterator.go
42 lines (34 loc) · 988 Bytes
/
masked_iterator.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
38
39
40
41
42
// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package state
import (
"github.com/ava-labs/avalanchego/ids"
)
var _ StakerIterator = &maskedIterator{}
type maskedIterator struct {
parentIterator StakerIterator
maskedStakers map[ids.ID]*Staker
}
// NewMaskedIterator returns a new iterator that skips the stakers in
// [parentIterator] that are present in [maskedStakers].
func NewMaskedIterator(parentIterator StakerIterator, maskedStakers map[ids.ID]*Staker) StakerIterator {
return &maskedIterator{
parentIterator: parentIterator,
maskedStakers: maskedStakers,
}
}
func (i *maskedIterator) Next() bool {
for i.parentIterator.Next() {
staker := i.parentIterator.Value()
if _, ok := i.maskedStakers[staker.TxID]; !ok {
return true
}
}
return false
}
func (i *maskedIterator) Value() *Staker {
return i.parentIterator.Value()
}
func (i *maskedIterator) Release() {
i.parentIterator.Release()
}