ipld-eth-server/pkg/history/populate_blocks.go

26 lines
835 B
Go
Raw Normal View History

package history
import (
"log"
"github.com/8thlight/vulcanizedb/pkg/core"
"github.com/8thlight/vulcanizedb/pkg/repositories"
)
func PopulateMissingBlocks(blockchain core.Blockchain, repository repositories.Repository, startingBlockNumber int64) int {
lastBlock := blockchain.LastBlock().Int64()
blockRange := repository.MissingBlockNumbers(startingBlockNumber, lastBlock-1)
log.SetPrefix("")
log.Printf("Backfilling %d blocks\n\n", len(blockRange))
RetrieveAndUpdateBlocks(blockchain, repository, blockRange)
return len(blockRange)
}
func RetrieveAndUpdateBlocks(blockchain core.Blockchain, repository repositories.Repository, blockNumbers []int64) int {
for _, blockNumber := range blockNumbers {
block := blockchain.GetBlockByNumber(blockNumber)
repository.CreateOrUpdateBlock(block)
}
return len(blockNumbers)
}