-
Notifications
You must be signed in to change notification settings - Fork 11
/
iter.go
37 lines (32 loc) · 994 Bytes
/
iter.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 llmq
import "github.com/dashpay/tenderdash/crypto"
// Iter creates and returns LLMQ iterator
func (l *Data) Iter() *Iter {
return &Iter{data: l}
}
// Iter is an iterator implementation
// this iterator go through the proTxHash and validator quorum-keys (like: private and public share keys)
type Iter struct {
proTxHash crypto.ProTxHash
quorumKeys crypto.QuorumKeys
data *Data
pos int
}
// Value returns node's crypto.ProTxHash and crypto.QuorumKeys from the current position
func (i *Iter) Value() (crypto.ProTxHash, crypto.QuorumKeys) {
return i.proTxHash, i.quorumKeys
}
// Next moves a position pointer to a next element
func (i *Iter) Next() bool {
if i.pos >= len(i.data.ProTxHashes) {
return false
}
i.proTxHash = i.data.ProTxHashes[i.pos]
i.quorumKeys = crypto.QuorumKeys{
PrivKey: i.data.PrivKeyShares[i.pos],
PubKey: i.data.PubKeyShares[i.pos],
ThresholdPublicKey: i.data.ThresholdPubKey,
}
i.pos++
return true
}