-
Notifications
You must be signed in to change notification settings - Fork 199
/
interceptedMetaHeaderDataFactory.go
92 lines (84 loc) · 3.4 KB
/
interceptedMetaHeaderDataFactory.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package factory
import (
"github.com/ElrondNetwork/elrond-go/core/check"
"github.com/ElrondNetwork/elrond-go/data/typeConverters"
"github.com/ElrondNetwork/elrond-go/hashing"
"github.com/ElrondNetwork/elrond-go/marshal"
"github.com/ElrondNetwork/elrond-go/process"
"github.com/ElrondNetwork/elrond-go/process/block/interceptedBlocks"
"github.com/ElrondNetwork/elrond-go/sharding"
)
var _ process.InterceptedDataFactory = (*interceptedMetaHeaderDataFactory)(nil)
type interceptedMetaHeaderDataFactory struct {
marshalizer marshal.Marshalizer
hasher hashing.Hasher
shardCoordinator sharding.Coordinator
headerSigVerifier process.InterceptedHeaderSigVerifier
headerIntegrityVerifier process.InterceptedHeaderIntegrityVerifier
chainID []byte
validityAttester process.ValidityAttester
epochStartTrigger process.EpochStartTriggerHandler
nonceConverter typeConverters.Uint64ByteSliceConverter
}
// NewInterceptedMetaHeaderDataFactory creates an instance of interceptedMetaHeaderDataFactory
func NewInterceptedMetaHeaderDataFactory(argument *ArgInterceptedDataFactory) (*interceptedMetaHeaderDataFactory, error) {
if argument == nil {
return nil, process.ErrNilArgumentStruct
}
if check.IfNil(argument.ProtoMarshalizer) {
return nil, process.ErrNilMarshalizer
}
if check.IfNil(argument.TxSignMarshalizer) {
return nil, process.ErrNilMarshalizer
}
if check.IfNil(argument.Hasher) {
return nil, process.ErrNilHasher
}
if check.IfNil(argument.ShardCoordinator) {
return nil, process.ErrNilShardCoordinator
}
if check.IfNil(argument.HeaderSigVerifier) {
return nil, process.ErrNilHeaderSigVerifier
}
if check.IfNil(argument.HeaderIntegrityVerifier) {
return nil, process.ErrNilHeaderIntegrityVerifier
}
if check.IfNil(argument.EpochStartTrigger) {
return nil, process.ErrNilEpochStartTrigger
}
if check.IfNil(argument.ValidityAttester) {
return nil, process.ErrNilValidityAttester
}
if check.IfNil(argument.NonceConverter) {
return nil, process.ErrNilUint64Converter
}
return &interceptedMetaHeaderDataFactory{
marshalizer: argument.ProtoMarshalizer,
hasher: argument.Hasher,
shardCoordinator: argument.ShardCoordinator,
headerSigVerifier: argument.HeaderSigVerifier,
headerIntegrityVerifier: argument.HeaderIntegrityVerifier,
validityAttester: argument.ValidityAttester,
epochStartTrigger: argument.EpochStartTrigger,
nonceConverter: argument.NonceConverter,
}, nil
}
// Create creates instances of InterceptedData by unmarshalling provided buffer
func (imhdf *interceptedMetaHeaderDataFactory) Create(buff []byte) (process.InterceptedData, error) {
arg := &interceptedBlocks.ArgInterceptedBlockHeader{
HdrBuff: buff,
Marshalizer: imhdf.marshalizer,
Hasher: imhdf.hasher,
ShardCoordinator: imhdf.shardCoordinator,
HeaderSigVerifier: imhdf.headerSigVerifier,
HeaderIntegrityVerifier: imhdf.headerIntegrityVerifier,
ValidityAttester: imhdf.validityAttester,
EpochStartTrigger: imhdf.epochStartTrigger,
NonceConverter: imhdf.nonceConverter,
}
return interceptedBlocks.NewInterceptedMetaHeader(arg)
}
// IsInterfaceNil returns true if there is no value under the interface
func (imhdf *interceptedMetaHeaderDataFactory) IsInterfaceNil() bool {
return imhdf == nil
}