-
Notifications
You must be signed in to change notification settings - Fork 884
/
store_mem.go
55 lines (44 loc) · 985 Bytes
/
store_mem.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 nodebuilder
import (
"sync"
"github.com/ipfs/go-datastore"
ds_sync "github.com/ipfs/go-datastore/sync"
"github.com/celestiaorg/celestia-node/libs/keystore"
)
type memStore struct {
keys keystore.Keystore
data datastore.Batching
cfg *Config
cfgL sync.Mutex
}
// NewMemStore creates an in-memory Store for Node.
// Useful for testing.
func NewMemStore() Store {
return &memStore{
keys: keystore.NewMapKeystore(),
data: ds_sync.MutexWrap(datastore.NewMapDatastore()),
}
}
func (m *memStore) Keystore() (keystore.Keystore, error) {
return m.keys, nil
}
func (m *memStore) Datastore() (datastore.Batching, error) {
return m.data, nil
}
func (m *memStore) Config() (*Config, error) {
m.cfgL.Lock()
defer m.cfgL.Unlock()
return m.cfg, nil
}
func (m *memStore) PutConfig(cfg *Config) error {
m.cfgL.Lock()
defer m.cfgL.Unlock()
m.cfg = cfg
return nil
}
func (m *memStore) Path() string {
return ""
}
func (m *memStore) Close() error {
return nil
}