-
Notifications
You must be signed in to change notification settings - Fork 199
/
trieNodeInterceptorProcessor.go
53 lines (43 loc) · 1.83 KB
/
trieNodeInterceptorProcessor.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
package processor
import (
"github.com/ElrondNetwork/elrond-go/core"
"github.com/ElrondNetwork/elrond-go/core/check"
"github.com/ElrondNetwork/elrond-go/data/trie"
"github.com/ElrondNetwork/elrond-go/process"
"github.com/ElrondNetwork/elrond-go/storage"
)
var _ process.InterceptorProcessor = (*TrieNodeInterceptorProcessor)(nil)
// TrieNodeInterceptorProcessor is the processor used when intercepting trie nodes
type TrieNodeInterceptorProcessor struct {
interceptedNodes storage.Cacher
}
// NewTrieNodesInterceptorProcessor creates a new instance of TrieNodeInterceptorProcessor
func NewTrieNodesInterceptorProcessor(interceptedNodes storage.Cacher) (*TrieNodeInterceptorProcessor, error) {
if check.IfNil(interceptedNodes) {
return nil, process.ErrNilCacher
}
return &TrieNodeInterceptorProcessor{
interceptedNodes: interceptedNodes,
}, nil
}
// Validate checks if the intercepted data can be processed
func (tnip *TrieNodeInterceptorProcessor) Validate(_ process.InterceptedData, _ core.PeerID) error {
return nil
}
// Save saves the intercepted trie node in the intercepted nodes cacher
func (tnip *TrieNodeInterceptorProcessor) Save(data process.InterceptedData, _ core.PeerID, _ string) error {
nodeData, ok := data.(*trie.InterceptedTrieNode)
if !ok {
return process.ErrWrongTypeAssertion
}
tnip.interceptedNodes.Put(nodeData.Hash(), nodeData, len(nodeData.EncodedNode()))
return nil
}
// RegisterHandler registers a callback function to be notified of incoming trie nodes
func (tnip *TrieNodeInterceptorProcessor) RegisterHandler(_ func(topic string, hash []byte, data interface{})) {
log.Error("trieNodeInterceptorProcessor.RegisterHandler", "error", "not implemented")
}
// IsInterfaceNil returns true if there is no value under the interface
func (tnip *TrieNodeInterceptorProcessor) IsInterfaceNil() bool {
return tnip == nil
}