Skip to content
This repository was archived by the owner on Apr 14, 2025. It is now read-only.

Commit 8cbdb5b

Browse files
Merge pull request #76 from gateway-fm/feat/add-retrievemarketregistered
feat: add RetrieveMarketRegisteredOpts
2 parents a946290 + 5cc3bcb commit 8cbdb5b

File tree

3 files changed

+36
-12
lines changed

3 files changed

+36
-12
lines changed

perpsv3.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ type IPerpsv3 interface {
136136
// limit. For most public RPC providers the value for limit is 20 000 blocks
137137
RetrieveMarketRegistered(limit uint64) ([]*models.MarketRegistered, error)
138138

139+
// RetrieveMarketRegisteredOpts is used to get all `MarketRegistered` events with given start block, end block and block search
140+
// // limit. For most public RPC providers the value for limit is 20 000 blocks
141+
RetrieveMarketRegisteredOpts(fromBlock uint64, toBlock uint64, limit uint64) ([]*models.MarketRegistered, error)
142+
139143
// RetrievePoolCreatedLimit is used to get all `PoolCreated` events from the Core contract with given block search
140144
// limit. For most public RPC providers the value for limit is 20 000 blocks
141145
RetrievePoolCreatedLimit(limit uint64) ([]*models.PoolCreated, error)
@@ -506,6 +510,10 @@ func (p *Perpsv3) RetrieveMarketRegistered(limit uint64) ([]*models.MarketRegist
506510
return p.service.RetrieveMarketRegistered(limit)
507511
}
508512

513+
func (p *Perpsv3) RetrieveMarketRegisteredOpts(fromBlock uint64, toBlock uint64, limit uint64) ([]*models.MarketRegistered, error) {
514+
return p.service.RetrieveMarketRegisteredOpts(fromBlock, toBlock, limit)
515+
}
516+
509517
func (p *Perpsv3) RetrievePoolCreated(fromBlock uint64, toBlock uint64, limit uint64) ([]*models.PoolCreated, error) {
510518
return p.service.RetrievePoolCreated(fromBlock, toBlock, limit)
511519
}

services/marketData.go

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -112,25 +112,37 @@ func (s *Service) RetrieveMarketUpdatesBig(fromBlock uint64, toBLock *uint64) ([
112112
}
113113

114114
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)
116120
if err != nil {
117121
return nil, err
118122
}
119123

120124
var marketRegistrations []*models.MarketRegistered
121125

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,
125133
)
126134

127-
fromBlock := s.coreFirstBlock
128-
toBlock := fromBlock + limit
135+
startBlockOfIteration := fromBlock
136+
endBlockOfIteration := startBlockOfIteration + limit
137+
if endBlockOfIteration > toBlock {
138+
endBlockOfIteration = toBlock
139+
}
140+
129141
for i := uint64(1); i <= iterations; i++ {
130142
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)
132144
}
133-
opts := s.getFilterOptsCore(fromBlock, &toBlock)
145+
opts := s.getFilterOptsCore(startBlockOfIteration, &endBlockOfIteration)
134146

135147
res, err := s.retrieveMarketRegistrations(opts)
136148
if err != nil {
@@ -139,16 +151,16 @@ func (s *Service) RetrieveMarketRegistered(limit uint64) ([]*models.MarketRegist
139151

140152
marketRegistrations = append(marketRegistrations, res...)
141153

142-
fromBlock = toBlock + 1
154+
startBlockOfIteration = endBlockOfIteration + 1
143155

144156
if i == iterations-1 {
145-
toBlock = last
157+
endBlockOfIteration = lastBlock
146158
} else {
147-
toBlock = fromBlock + limit
159+
endBlockOfIteration = startBlockOfIteration + limit
148160
}
149161
}
150162

151-
logger.Log().WithField("layer", "Service-RetrieveMarketRegistered").Infof("task completed successfully")
163+
logger.Log().WithField("layer", "Service-RetrieveMarketRegisteredOpts").Infof("task completed successfully")
152164

153165
return marketRegistrations, nil
154166
}

services/service.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ type IService interface {
131131
// limit. For most public RPC providers the value for limit is 20 000 blocks
132132
RetrieveMarketRegistered(limit uint64) ([]*models.MarketRegistered, error)
133133

134+
// RetrieveMarketRegisteredOpts is used to get all `MarketRegistered` events with given start block, end block and block search
135+
// // limit. For most public RPC providers the value for limit is 20 000 blocks
136+
RetrieveMarketRegisteredOpts(fromBlock uint64, toBlock uint64, limit uint64) ([]*models.MarketRegistered, error)
137+
134138
// RetrievePoolCreated is used to get all `PoolCreated` events from the Core contract with given block search
135139
// limit. For most public RPC providers the value for limit is 20 000 blocks
136140
RetrievePoolCreatedLimit(limit uint64) ([]*models.PoolCreated, error)

0 commit comments

Comments
 (0)