forked from cerc-io/ipld-eth-server
Remove bc references and cleanup pointers
This commit is contained in:
parent
637623b752
commit
587d2219d8
@ -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()
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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())
|
||||
|
Loading…
Reference in New Issue
Block a user