-
Notifications
You must be signed in to change notification settings - Fork 4
/
store.go
52 lines (39 loc) · 1 KB
/
store.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
43
44
45
46
47
48
49
50
51
52
package memory
import (
"context"
"sync"
"github.com/pkg/errors"
"github.com/code-payments/code-server/pkg/code/data/airdrop"
)
type store struct {
mu sync.Mutex
ineligibleAidropOwners map[string]any
}
// New returns a new in memory airdrop.Store
func New() airdrop.Store {
return &store{
ineligibleAidropOwners: make(map[string]any),
}
}
// MarkIneligible implements airdrop.Store.MarkIneligible
func (s *store) MarkIneligible(ctx context.Context, owner string) error {
if len(owner) == 0 {
return errors.New("owner is required")
}
s.mu.Lock()
defer s.mu.Unlock()
s.ineligibleAidropOwners[owner] = struct{}{}
return nil
}
// IsEligible implements airdrop.Store.IsEligible
func (s *store) IsEligible(ctx context.Context, owner string) (bool, error) {
s.mu.Lock()
defer s.mu.Unlock()
_, isIneligible := s.ineligibleAidropOwners[owner]
return !isIneligible, nil
}
func (s *store) reset() {
s.mu.Lock()
defer s.mu.Unlock()
s.ineligibleAidropOwners = make(map[string]any)
}