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:
+4
-2
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/filters"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/geth"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/repositories/postgres"
|
||||
"github.com/vulcanize/vulcanizedb/utils"
|
||||
)
|
||||
|
||||
@@ -56,7 +57,8 @@ func addFilter() {
|
||||
}
|
||||
var logFilters filters.LogFilters
|
||||
blockchain := geth.NewBlockchain(ipc)
|
||||
repository := utils.LoadPostgres(databaseConfig, blockchain.Node())
|
||||
db := utils.LoadPostgres(databaseConfig, blockchain.Node())
|
||||
filterRepository := postgres.FilterRepository{DB: &db}
|
||||
absFilePath := utils.AbsFilePath(filterFilepath)
|
||||
logFilterBytes, err := ioutil.ReadFile(absFilePath)
|
||||
if err != nil {
|
||||
@@ -67,7 +69,7 @@ func addFilter() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
for _, filter := range logFilters {
|
||||
err = repository.CreateFilter(filter)
|
||||
err = filterRepository.CreateFilter(filter)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
+13
-2
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/geth"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/graphql_server"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/repositories/postgres"
|
||||
"github.com/vulcanize/vulcanizedb/utils"
|
||||
)
|
||||
|
||||
@@ -43,8 +44,18 @@ func init() {
|
||||
func parseSchema() *graphql.Schema {
|
||||
|
||||
blockchain := geth.NewBlockchain(ipc)
|
||||
repository := utils.LoadPostgres(databaseConfig, blockchain.Node())
|
||||
schema := graphql.MustParseSchema(graphql_server.Schema, graphql_server.NewResolver(repository))
|
||||
db := utils.LoadPostgres(databaseConfig, blockchain.Node())
|
||||
blockRepository := &postgres.BlockRepository{DB: &db}
|
||||
logRepository := &postgres.LogRepository{DB: &db}
|
||||
filterRepository := &postgres.FilterRepository{DB: &db}
|
||||
watchedEventRepository := &postgres.WatchedEventRepository{DB: &db}
|
||||
graphQLRepositories := graphql_server.GraphQLRepositories{
|
||||
WatchedEventRepository: watchedEventRepository,
|
||||
BlockRepository: blockRepository,
|
||||
LogRepository: logRepository,
|
||||
FilterRepository: filterRepository,
|
||||
}
|
||||
schema := graphql.MustParseSchema(graphql_server.Schema, graphql_server.NewResolver(graphQLRepositories))
|
||||
return schema
|
||||
|
||||
}
|
||||
|
||||
+8
-6
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/vulcanize/vulcanizedb/pkg/core"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/geth"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/history"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/repositories"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/repositories/postgres"
|
||||
"github.com/vulcanize/vulcanizedb/utils"
|
||||
)
|
||||
@@ -49,9 +50,9 @@ func init() {
|
||||
syncCmd.Flags().IntVarP(&startingBlockNumber, "starting-block-number", "s", 0, "Block number to start syncing from")
|
||||
}
|
||||
|
||||
func backFillAllBlocks(blockchain core.Blockchain, repository postgres.DB, missingBlocksPopulated chan int, startingBlockNumber int64) {
|
||||
func backFillAllBlocks(blockchain core.Blockchain, blockRepository repositories.BlockRepository, missingBlocksPopulated chan int, startingBlockNumber int64) {
|
||||
go func() {
|
||||
missingBlocksPopulated <- history.PopulateMissingBlocks(blockchain, repository, startingBlockNumber)
|
||||
missingBlocksPopulated <- history.PopulateMissingBlocks(blockchain, blockRepository, startingBlockNumber)
|
||||
}()
|
||||
}
|
||||
|
||||
@@ -63,12 +64,13 @@ func sync() {
|
||||
if blockchain.LastBlock().Int64() == 0 {
|
||||
log.Fatal("geth initial: state sync not finished")
|
||||
}
|
||||
repository := utils.LoadPostgres(databaseConfig, blockchain.Node())
|
||||
validator := history.NewBlockValidator(blockchain, repository, 15)
|
||||
db := utils.LoadPostgres(databaseConfig, blockchain.Node())
|
||||
blockRepository := postgres.BlockRepository{DB: &db}
|
||||
validator := history.NewBlockValidator(blockchain, blockRepository, 15)
|
||||
|
||||
missingBlocksPopulated := make(chan int)
|
||||
_startingBlockNumber := int64(startingBlockNumber)
|
||||
go backFillAllBlocks(blockchain, repository, missingBlocksPopulated, _startingBlockNumber)
|
||||
go backFillAllBlocks(blockchain, blockRepository, missingBlocksPopulated, _startingBlockNumber)
|
||||
|
||||
for {
|
||||
select {
|
||||
@@ -76,7 +78,7 @@ func sync() {
|
||||
window := validator.ValidateBlocks()
|
||||
validator.Log(os.Stdout, window)
|
||||
case <-missingBlocksPopulated:
|
||||
go backFillAllBlocks(blockchain, repository, missingBlocksPopulated, _startingBlockNumber)
|
||||
go backFillAllBlocks(blockchain, blockRepository, missingBlocksPopulated, _startingBlockNumber)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user