-
Notifications
You must be signed in to change notification settings - Fork 199
/
interceptedTxDataFactory.go
93 lines (86 loc) · 2.97 KB
/
interceptedTxDataFactory.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
93
package factory
import (
"github.com/ElrondNetwork/elrond-go/core"
"github.com/ElrondNetwork/elrond-go/core/check"
"github.com/ElrondNetwork/elrond-go/crypto"
"github.com/ElrondNetwork/elrond-go/hashing"
"github.com/ElrondNetwork/elrond-go/marshal"
"github.com/ElrondNetwork/elrond-go/process"
"github.com/ElrondNetwork/elrond-go/process/transaction"
"github.com/ElrondNetwork/elrond-go/sharding"
)
var _ process.InterceptedDataFactory = (*interceptedTxDataFactory)(nil)
type interceptedTxDataFactory struct {
protoMarshalizer marshal.Marshalizer
signMarshalizer marshal.Marshalizer
hasher hashing.Hasher
keyGen crypto.KeyGenerator
singleSigner crypto.SingleSigner
pubkeyConverter core.PubkeyConverter
shardCoordinator sharding.Coordinator
feeHandler process.FeeHandler
whiteListerVerifiedTxs process.WhiteListHandler
}
// NewInterceptedTxDataFactory creates an instance of interceptedTxDataFactory
func NewInterceptedTxDataFactory(argument *ArgInterceptedDataFactory) (*interceptedTxDataFactory, 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.KeyGen) {
return nil, process.ErrNilKeyGen
}
if check.IfNil(argument.Signer) {
return nil, process.ErrNilSingleSigner
}
if check.IfNil(argument.AddressPubkeyConv) {
return nil, process.ErrNilPubkeyConverter
}
if check.IfNil(argument.ShardCoordinator) {
return nil, process.ErrNilShardCoordinator
}
if check.IfNil(argument.FeeHandler) {
return nil, process.ErrNilEconomicsFeeHandler
}
if check.IfNil(argument.WhiteListerVerifiedTxs) {
return nil, process.ErrNilWhiteListHandler
}
return &interceptedTxDataFactory{
protoMarshalizer: argument.ProtoMarshalizer,
signMarshalizer: argument.TxSignMarshalizer,
hasher: argument.Hasher,
keyGen: argument.KeyGen,
singleSigner: argument.Signer,
pubkeyConverter: argument.AddressPubkeyConv,
shardCoordinator: argument.ShardCoordinator,
feeHandler: argument.FeeHandler,
whiteListerVerifiedTxs: argument.WhiteListerVerifiedTxs,
}, nil
}
// Create creates instances of InterceptedData by unmarshalling provided buffer
func (itdf *interceptedTxDataFactory) Create(buff []byte) (process.InterceptedData, error) {
return transaction.NewInterceptedTransaction(
buff,
itdf.protoMarshalizer,
itdf.signMarshalizer,
itdf.hasher,
itdf.keyGen,
itdf.singleSigner,
itdf.pubkeyConverter,
itdf.shardCoordinator,
itdf.feeHandler,
itdf.whiteListerVerifiedTxs,
)
}
// IsInterfaceNil returns true if there is no value under the interface
func (itdf *interceptedTxDataFactory) IsInterfaceNil() bool {
return itdf == nil
}