forked from cerc-io/ipld-eth-server
6decf0b54b
* Rename geth package structs to not be prefaced with package name * No longer need to dump schema since Travis uses migrate * Rearrange history package * Removed double request for receipt from block rewards * Remove Listener + Observers and Replace w/ Polling Head * Potential Short term Issue w/ Infura (ignore these tests for now)
26 lines
835 B
Go
26 lines
835 B
Go
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)
|
|
}
|