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 (
|
import (
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
shared2 "github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
||||||
|
|
||||||
"github.com/vulcanize/vulcanizedb/libraries/shared"
|
"github.com/vulcanize/vulcanizedb/libraries/shared"
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
||||||
@ -46,10 +47,8 @@ func backfillMakerLogs() {
|
|||||||
log.Fatal("Failed to initialize database.")
|
log.Fatal("Failed to initialize database.")
|
||||||
}
|
}
|
||||||
|
|
||||||
watcher := shared.Watcher{
|
fetcher := shared2.NewFetcher(blockChain)
|
||||||
DB: *db,
|
watcher := shared.NewWatcher(db, fetcher)
|
||||||
Blockchain: blockChain,
|
|
||||||
}
|
|
||||||
|
|
||||||
watcher.AddTransformers(transformers.TransformerInitializers())
|
watcher.AddTransformers(transformers.TransformerInitializers())
|
||||||
watcher.Execute()
|
watcher.Execute()
|
||||||
|
@ -58,9 +58,11 @@ func syncMakerLogs() {
|
|||||||
log.Fatal("Failed to initialize database.")
|
log.Fatal("Failed to initialize database.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fetcher := shared2.NewFetcher(blockChain)
|
||||||
|
|
||||||
watcher := shared.Watcher{
|
watcher := shared.Watcher{
|
||||||
DB: *db,
|
DB: db,
|
||||||
Blockchain: blockChain,
|
Fetcher: fetcher,
|
||||||
}
|
}
|
||||||
|
|
||||||
transformerInititalizers := getTransformerInititalizers(transformerNames)
|
transformerInititalizers := getTransformerInititalizers(transformerNames)
|
||||||
|
@ -3,7 +3,6 @@ package shared
|
|||||||
import (
|
import (
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/core"
|
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/transformers"
|
"github.com/vulcanize/vulcanizedb/pkg/transformers"
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
||||||
@ -11,15 +10,14 @@ import (
|
|||||||
|
|
||||||
type Watcher struct {
|
type Watcher struct {
|
||||||
Transformers []shared.Transformer
|
Transformers []shared.Transformer
|
||||||
DB postgres.DB
|
DB *postgres.DB
|
||||||
Blockchain core.BlockChain
|
|
||||||
Fetcher shared.LogFetcher
|
Fetcher shared.LogFetcher
|
||||||
Chunker shared.LogChunker
|
Chunker shared.LogChunker
|
||||||
Addresses []common.Address
|
Addresses []common.Address
|
||||||
Topics []common.Hash
|
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()
|
transformerConfigs := transformers.TransformerConfigs()
|
||||||
var contractAddresses []common.Address
|
var contractAddresses []common.Address
|
||||||
var topic0s []common.Hash
|
var topic0s []common.Hash
|
||||||
@ -34,31 +32,30 @@ func NewWatcher(db postgres.DB, bc core.BlockChain, fetcher shared.LogFetcher) W
|
|||||||
chunker := shared.NewLogChunker(transformerConfigs)
|
chunker := shared.NewLogChunker(transformerConfigs)
|
||||||
|
|
||||||
return Watcher{
|
return Watcher{
|
||||||
DB: db,
|
DB: db,
|
||||||
Blockchain: bc,
|
Fetcher: fetcher,
|
||||||
Fetcher: fetcher,
|
Chunker: chunker,
|
||||||
Chunker: chunker,
|
Addresses: contractAddresses,
|
||||||
Addresses: contractAddresses,
|
Topics: topic0s,
|
||||||
Topics: topic0s,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (watcher *Watcher) AddTransformers(us []shared.TransformerInitializer) {
|
func (watcher *Watcher) AddTransformers(us []shared.TransformerInitializer) {
|
||||||
for _, transformerInitializer := range us {
|
for _, transformerInitializer := range us {
|
||||||
transformer := transformerInitializer(&watcher.DB)
|
transformer := transformerInitializer(watcher.DB)
|
||||||
watcher.Transformers = append(watcher.Transformers, transformer)
|
watcher.Transformers = append(watcher.Transformers, transformer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (watcher *Watcher) Execute() error {
|
func (watcher *Watcher) Execute() error {
|
||||||
checkedColumnNames, err := shared.GetCheckedColumnNames(&watcher.DB)
|
checkedColumnNames, err := shared.GetCheckedColumnNames(watcher.DB)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
notCheckedSQL := shared.CreateNotCheckedSQL(checkedColumnNames)
|
notCheckedSQL := shared.CreateNotCheckedSQL(checkedColumnNames)
|
||||||
|
|
||||||
// TODO Handle start and end numbers in transformers?
|
// 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 {
|
for _, header := range missingHeaders {
|
||||||
// TODO Extend FetchLogs for doing several blocks at a time
|
// 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())
|
db = test_config.NewTestDB(test_config.NewTestNode())
|
||||||
test_config.CleanTestDB(db)
|
test_config.CleanTestDB(db)
|
||||||
mockFetcher = &mocks.MockLogFetcher{}
|
mockFetcher = &mocks.MockLogFetcher{}
|
||||||
watcher = shared.NewWatcher(*db, nil, mockFetcher)
|
watcher = shared.NewWatcher(db, mockFetcher)
|
||||||
headerRepository = repositories.NewHeaderRepository(db)
|
headerRepository = repositories.NewHeaderRepository(db)
|
||||||
_, err := headerRepository.CreateOrUpdateHeader(fakes.FakeHeader)
|
_, err := headerRepository.CreateOrUpdateHeader(fakes.FakeHeader)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
Loading…
Reference in New Issue
Block a user