Separate DB access into several repos (#28)

* Separate files for InMemory

* Start using separate repos for collaborating objects

* Before Updating schema

* Separate various repos
This commit is contained in:
Matt K
2018-02-12 10:54:05 -06:00
committed by GitHub
parent 605b0a96ae
commit ed907535e3
34 changed files with 538 additions and 501 deletions
+5 -5
View File
@@ -7,19 +7,19 @@ import (
"github.com/vulcanize/vulcanizedb/pkg/repositories"
)
func PopulateMissingBlocks(blockchain core.Blockchain, repository repositories.Repository, startingBlockNumber int64) int {
func PopulateMissingBlocks(blockchain core.Blockchain, blockRepository repositories.BlockRepository, startingBlockNumber int64) int {
lastBlock := blockchain.LastBlock().Int64()
blockRange := repository.MissingBlockNumbers(startingBlockNumber, lastBlock-1)
blockRange := blockRepository.MissingBlockNumbers(startingBlockNumber, lastBlock-1)
log.SetPrefix("")
log.Printf("Backfilling %d blocks\n\n", len(blockRange))
RetrieveAndUpdateBlocks(blockchain, repository, blockRange)
RetrieveAndUpdateBlocks(blockchain, blockRepository, blockRange)
return len(blockRange)
}
func RetrieveAndUpdateBlocks(blockchain core.Blockchain, repository repositories.Repository, blockNumbers []int64) int {
func RetrieveAndUpdateBlocks(blockchain core.Blockchain, blockRepository repositories.BlockRepository, blockNumbers []int64) int {
for _, blockNumber := range blockNumbers {
block := blockchain.GetBlockByNumber(blockNumber)
repository.CreateOrUpdateBlock(block)
blockRepository.CreateOrUpdateBlock(block)
}
return len(blockNumbers)
}