Skip to content

Commit

Permalink
limit blocks to subscribe
Browse files Browse the repository at this point in the history
  • Loading branch information
nnn-gif committed Mar 27, 2024
1 parent f50aef5 commit 99c8e03
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion internal/scraper/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,21 @@ func (s *scraperImpl) listenEvents(addresses []common.Address) {

topic := s.oraclesmap[s.oraclesaddresses[0]].ContractABI.Events["OracleUpdate"].ID

latestBlock, err := s.wsClient.BlockNumber(ctx)
if err != nil {
s.logger.Printf("Failed to get latest BlockNumber : %v chainid %s ", err, s.chainID)
return
}

latestBlock = latestBlock - 500

subscription, err := s.wsClient.SubscribeFilterLogs(ctx, ethereum.FilterQuery{
Addresses: addresses,
FromBlock: big.NewInt(int64(latestBlock)),
Topics: [][]common.Hash{{topic}},
}, updateeventchan)
if err != nil {
s.logger.Printf("Failed to subscribe to event logs: %v chainid ", err, s.chainID)
s.logger.Printf("Failed to subscribe to event logs: %v chainid %s ", err, s.chainID)
return
}

Expand Down

0 comments on commit 99c8e03

Please sign in to comment.