diff --git a/cmd/backfillMakerLogs.go b/cmd/backfillMakerLogs.go index 07a3d003..339b9252 100644 --- a/cmd/backfillMakerLogs.go +++ b/cmd/backfillMakerLogs.go @@ -17,6 +17,7 @@ package cmd import ( log "github.com/sirupsen/logrus" "github.com/spf13/cobra" + shared2 "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" "github.com/vulcanize/vulcanizedb/libraries/shared" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" @@ -46,10 +47,8 @@ func backfillMakerLogs() { log.Fatal("Failed to initialize database.") } - watcher := shared.Watcher{ - DB: *db, - Blockchain: blockChain, - } + fetcher := shared2.NewFetcher(blockChain) + watcher := shared.NewWatcher(db, fetcher) watcher.AddTransformers(transformers.TransformerInitializers()) watcher.Execute() diff --git a/cmd/continuousLogSync.go b/cmd/continuousLogSync.go index 9f081ea3..786ea5ea 100644 --- a/cmd/continuousLogSync.go +++ b/cmd/continuousLogSync.go @@ -58,9 +58,11 @@ func syncMakerLogs() { log.Fatal("Failed to initialize database.") } + fetcher := shared2.NewFetcher(blockChain) + watcher := shared.Watcher{ - DB: *db, - Blockchain: blockChain, + DB: db, + Fetcher: fetcher, } transformerInititalizers := getTransformerInititalizers(transformerNames) diff --git a/libraries/shared/watcher.go b/libraries/shared/watcher.go index 79834d57..d521f597 100644 --- a/libraries/shared/watcher.go +++ b/libraries/shared/watcher.go @@ -3,7 +3,6 @@ package shared import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/log" - "github.com/vulcanize/vulcanizedb/pkg/core" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" "github.com/vulcanize/vulcanizedb/pkg/transformers" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" @@ -11,15 +10,14 @@ import ( type Watcher struct { Transformers []shared.Transformer - DB postgres.DB - Blockchain core.BlockChain + DB *postgres.DB Fetcher shared.LogFetcher Chunker shared.LogChunker Addresses []common.Address Topics []common.Hash } -func NewWatcher(db postgres.DB, bc core.BlockChain, fetcher shared.LogFetcher) Watcher { +func NewWatcher(db *postgres.DB, fetcher shared.LogFetcher) Watcher { transformerConfigs := transformers.TransformerConfigs() var contractAddresses []common.Address var topic0s []common.Hash @@ -34,31 +32,30 @@ func NewWatcher(db postgres.DB, bc core.BlockChain, fetcher shared.LogFetcher) W chunker := shared.NewLogChunker(transformerConfigs) return Watcher{ - DB: db, - Blockchain: bc, - Fetcher: fetcher, - Chunker: chunker, - Addresses: contractAddresses, - Topics: topic0s, + DB: db, + Fetcher: fetcher, + Chunker: chunker, + Addresses: contractAddresses, + Topics: topic0s, } } func (watcher *Watcher) AddTransformers(us []shared.TransformerInitializer) { for _, transformerInitializer := range us { - transformer := transformerInitializer(&watcher.DB) + transformer := transformerInitializer(watcher.DB) watcher.Transformers = append(watcher.Transformers, transformer) } } func (watcher *Watcher) Execute() error { - checkedColumnNames, err := shared.GetCheckedColumnNames(&watcher.DB) + checkedColumnNames, err := shared.GetCheckedColumnNames(watcher.DB) if err != nil { return err } notCheckedSQL := shared.CreateNotCheckedSQL(checkedColumnNames) // TODO Handle start and end numbers in transformers? - missingHeaders, err := shared.MissingHeaders(0, -1, &watcher.DB, notCheckedSQL) + missingHeaders, err := shared.MissingHeaders(0, -1, watcher.DB, notCheckedSQL) for _, header := range missingHeaders { // TODO Extend FetchLogs for doing several blocks at a time diff --git a/libraries/shared/watcher_test.go b/libraries/shared/watcher_test.go index 2386375a..a3007a60 100644 --- a/libraries/shared/watcher_test.go +++ b/libraries/shared/watcher_test.go @@ -77,7 +77,7 @@ var _ = Describe("Watcher", func() { db = test_config.NewTestDB(test_config.NewTestNode()) test_config.CleanTestDB(db) mockFetcher = &mocks.MockLogFetcher{} - watcher = shared.NewWatcher(*db, nil, mockFetcher) + watcher = shared.NewWatcher(db, mockFetcher) headerRepository = repositories.NewHeaderRepository(db) _, err := headerRepository.CreateOrUpdateHeader(fakes.FakeHeader) Expect(err).NotTo(HaveOccurred())