-
Notifications
You must be signed in to change notification settings - Fork 199
/
interceptedTrieNodeDataFactory.go
50 lines (42 loc) · 1.58 KB
/
interceptedTrieNodeDataFactory.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
package factory
import (
"github.com/ElrondNetwork/elrond-go-core/core/check"
"github.com/ElrondNetwork/elrond-go-core/hashing"
"github.com/ElrondNetwork/elrond-go-core/marshal"
"github.com/ElrondNetwork/elrond-go/process"
"github.com/ElrondNetwork/elrond-go/trie"
)
var _ process.InterceptedDataFactory = (*interceptedTrieNodeDataFactory)(nil)
type interceptedTrieNodeDataFactory struct {
marshalizer marshal.Marshalizer
hasher hashing.Hasher
}
// NewInterceptedTrieNodeDataFactory creates an instance of interceptedTrieNodeDataFactory
func NewInterceptedTrieNodeDataFactory(
argument *ArgInterceptedDataFactory,
) (*interceptedTrieNodeDataFactory, error) {
if argument == nil {
return nil, process.ErrNilArgumentStruct
}
if check.IfNil(argument.CoreComponents) {
return nil, process.ErrNilCoreComponentsHolder
}
if check.IfNil(argument.CoreComponents.InternalMarshalizer()) {
return nil, process.ErrNilMarshalizer
}
if check.IfNil(argument.CoreComponents.Hasher()) {
return nil, process.ErrNilHasher
}
return &interceptedTrieNodeDataFactory{
marshalizer: argument.CoreComponents.InternalMarshalizer(),
hasher: argument.CoreComponents.Hasher(),
}, nil
}
// Create creates instances of InterceptedData by unmarshalling provided buffer
func (sidf *interceptedTrieNodeDataFactory) Create(buff []byte) (process.InterceptedData, error) {
return trie.NewInterceptedTrieNode(buff, sidf.marshalizer, sidf.hasher)
}
// IsInterfaceNil returns true if there is no value under the interface
func (sidf *interceptedTrieNodeDataFactory) IsInterfaceNil() bool {
return sidf == nil
}