-
Notifications
You must be signed in to change notification settings - Fork 197
/
peerAccountsDB.go
46 lines (41 loc) · 1.11 KB
/
peerAccountsDB.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
package state
import (
"sync"
"github.com/ElrondNetwork/elrond-go/data"
"github.com/ElrondNetwork/elrond-go/hashing"
"github.com/ElrondNetwork/elrond-go/marshal"
)
// PeerAccountsDB will save and synchronize data from peer processor, plus will synchronize with nodesCoordinator
type PeerAccountsDB struct {
*AccountsDB
}
// NewPeerAccountsDB creates a new account manager
func NewPeerAccountsDB(
trie data.Trie,
hasher hashing.Hasher,
marshalizer marshal.Marshalizer,
accountFactory AccountFactory,
) (*PeerAccountsDB, error) {
if trie == nil || trie.IsInterfaceNil() {
return nil, ErrNilTrie
}
if hasher == nil || hasher.IsInterfaceNil() {
return nil, ErrNilHasher
}
if marshalizer == nil || marshalizer.IsInterfaceNil() {
return nil, ErrNilMarshalizer
}
if accountFactory == nil || accountFactory.IsInterfaceNil() {
return nil, ErrNilAccountFactory
}
return &PeerAccountsDB{
&AccountsDB{
mainTrie: trie,
hasher: hasher,
marshalizer: marshalizer,
accountFactory: accountFactory,
entries: make([]JournalEntry, 0),
mutEntries: sync.RWMutex{},
},
}, nil
}