func GetBlocksWithTxReceipts(client *ethclient.Client, blockChan chan<- *BlockWithTxReceipts, startBlock int64, endBlock int64, concurrency int) {
	var blockWorkerWg sync.WaitGroup
	blockHeightChan := make(chan int64, 100) // blockHeight to fetch with receipts

	// Start eth client thread pool
	for w := 1; w <= concurrency; w++ {
		blockWorkerWg.Add(1)

		go func() {
			defer blockWorkerWg.Done()
			for blockHeight := range blockHeightChan {
				res, err := GetBlockWithTxReceipts(client, blockHeight)
				if err != nil {
					log.Println("Error getting block with tx receipts:", err)
					continue
				}
				blockChan <- res
			}
		}()
	}

	// Push blocks into channel, for workers to pick up
	for currentBlockNumber := startBlock; currentBlockNumber <= endBlock; currentBlockNumber++ {
		blockHeightChan <- currentBlockNumber
	}

	// Close worker channel and wait for workers to finish
	close(blockHeightChan)
	blockWorkerWg.Wait()
}
// GetBlocksWithTxReceipts downloads a range of blocks with tx receipts, and sends each to a channel once it is ready.
// Uses concurrency parallel connections to get data from the eth node fast. 5 seems a good number for a direct IPC connection.
GetBlocksWithTxReceipts downloads a range of blocks with tx receipts, and sends each to a channel once it is ready.
Uses concurrency parallel connections to get data from the eth node fast. 5 seems a good number for a direct IPC connection.
// GetBlocksWithTxReceipts downloads a range of blocks with tx receipts and sends each to a channel once it is ready . // Uses concurrency parallel connections to get data from the eth node fast . 5 seems a good number for a direct IPC connection .
func GetBlocksWithTxReceipts(client *ethclient.Client, blockChan chan<- *BlockWithTxReceipts, startBlock int64, endBlock int64, concurrency int) {
	var blockWorkerWg sync.WaitGroup
	blockHeightChan := make(chan int64, 100) 
	for w := 1; w <= concurrency; w++ {
		blockWorkerWg.Add(1)
		go func() {
			defer blockWorkerWg.Done()
			for blockHeight := range blockHeightChan {
				res, err := GetBlockWithTxReceipts(client, blockHeight)
				if err != nil {
					log.Println("Error getting block with tx receipts:", err)
					continue
				}
				blockChan <- res
			}
		}()
	}
	for currentBlockNumber := startBlock; currentBlockNumber <= endBlock; currentBlockNumber++ {
		blockHeightChan <- currentBlockNumber
	}
	close(blockHeightChan)
	blockWorkerWg.Wait()
}
func GetBlocksWithTxReceipts ( client * ethclient . Client , blockChan chan <- * BlockWithTxReceipts , startBlock int64 , endBlock int64 , concurrency int ) { var blockWorkerWg sync . WaitGroup blockHeightChan := make ( chan int64 , 100 ) for w := 1 ; w <= concurrency ; w ++ { blockWorkerWg . Add ( 1 ) go func ( ) { defer blockWorkerWg . Done ( ) for blockHeight := range blockHeightChan { res , err := GetBlockWithTxReceipts ( client , blockHeight ) if err != nil { log . Println ( " " , err ) continue } blockChan <- res } } ( ) } for currentBlockNumber := startBlock ; currentBlockNumber <= endBlock ; currentBlockNumber ++ { blockHeightChan <- currentBlockNumber } close ( blockHeightChan ) blockWorkerWg . Wait ( ) }
GetBlocksWithTxReceipts downloads a range of blocks with tx receipts, and sends each to a channel once it is ready.
GetBlocksWithTxReceipts downloads a range of blocks with tx receipts and sends each to a channel once it is ready .
// blockHeight to fetch with receipts // Start eth client thread pool // Push blocks into channel, for workers to pick up // Close worker channel and wait for workers to finish