Skip to content

Commit

Permalink
feat: added RetrieveUSDBurned and RetrieveUSDMinted
Browse files Browse the repository at this point in the history
  • Loading branch information
xfiendx4life committed Aug 29, 2024
1 parent 50459d4 commit f6bd391
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 16 deletions.
56 changes: 40 additions & 16 deletions services/pools.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ import (
)

func (s *Service) RetrieveUSDMintedLimit(limit uint64) ([]*models.USDMinted, error) {
iterations, last, err := s.getIterationsForLimitQueryCore(limit)
return s.RetrieveUSDMinted(0, 0, limit)
}
func (s *Service) RetrieveUSDMinted(fromBlock uint64, toBlock uint64, limit uint64) ([]*models.USDMinted, error) {
iterations, lastBlock, err := s.getIterationsForLimitQueryCore(limit)
if err != nil {
return nil, err
}
Expand All @@ -27,16 +30,25 @@ func (s *Service) RetrieveUSDMintedLimit(limit uint64) ([]*models.USDMinted, err

logger.Log().WithField("layer", "Service-RetrieveUSDMintedLimit").Infof(
"fetching USDMinted with limit: %v to block: %v total iterations: %v...",
limit, last, iterations,
limit, lastBlock, iterations,
)

fromBlock := s.coreFirstBlock
toBlock := fromBlock + limit
if fromBlock == 0 {
fromBlock = s.coreFirstBlock
}

startBlockOfIteration := fromBlock
endBlockOfIteration := startBlockOfIteration + limit

if endBlockOfIteration > toBlock {
endBlockOfIteration = toBlock
}

for i := uint64(1); i <= iterations; i++ {
if i%10 == 0 || i == iterations {
logger.Log().WithField("layer", "Service-RetrieveUSDMintedLimit").Infof("-- iteration %v", i)
}
opts := s.getFilterOptsCore(fromBlock, &toBlock)
opts := s.getFilterOptsCore(startBlockOfIteration, &endBlockOfIteration)

res, err := s.retrieveUSDMinted(opts)
if err != nil {
Expand All @@ -45,12 +57,12 @@ func (s *Service) RetrieveUSDMintedLimit(limit uint64) ([]*models.USDMinted, err

mints = append(mints, res...)

fromBlock = toBlock + 1
startBlockOfIteration = endBlockOfIteration + 1

if i == iterations-1 {
toBlock = last
endBlockOfIteration = lastBlock
} else {
toBlock = fromBlock + limit
endBlockOfIteration = startBlockOfIteration + limit
}
}

Expand All @@ -60,7 +72,11 @@ func (s *Service) RetrieveUSDMintedLimit(limit uint64) ([]*models.USDMinted, err
}

func (s *Service) RetrieveUSDBurnedLimit(limit uint64) ([]*models.USDBurned, error) {
iterations, last, err := s.getIterationsForLimitQueryCore(limit)
return s.RetrieveUSDBurned(0, 0, limit)
}

func (s *Service) RetrieveUSDBurned(fromBlock uint64, toBlock uint64, limit uint64) ([]*models.USDBurned, error) {
iterations, lastBlock, err := s.getIterationsForLimitQueryCore(limit)
if err != nil {
return nil, err
}
Expand All @@ -69,16 +85,24 @@ func (s *Service) RetrieveUSDBurnedLimit(limit uint64) ([]*models.USDBurned, err

logger.Log().WithField("layer", "Service-RetrieveUSDBurnedLimit").Infof(
"fetching USDMBurned with limit: %v to block: %v total iterations: %v...",
limit, last, iterations,
limit, lastBlock, iterations,
)

fromBlock := s.coreFirstBlock
toBlock := fromBlock + limit
if fromBlock == 0 {
fromBlock = s.coreFirstBlock
}

startBlockOfIteration := fromBlock
endBlockOfIteration := startBlockOfIteration + limit

if endBlockOfIteration > toBlock {
endBlockOfIteration = toBlock
}
for i := uint64(1); i <= iterations; i++ {
if i%10 == 0 || i == iterations {
logger.Log().WithField("layer", "Service-RetrieveUSDMBurnedLimit").Infof("-- iteration %v", i)
}
opts := s.getFilterOptsCore(fromBlock, &toBlock)
opts := s.getFilterOptsCore(startBlockOfIteration, &endBlockOfIteration)

res, err := s.retrieveUSDBurned(opts)
if err != nil {
Expand All @@ -87,12 +111,12 @@ func (s *Service) RetrieveUSDBurnedLimit(limit uint64) ([]*models.USDBurned, err

burns = append(burns, res...)

fromBlock = toBlock + 1
startBlockOfIteration = endBlockOfIteration + 1

if i == iterations-1 {
toBlock = last
endBlockOfIteration = lastBlock
} else {
toBlock = fromBlock + limit
endBlockOfIteration = startBlockOfIteration + limit
}
}

Expand Down
8 changes: 8 additions & 0 deletions services/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,18 @@ type IService interface {
// limit. For most public RPC providers the value for limit is 20 000 blocks
RetrieveUSDMintedLimit(limit uint64) ([]*models.USDMinted, error)

// RetrieveUSDMintedLimit is used to get all `usdMinted` events from the Core contract with given start block, end block and block search
// limit. For most public RPC providers the value for limit is 20 000 blocks
RetrieveUSDMinted(fromBlock uint64, toBlock uint64, limit uint64) ([]*models.USDMinted, error)

// RetrieveUSDBurnedLimit is used to get all `usdBurned` events from the Core contract with given block search
// limit. For most public RPC providers the value for limit is 20 000 blocks
RetrieveUSDBurnedLimit(limit uint64) ([]*models.USDBurned, error)

// RetrieveUSDBurnedLimit is used to get all `usdBurned` events from the Core contract with given start block, end block and block search
// limit. For most public RPC providers the value for limit is 20 000 blocks
RetrieveUSDBurned(fromBlock uint64, toBlock uint64, limit uint64) ([]*models.USDBurned, error)

// RetrieveDelegationUpdatedLimit is used to get all `DelegationUpdated` events from the Core contract with given block search
// limit. For most public RPC providers the value for limit is 20 000 blocks
RetrieveDelegationUpdatedLimit(limit uint64) ([]*models.DelegationUpdated, error)
Expand Down

0 comments on commit f6bd391

Please sign in to comment.