@@ -112,25 +112,37 @@ func (s *Service) RetrieveMarketUpdatesBig(fromBlock uint64, toBLock *uint64) ([
112
112
}
113
113
114
114
func (s * Service ) RetrieveMarketRegistered (limit uint64 ) ([]* models.MarketRegistered , error ) {
115
- iterations , last , err := s .getIterationsForLimitQueryCore (limit )
115
+ return s .RetrieveMarketRegisteredOpts (0 , 0 , limit )
116
+ }
117
+
118
+ func (s * Service ) RetrieveMarketRegisteredOpts (fromBlock uint64 , toBlock uint64 , limit uint64 ) ([]* models.MarketRegistered , error ) {
119
+ iterations , lastBlock , err := s .getIterationsForQuery (fromBlock , toBlock , limit , ContractCore )
116
120
if err != nil {
117
121
return nil , err
118
122
}
119
123
120
124
var marketRegistrations []* models.MarketRegistered
121
125
122
- logger .Log ().WithField ("layer" , "Service-RetrieveMarketRegistered" ).Infof (
123
- "fetching market registrations with limit: %v to block: %v total iterations: %v..." ,
124
- limit , last , iterations ,
126
+ if fromBlock == 0 {
127
+ fromBlock = s .coreFirstBlock
128
+ }
129
+
130
+ logger .Log ().WithField ("layer" , "Service-RetrieveMarketRegisteredOpts" ).Infof (
131
+ "fetching market registrations with limit: %v from block: %v to block: %v total iterations: %v..." ,
132
+ limit , fromBlock , lastBlock , iterations ,
125
133
)
126
134
127
- fromBlock := s .coreFirstBlock
128
- toBlock := fromBlock + limit
135
+ startBlockOfIteration := fromBlock
136
+ endBlockOfIteration := startBlockOfIteration + limit
137
+ if endBlockOfIteration > toBlock {
138
+ endBlockOfIteration = toBlock
139
+ }
140
+
129
141
for i := uint64 (1 ); i <= iterations ; i ++ {
130
142
if i % 10 == 0 || i == iterations {
131
- logger .Log ().WithField ("layer" , "Service-RetrieveMarketRegistered " ).Infof ("-- iteration %v" , i )
143
+ logger .Log ().WithField ("layer" , "Service-RetrieveMarketRegisteredOpts " ).Infof ("-- iteration %v" , i )
132
144
}
133
- opts := s .getFilterOptsCore (fromBlock , & toBlock )
145
+ opts := s .getFilterOptsCore (startBlockOfIteration , & endBlockOfIteration )
134
146
135
147
res , err := s .retrieveMarketRegistrations (opts )
136
148
if err != nil {
@@ -139,16 +151,16 @@ func (s *Service) RetrieveMarketRegistered(limit uint64) ([]*models.MarketRegist
139
151
140
152
marketRegistrations = append (marketRegistrations , res ... )
141
153
142
- fromBlock = toBlock + 1
154
+ startBlockOfIteration = endBlockOfIteration + 1
143
155
144
156
if i == iterations - 1 {
145
- toBlock = last
157
+ endBlockOfIteration = lastBlock
146
158
} else {
147
- toBlock = fromBlock + limit
159
+ endBlockOfIteration = startBlockOfIteration + limit
148
160
}
149
161
}
150
162
151
- logger .Log ().WithField ("layer" , "Service-RetrieveMarketRegistered " ).Infof ("task completed successfully" )
163
+ logger .Log ().WithField ("layer" , "Service-RetrieveMarketRegisteredOpts " ).Infof ("task completed successfully" )
152
164
153
165
return marketRegistrations , nil
154
166
}
0 commit comments