forked from firedancer-io/radiance
-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathepoch_authorized_voters.go
More file actions
36 lines (29 loc) · 1.1 KB
/
epoch_authorized_voters.go
File metadata and controls
36 lines (29 loc) · 1.1 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
package epochstakes
import (
"github.com/gagliardetto/solana-go"
)
type EpochAuthorizedVotersCache struct {
authorizedVoters map[solana.PublicKey][]solana.PublicKey
}
func NewEpochAuthorizedVotersCache() *EpochAuthorizedVotersCache {
return &EpochAuthorizedVotersCache{authorizedVoters: make(map[solana.PublicKey][]solana.PublicKey)}
}
func (cache *EpochAuthorizedVotersCache) PutEntry(voteAcct solana.PublicKey, authorizedVoter solana.PublicKey) {
cache.authorizedVoters[voteAcct] = append(cache.authorizedVoters[voteAcct], authorizedVoter)
}
func (cache *EpochAuthorizedVotersCache) IsAuthorizedVoter(voteAcct solana.PublicKey, pubkey solana.PublicKey) bool {
for _, a := range cache.authorizedVoters[voteAcct] {
if a == pubkey {
return true
}
}
return false
}
// Entries returns the underlying map for serialization/persistence.
func (cache *EpochAuthorizedVotersCache) Entries() map[solana.PublicKey][]solana.PublicKey {
return cache.authorizedVoters
}
// Len returns the number of vote accounts in the cache.
func (cache *EpochAuthorizedVotersCache) Len() int {
return len(cache.authorizedVoters)
}