-
Notifications
You must be signed in to change notification settings - Fork 199
/
historyRepositoryFactory.go
130 lines (114 loc) · 4.21 KB
/
historyRepositoryFactory.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package factory
import (
"github.com/multiversx/mx-chain-core-go/core"
"github.com/multiversx/mx-chain-core-go/core/check"
"github.com/multiversx/mx-chain-core-go/data/typeConverters"
"github.com/multiversx/mx-chain-core-go/hashing"
"github.com/multiversx/mx-chain-core-go/marshal"
"github.com/multiversx/mx-chain-go/config"
"github.com/multiversx/mx-chain-go/dataRetriever"
"github.com/multiversx/mx-chain-go/dblookupext"
"github.com/multiversx/mx-chain-go/dblookupext/disabled"
"github.com/multiversx/mx-chain-go/dblookupext/esdtSupply"
"github.com/multiversx/mx-chain-go/process"
)
// ArgsHistoryRepositoryFactory holds all dependencies required by the history processor factory in order to create
// new instances
type ArgsHistoryRepositoryFactory struct {
SelfShardID uint32
Config config.DbLookupExtensionsConfig
Store dataRetriever.StorageService
Marshalizer marshal.Marshalizer
Hasher hashing.Hasher
Uint64ByteSliceConverter typeConverters.Uint64ByteSliceConverter
}
type historyRepositoryFactory struct {
selfShardID uint32
dbLookupExtensionsConfig config.DbLookupExtensionsConfig
store dataRetriever.StorageService
marshalizer marshal.Marshalizer
hasher hashing.Hasher
uInt64ByteSliceConverter typeConverters.Uint64ByteSliceConverter
}
// NewHistoryRepositoryFactory creates an instance of historyRepositoryFactory
func NewHistoryRepositoryFactory(args *ArgsHistoryRepositoryFactory) (dblookupext.HistoryRepositoryFactory, error) {
if check.IfNil(args.Marshalizer) {
return nil, core.ErrNilMarshalizer
}
if check.IfNil(args.Hasher) {
return nil, core.ErrNilHasher
}
if check.IfNil(args.Store) {
return nil, core.ErrNilStore
}
if check.IfNil(args.Uint64ByteSliceConverter) {
return nil, process.ErrNilUint64Converter
}
return &historyRepositoryFactory{
selfShardID: args.SelfShardID,
dbLookupExtensionsConfig: args.Config,
store: args.Store,
marshalizer: args.Marshalizer,
hasher: args.Hasher,
uInt64ByteSliceConverter: args.Uint64ByteSliceConverter,
}, nil
}
// Create creates instances of HistoryRepository
func (hpf *historyRepositoryFactory) Create() (dblookupext.HistoryRepository, error) {
if !hpf.dbLookupExtensionsConfig.Enabled {
return disabled.NewNilHistoryRepository()
}
esdtSuppliesStorer, err := hpf.store.GetStorer(dataRetriever.ESDTSuppliesUnit)
if err != nil {
return nil, err
}
txLogsStorer, err := hpf.store.GetStorer(dataRetriever.TxLogsUnit)
if err != nil {
return nil, err
}
esdtSuppliesHandler, err := esdtSupply.NewSuppliesProcessor(
hpf.marshalizer,
esdtSuppliesStorer,
txLogsStorer,
)
if err != nil {
return nil, err
}
roundHdrHashDataStorer, err := hpf.store.GetStorer(dataRetriever.RoundHdrHashDataUnit)
if err != nil {
return nil, err
}
miniblocksMetadataStorer, err := hpf.store.GetStorer(dataRetriever.MiniblocksMetadataUnit)
if err != nil {
return nil, err
}
epochByHashStorer, err := hpf.store.GetStorer(dataRetriever.EpochByHashUnit)
if err != nil {
return nil, err
}
miniblockHashByTxHashStorer, err := hpf.store.GetStorer(dataRetriever.MiniblockHashByTxHashUnit)
if err != nil {
return nil, err
}
resultsHashesByTxHashStorer, err := hpf.store.GetStorer(dataRetriever.ResultsHashesByTxHashUnit)
if err != nil {
return nil, err
}
historyRepArgs := dblookupext.HistoryRepositoryArguments{
SelfShardID: hpf.selfShardID,
Hasher: hpf.hasher,
Marshalizer: hpf.marshalizer,
BlockHashByRound: roundHdrHashDataStorer,
Uint64ByteSliceConverter: hpf.uInt64ByteSliceConverter,
MiniblocksMetadataStorer: miniblocksMetadataStorer,
EpochByHashStorer: epochByHashStorer,
MiniblockHashByTxHashStorer: miniblockHashByTxHashStorer,
EventsHashesByTxHashStorer: resultsHashesByTxHashStorer,
ESDTSuppliesHandler: esdtSuppliesHandler,
}
return dblookupext.NewHistoryRepository(historyRepArgs)
}
// IsInterfaceNil returns true if there is no value under the interface
func (hpf *historyRepositoryFactory) IsInterfaceNil() bool {
return hpf == nil
}