/
sync.go
55 lines (45 loc) · 1.27 KB
/
sync.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
53
54
55
package valkeystore
import (
"sync"
"github.com/Ecosystem-Knowledge/go-ecoterium/inter/validatorpk"
"github.com/Ecosystem-Knowledge/go-ecoterium/valkeystore/encryption"
)
type SyncedKeystore struct {
backend KeystoreI
mu sync.Mutex
}
func NewSyncedKeystore(backend KeystoreI) *SyncedKeystore {
return &SyncedKeystore{
backend: backend,
}
}
func (s *SyncedKeystore) Unlocked(pubkey validatorpk.PubKey) bool {
s.mu.Lock()
defer s.mu.Unlock()
return s.backend.Unlocked(pubkey)
}
func (s *SyncedKeystore) Has(pubkey validatorpk.PubKey) bool {
s.mu.Lock()
defer s.mu.Unlock()
return s.backend.Has(pubkey)
}
func (s *SyncedKeystore) Unlock(pubkey validatorpk.PubKey, auth string) error {
s.mu.Lock()
defer s.mu.Unlock()
return s.backend.Unlock(pubkey, auth)
}
func (s *SyncedKeystore) GetUnlocked(pubkey validatorpk.PubKey) (*encryption.PrivateKey, error) {
s.mu.Lock()
defer s.mu.Unlock()
return s.backend.GetUnlocked(pubkey)
}
func (s *SyncedKeystore) Add(pubkey validatorpk.PubKey, key []byte, auth string) error {
s.mu.Lock()
defer s.mu.Unlock()
return s.backend.Add(pubkey, key, auth)
}
func (s *SyncedKeystore) Get(pubkey validatorpk.PubKey, auth string) (*encryption.PrivateKey, error) {
s.mu.Lock()
defer s.mu.Unlock()
return s.backend.Get(pubkey, auth)
}