diff --git a/pkg/transformers/cat_file/config.go b/pkg/transformers/cat_file/chop_lump/config.go similarity index 81% rename from pkg/transformers/cat_file/config.go rename to pkg/transformers/cat_file/chop_lump/config.go index 50d6ed98..6dfb8f93 100644 --- a/pkg/transformers/cat_file/config.go +++ b/pkg/transformers/cat_file/chop_lump/config.go @@ -12,14 +12,15 @@ // See the License for the specific language governing permissions and // limitations under the License. -package cat_file +package chop_lump import "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" -var CatFileConfig = shared.TransformerConfig{ +var CatFileChopLumpConfig = shared.SingleTransformerConfig{ + TransformerName: shared.CatFileChopLumpLabel, ContractAddresses: []string{shared.CatContractAddress}, ContractAbi: shared.CatABI, - Topics: []string{shared.CatFileChopLumpSignature, shared.CatFileFlipSignature, shared.CatFilePitVowSignature}, + Topic: shared.CatFileChopLumpSignature, StartingBlockNumber: 0, EndingBlockNumber: 10000000, } diff --git a/pkg/transformers/cat_file/chop_lump/converter.go b/pkg/transformers/cat_file/chop_lump/converter.go index 01c3b772..a73c5fc0 100644 --- a/pkg/transformers/cat_file/chop_lump/converter.go +++ b/pkg/transformers/cat_file/chop_lump/converter.go @@ -23,14 +23,10 @@ import ( "math/big" ) -type Converter interface { - ToModels(ethLogs []types.Log) ([]CatFileChopLumpModel, error) -} - type CatFileChopLumpConverter struct{} -func (CatFileChopLumpConverter) ToModels(ethLogs []types.Log) ([]CatFileChopLumpModel, error) { - var results []CatFileChopLumpModel +func (CatFileChopLumpConverter) ToModels(ethLogs []types.Log) ([]interface{}, error) { + var results []interface{} for _, ethLog := range ethLogs { err := verifyLog(ethLog) if err != nil { diff --git a/pkg/transformers/cat_file/chop_lump/repository.go b/pkg/transformers/cat_file/chop_lump/repository.go index 5676afe7..6063beae 100644 --- a/pkg/transformers/cat_file/chop_lump/repository.go +++ b/pkg/transformers/cat_file/chop_lump/repository.go @@ -15,34 +15,32 @@ package chop_lump import ( + "fmt" "github.com/vulcanize/vulcanizedb/pkg/core" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" ) -type Repository interface { - Create(headerID int64, models []CatFileChopLumpModel) error - MarkHeaderChecked(headerID int64) error - MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) -} - type CatFileChopLumpRepository struct { db *postgres.DB } -func NewCatFileChopLumpRepository(db *postgres.DB) CatFileChopLumpRepository { - return CatFileChopLumpRepository{db: db} -} - -func (repository CatFileChopLumpRepository) Create(headerID int64, models []CatFileChopLumpModel) error { +func (repository CatFileChopLumpRepository) Create(headerID int64, models []interface{}) error { tx, err := repository.db.Begin() if err != nil { return err } + for _, model := range models { + chopLump, ok := model.(CatFileChopLumpModel) + if !ok { + tx.Rollback() + return fmt.Errorf("model of type %T, not %T", model, CatFileChopLumpModel{}) + } + _, err := tx.Exec( `INSERT into maker.cat_file_chop_lump (header_id, ilk, what, data, tx_idx, log_idx, raw_log) - VALUES($1, $2, $3, $4::NUMERIC, $5, $6, $7)`, - headerID, model.Ilk, model.What, model.Data, model.TransactionIndex, model.LogIndex, model.Raw, + VALUES($1, $2, $3, $4::NUMERIC, $5, $6, $7)`, + headerID, chopLump.Ilk, chopLump.What, chopLump.Data, chopLump.TransactionIndex, chopLump.LogIndex, chopLump.Raw, ) if err != nil { tx.Rollback() @@ -50,9 +48,9 @@ func (repository CatFileChopLumpRepository) Create(headerID int64, models []CatF } } _, err = tx.Exec(`INSERT INTO public.checked_headers (header_id, cat_file_chop_lump_checked) - VALUES ($1, $2) - ON CONFLICT (header_id) DO - UPDATE SET cat_file_chop_lump_checked = $2`, headerID, true) + VALUES ($1, $2) + ON CONFLICT (header_id) DO + UPDATE SET cat_file_chop_lump_checked = $2`, headerID, true) if err != nil { tx.Rollback() return err @@ -62,9 +60,9 @@ func (repository CatFileChopLumpRepository) Create(headerID int64, models []CatF func (repository CatFileChopLumpRepository) MarkHeaderChecked(headerID int64) error { _, err := repository.db.Exec(`INSERT INTO public.checked_headers (header_id, cat_file_chop_lump_checked) - VALUES ($1, $2) - ON CONFLICT (header_id) DO - UPDATE SET cat_file_chop_lump_checked = $2`, headerID, true) + VALUES ($1, $2) + ON CONFLICT (header_id) DO + UPDATE SET cat_file_chop_lump_checked = $2`, headerID, true) return err } @@ -73,14 +71,18 @@ func (repository CatFileChopLumpRepository) MissingHeaders(startingBlockNumber, err := repository.db.Select( &result, `SELECT headers.id, headers.block_number FROM headers - LEFT JOIN checked_headers on headers.id = header_id - WHERE (header_id ISNULL OR cat_file_chop_lump_checked IS FALSE) - AND headers.block_number >= $1 - AND headers.block_number <= $2 - AND headers.eth_node_fingerprint = $3`, + LEFT JOIN checked_headers on headers.id = header_id + WHERE (header_id ISNULL OR cat_file_chop_lump_checked IS FALSE) + AND headers.block_number >= $1 + AND headers.block_number <= $2 + AND headers.eth_node_fingerprint = $3`, startingBlockNumber, endingBlockNumber, repository.db.Node.ID, ) return result, err } + +func (repository *CatFileChopLumpRepository) SetDB(db *postgres.DB) { + repository.db = db +} diff --git a/pkg/transformers/cat_file/chop_lump/transformer.go b/pkg/transformers/cat_file/chop_lump/transformer.go deleted file mode 100644 index 17d75548..00000000 --- a/pkg/transformers/cat_file/chop_lump/transformer.go +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright 2018 Vulcanize -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package chop_lump - -import ( - "github.com/ethereum/go-ethereum/common" - - "github.com/vulcanize/vulcanizedb/pkg/core" - "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" - "github.com/vulcanize/vulcanizedb/pkg/transformers/cat_file" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" -) - -type CatFileChopLumpTransformerInitializer struct { - Config shared.TransformerConfig -} - -func (initializer CatFileChopLumpTransformerInitializer) NewCatFileChopLumpTransformer(db *postgres.DB, blockChain core.BlockChain) shared.Transformer { - converter := CatFileChopLumpConverter{} - fetcher := shared.NewFetcher(blockChain) - repository := NewCatFileChopLumpRepository(db) - return CatFileChopLumpTransformer{ - Config: initializer.Config, - Converter: converter, - Fetcher: fetcher, - Repository: repository, - } -} - -type CatFileChopLumpTransformer struct { - Config shared.TransformerConfig - Converter Converter - Fetcher shared.LogFetcher - Repository Repository -} - -func (transformer CatFileChopLumpTransformer) Execute() error { - missingHeaders, err := transformer.Repository.MissingHeaders(transformer.Config.StartingBlockNumber, transformer.Config.EndingBlockNumber) - if err != nil { - return err - } - for _, header := range missingHeaders { - topics := [][]common.Hash{{common.HexToHash(shared.CatFileChopLumpSignature)}} - matchingLogs, err := transformer.Fetcher.FetchLogs(cat_file.CatFileConfig.ContractAddresses, topics, header.BlockNumber) - if err != nil { - return err - } - if len(matchingLogs) < 1 { - err = transformer.Repository.MarkHeaderChecked(header.Id) - if err != nil { - return err - } - } - models, err := transformer.Converter.ToModels(matchingLogs) - if err != nil { - return err - } - err = transformer.Repository.Create(header.Id, models) - if err != nil { - return err - } - } - return nil -} diff --git a/pkg/transformers/test_data/mocks/cat_file/flip/converter.go b/pkg/transformers/cat_file/flip/config.go similarity index 51% rename from pkg/transformers/test_data/mocks/cat_file/flip/converter.go rename to pkg/transformers/cat_file/flip/config.go index 687ab41e..9ea57237 100644 --- a/pkg/transformers/test_data/mocks/cat_file/flip/converter.go +++ b/pkg/transformers/cat_file/flip/config.go @@ -14,22 +14,13 @@ package flip -import ( - "github.com/ethereum/go-ethereum/core/types" - "github.com/vulcanize/vulcanizedb/pkg/transformers/cat_file/flip" - "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" -) +import "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" -type MockCatFileFlipConverter struct { - err error - PassedLogs []types.Log -} - -func (converter *MockCatFileFlipConverter) ToModels(ethLogs []types.Log) ([]flip.CatFileFlipModel, error) { - converter.PassedLogs = ethLogs - return []flip.CatFileFlipModel{test_data.CatFileFlipModel}, converter.err -} - -func (converter *MockCatFileFlipConverter) SetConverterError(e error) { - converter.err = e +var CatFileFlipConfig = shared.SingleTransformerConfig{ + TransformerName: shared.CatFileFlipLabel, + ContractAddresses: []string{shared.CatContractAddress}, + ContractAbi: shared.CatABI, + Topic: shared.CatFileFlipSignature, + StartingBlockNumber: 0, + EndingBlockNumber: 10000000, } diff --git a/pkg/transformers/cat_file/flip/converter.go b/pkg/transformers/cat_file/flip/converter.go index 59beb16d..9a313f1e 100644 --- a/pkg/transformers/cat_file/flip/converter.go +++ b/pkg/transformers/cat_file/flip/converter.go @@ -23,14 +23,10 @@ import ( "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" ) -type Converter interface { - ToModels(ethLogs []types.Log) ([]CatFileFlipModel, error) -} - type CatFileFlipConverter struct{} -func (CatFileFlipConverter) ToModels(ethLogs []types.Log) ([]CatFileFlipModel, error) { - var results []CatFileFlipModel +func (CatFileFlipConverter) ToModels(ethLogs []types.Log) ([]interface{}, error) { + var results []interface{} for _, ethLog := range ethLogs { err := verifyLog(ethLog) if err != nil { diff --git a/pkg/transformers/cat_file/flip/repository.go b/pkg/transformers/cat_file/flip/repository.go index fd55b73e..ac0d6071 100644 --- a/pkg/transformers/cat_file/flip/repository.go +++ b/pkg/transformers/cat_file/flip/repository.go @@ -15,34 +15,31 @@ package flip import ( + "fmt" "github.com/vulcanize/vulcanizedb/pkg/core" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" ) -type Repository interface { - Create(headerID int64, models []CatFileFlipModel) error - MarkHeaderChecked(headerID int64) error - MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) -} - type CatFileFlipRepository struct { db *postgres.DB } -func NewCatFileFlipRepository(db *postgres.DB) CatFileFlipRepository { - return CatFileFlipRepository{db: db} -} - -func (repository CatFileFlipRepository) Create(headerID int64, models []CatFileFlipModel) error { +func (repository CatFileFlipRepository) Create(headerID int64, models []interface{}) error { tx, err := repository.db.Begin() if err != nil { return err } for _, model := range models { + flip, ok := model.(CatFileFlipModel) + if !ok { + tx.Rollback() + return fmt.Errorf("model of type %T, not %T", model, CatFileFlipModel{}) + } + _, err = repository.db.Exec( `INSERT into maker.cat_file_flip (header_id, ilk, what, flip, tx_idx, log_idx, raw_log) - VALUES($1, $2, $3, $4, $5, $6, $7)`, - headerID, model.Ilk, model.What, model.Flip, model.TransactionIndex, model.LogIndex, model.Raw, + VALUES($1, $2, $3, $4, $5, $6, $7)`, + headerID, flip.Ilk, flip.What, flip.Flip, flip.TransactionIndex, flip.LogIndex, flip.Raw, ) if err != nil { tx.Rollback() @@ -50,9 +47,10 @@ func (repository CatFileFlipRepository) Create(headerID int64, models []CatFileF } } _, err = tx.Exec(`INSERT INTO public.checked_headers (header_id, cat_file_flip_checked) - VALUES ($1, $2) - ON CONFLICT (header_id) DO - UPDATE SET cat_file_flip_checked = $2`, headerID, true) + VALUES ($1, $2) + ON CONFLICT (header_id) DO + UPDATE SET cat_file_flip_checked = $2`, headerID, true) + if err != nil { tx.Rollback() return err @@ -62,9 +60,9 @@ func (repository CatFileFlipRepository) Create(headerID int64, models []CatFileF func (repository CatFileFlipRepository) MarkHeaderChecked(headerID int64) error { _, err := repository.db.Exec(`INSERT INTO public.checked_headers (header_id, cat_file_flip_checked) - VALUES ($1, $2) - ON CONFLICT (header_id) DO - UPDATE SET cat_file_flip_checked = $2`, headerID, true) + VALUES ($1, $2) + ON CONFLICT (header_id) DO + UPDATE SET cat_file_flip_checked = $2`, headerID, true) return err } @@ -84,3 +82,7 @@ func (repository CatFileFlipRepository) MissingHeaders(startingBlockNumber, endi ) return result, err } + +func (repository *CatFileFlipRepository) SetDB(db *postgres.DB) { + repository.db = db +} diff --git a/pkg/transformers/cat_file/flip/transformer.go b/pkg/transformers/cat_file/flip/transformer.go deleted file mode 100644 index 2be24b6b..00000000 --- a/pkg/transformers/cat_file/flip/transformer.go +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright 2018 Vulcanize -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package flip - -import ( - "github.com/ethereum/go-ethereum/common" - - "github.com/vulcanize/vulcanizedb/pkg/core" - "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" - "github.com/vulcanize/vulcanizedb/pkg/transformers/cat_file" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" -) - -type CatFileFlipTransformerInitializer struct { - Config shared.TransformerConfig -} - -func (initializer CatFileFlipTransformerInitializer) NewCatFileFlipTransformer(db *postgres.DB, blockChain core.BlockChain) shared.Transformer { - converter := CatFileFlipConverter{} - fetcher := shared.NewFetcher(blockChain) - repository := NewCatFileFlipRepository(db) - return CatFileFlipTransformer{ - Config: initializer.Config, - Converter: converter, - Fetcher: fetcher, - Repository: repository, - } -} - -type CatFileFlipTransformer struct { - Config shared.TransformerConfig - Converter Converter - Fetcher shared.LogFetcher - Repository Repository -} - -func (transformer CatFileFlipTransformer) Execute() error { - missingHeaders, err := transformer.Repository.MissingHeaders(transformer.Config.StartingBlockNumber, transformer.Config.EndingBlockNumber) - if err != nil { - return err - } - for _, header := range missingHeaders { - topics := [][]common.Hash{{common.HexToHash(shared.CatFileFlipSignature)}} - matchingLogs, err := transformer.Fetcher.FetchLogs(cat_file.CatFileConfig.ContractAddresses, topics, header.BlockNumber) - if err != nil { - return err - } - if len(matchingLogs) < 1 { - err = transformer.Repository.MarkHeaderChecked(header.Id) - if err != nil { - return err - } - } - models, err := transformer.Converter.ToModels(matchingLogs) - if err != nil { - return err - } - err = transformer.Repository.Create(header.Id, models) - if err != nil { - return err - } - } - return nil -} diff --git a/pkg/transformers/test_data/mocks/cat_file/pit_vow/converter.go b/pkg/transformers/cat_file/pit_vow/config.go similarity index 50% rename from pkg/transformers/test_data/mocks/cat_file/pit_vow/converter.go rename to pkg/transformers/cat_file/pit_vow/config.go index 7eb6a26c..678f4c57 100644 --- a/pkg/transformers/test_data/mocks/cat_file/pit_vow/converter.go +++ b/pkg/transformers/cat_file/pit_vow/config.go @@ -14,22 +14,13 @@ package pit_vow -import ( - "github.com/ethereum/go-ethereum/core/types" - "github.com/vulcanize/vulcanizedb/pkg/transformers/cat_file/pit_vow" - "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" -) +import "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" -type MockCatFilePitVowConverter struct { - err error - PassedLogs []types.Log -} - -func (converter *MockCatFilePitVowConverter) ToModels(ethLogs []types.Log) ([]pit_vow.CatFilePitVowModel, error) { - converter.PassedLogs = ethLogs - return []pit_vow.CatFilePitVowModel{test_data.CatFilePitVowModel}, converter.err -} - -func (converter *MockCatFilePitVowConverter) SetConverterError(e error) { - converter.err = e +var CatFilePitVowConfig = shared.SingleTransformerConfig{ + TransformerName: shared.CatFilePitVowLabel, + ContractAddresses: []string{shared.CatContractAddress}, + ContractAbi: shared.CatABI, + Topic: shared.CatFilePitVowSignature, + StartingBlockNumber: 0, + EndingBlockNumber: 10000000, } diff --git a/pkg/transformers/cat_file/pit_vow/converter.go b/pkg/transformers/cat_file/pit_vow/converter.go index a2f40879..873838a9 100644 --- a/pkg/transformers/cat_file/pit_vow/converter.go +++ b/pkg/transformers/cat_file/pit_vow/converter.go @@ -23,19 +23,16 @@ import ( "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" ) -type Converter interface { - ToModels(ethLogs []types.Log) ([]CatFilePitVowModel, error) -} - type CatFilePitVowConverter struct{} -func (CatFilePitVowConverter) ToModels(ethLogs []types.Log) ([]CatFilePitVowModel, error) { - var results []CatFilePitVowModel +func (CatFilePitVowConverter) ToModels(ethLogs []types.Log) ([]interface{}, error) { + var results []interface{} for _, ethLog := range ethLogs { err := verifyLog(ethLog) if err != nil { return nil, err } + what := string(bytes.Trim(ethLog.Topics[2].Bytes(), "\x00")) data := common.BytesToAddress(ethLog.Topics[3].Bytes()).String() @@ -43,6 +40,7 @@ func (CatFilePitVowConverter) ToModels(ethLogs []types.Log) ([]CatFilePitVowMode if err != nil { return nil, err } + result := CatFilePitVowModel{ What: what, Data: data, diff --git a/pkg/transformers/cat_file/pit_vow/repository.go b/pkg/transformers/cat_file/pit_vow/repository.go index 01c168fd..11f2c242 100644 --- a/pkg/transformers/cat_file/pit_vow/repository.go +++ b/pkg/transformers/cat_file/pit_vow/repository.go @@ -15,34 +15,31 @@ package pit_vow import ( + "fmt" "github.com/vulcanize/vulcanizedb/pkg/core" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" ) -type Repository interface { - Create(headerID int64, models []CatFilePitVowModel) error - MarkHeaderChecked(headerID int64) error - MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) -} - type CatFilePitVowRepository struct { db *postgres.DB } -func NewCatFilePitVowRepository(db *postgres.DB) CatFilePitVowRepository { - return CatFilePitVowRepository{db: db} -} - -func (repository CatFilePitVowRepository) Create(headerID int64, models []CatFilePitVowModel) error { +func (repository CatFilePitVowRepository) Create(headerID int64, models []interface{}) error { tx, err := repository.db.Begin() if err != nil { return err } for _, model := range models { + vow, ok := model.(CatFilePitVowModel) + if !ok { + tx.Rollback() + return fmt.Errorf("model of type %T, not %T", model, CatFilePitVowModel{}) + } + _, err = repository.db.Exec( `INSERT into maker.cat_file_pit_vow (header_id, what, data, tx_idx, log_idx, raw_log) - VALUES($1, $2, $3, $4, $5, $6)`, - headerID, model.What, model.Data, model.TransactionIndex, model.LogIndex, model.Raw, + VALUES($1, $2, $3, $4, $5, $6)`, + headerID, vow.What, vow.Data, vow.TransactionIndex, vow.LogIndex, vow.Raw, ) if err != nil { tx.Rollback() @@ -50,9 +47,9 @@ func (repository CatFilePitVowRepository) Create(headerID int64, models []CatFil } } _, err = tx.Exec(`INSERT INTO public.checked_headers (header_id, cat_file_pit_vow_checked) - VALUES ($1, $2) - ON CONFLICT (header_id) DO - UPDATE SET cat_file_pit_vow_checked = $2`, headerID, true) + VALUES ($1, $2) + ON CONFLICT (header_id) DO + UPDATE SET cat_file_pit_vow_checked = $2`, headerID, true) if err != nil { tx.Rollback() return err @@ -62,9 +59,9 @@ func (repository CatFilePitVowRepository) Create(headerID int64, models []CatFil func (repository CatFilePitVowRepository) MarkHeaderChecked(headerID int64) error { _, err := repository.db.Exec(`INSERT INTO public.checked_headers (header_id, cat_file_pit_vow_checked) - VALUES ($1, $2) - ON CONFLICT (header_id) DO - UPDATE SET cat_file_pit_vow_checked = $2`, headerID, true) + VALUES ($1, $2) + ON CONFLICT (header_id) DO + UPDATE SET cat_file_pit_vow_checked = $2`, headerID, true) return err } @@ -73,14 +70,18 @@ func (repository CatFilePitVowRepository) MissingHeaders(startingBlockNumber, en err := repository.db.Select( &result, `SELECT headers.id, headers.block_number FROM headers - LEFT JOIN checked_headers on headers.id = header_id - WHERE (header_id ISNULL OR cat_file_pit_vow_checked IS FALSE) - AND headers.block_number >= $1 - AND headers.block_number <= $2 - AND headers.eth_node_fingerprint = $3`, + LEFT JOIN checked_headers on headers.id = header_id + WHERE (header_id ISNULL OR cat_file_pit_vow_checked IS FALSE) + AND headers.block_number >= $1 + AND headers.block_number <= $2 + AND headers.eth_node_fingerprint = $3`, startingBlockNumber, endingBlockNumber, repository.db.Node.ID, ) return result, err } + +func (repository *CatFilePitVowRepository) SetDB(db *postgres.DB) { + repository.db = db +} diff --git a/pkg/transformers/cat_file/pit_vow/transformer.go b/pkg/transformers/cat_file/pit_vow/transformer.go deleted file mode 100644 index c748b572..00000000 --- a/pkg/transformers/cat_file/pit_vow/transformer.go +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright 2018 Vulcanize -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package pit_vow - -import ( - "github.com/ethereum/go-ethereum/common" - "github.com/vulcanize/vulcanizedb/pkg/core" - "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" - "github.com/vulcanize/vulcanizedb/pkg/transformers/cat_file" - "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" -) - -type CatFilePitVowTransformerInitializer struct { - Config shared.TransformerConfig -} - -func (initializer CatFilePitVowTransformerInitializer) NewCatFilePitVowTransformer(db *postgres.DB, blockChain core.BlockChain) shared.Transformer { - converter := CatFilePitVowConverter{} - fetcher := shared.NewFetcher(blockChain) - repository := NewCatFilePitVowRepository(db) - return CatFilePitVowTransformer{ - Config: initializer.Config, - Converter: converter, - Fetcher: fetcher, - Repository: repository, - } -} - -type CatFilePitVowTransformer struct { - Config shared.TransformerConfig - Converter Converter - Fetcher shared.LogFetcher - Repository Repository -} - -func (transformer CatFilePitVowTransformer) Execute() error { - missingHeaders, err := transformer.Repository.MissingHeaders(transformer.Config.StartingBlockNumber, transformer.Config.EndingBlockNumber) - if err != nil { - return err - } - for _, header := range missingHeaders { - topics := [][]common.Hash{{common.HexToHash(shared.CatFilePitVowSignature)}} - matchingLogs, err := transformer.Fetcher.FetchLogs(cat_file.CatFileConfig.ContractAddresses, topics, header.BlockNumber) - if err != nil { - return err - } - if len(matchingLogs) < 1 { - err = transformer.Repository.MarkHeaderChecked(header.Id) - if err != nil { - return err - } - } - models, err := transformer.Converter.ToModels(matchingLogs) - if err != nil { - return err - } - err = transformer.Repository.Create(header.Id, models) - if err != nil { - return err - } - } - return nil -} diff --git a/pkg/transformers/factories/transformer.go b/pkg/transformers/factories/transformer.go index 93c7048e..f625c1e0 100644 --- a/pkg/transformers/factories/transformer.go +++ b/pkg/transformers/factories/transformer.go @@ -53,7 +53,7 @@ func (transformer Transformer) Execute() error { transformerName := transformer.Config.TransformerName missingHeaders, err := transformer.Repository.MissingHeaders(transformer.Config.StartingBlockNumber, transformer.Config.EndingBlockNumber) if err != nil { - log.Printf("Error fetching mising headers in %v transformer: %v \n", transformerName, err) + log.Printf("Error fetching missing headers in %v transformer: %v \n", transformerName, err) return err } diff --git a/pkg/transformers/test_data/mocks/cat_file/chop_lump/converter.go b/pkg/transformers/test_data/mocks/cat_file/chop_lump/converter.go deleted file mode 100644 index 559cd05b..00000000 --- a/pkg/transformers/test_data/mocks/cat_file/chop_lump/converter.go +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2018 Vulcanize -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package chop_lump - -import ( - "github.com/ethereum/go-ethereum/core/types" - "github.com/vulcanize/vulcanizedb/pkg/transformers/cat_file/chop_lump" - "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" -) - -type MockCatFileChopLumpConverter struct { - Err error - PassedLogs []types.Log -} - -func (converter *MockCatFileChopLumpConverter) ToModels(ethLogs []types.Log) ([]chop_lump.CatFileChopLumpModel, error) { - converter.PassedLogs = ethLogs - return []chop_lump.CatFileChopLumpModel{test_data.CatFileChopLumpModel}, converter.Err -} - -func (converter *MockCatFileChopLumpConverter) SetConverterError(e error) { - converter.Err = e -} diff --git a/pkg/transformers/test_data/mocks/cat_file/chop_lump/repository.go b/pkg/transformers/test_data/mocks/cat_file/chop_lump/repository.go deleted file mode 100644 index bebc85ab..00000000 --- a/pkg/transformers/test_data/mocks/cat_file/chop_lump/repository.go +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright 2018 Vulcanize -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package chop_lump - -import ( - . "github.com/onsi/gomega" - - "github.com/vulcanize/vulcanizedb/pkg/core" - "github.com/vulcanize/vulcanizedb/pkg/transformers/cat_file/chop_lump" -) - -type MockCatFileChopLumpRepository struct { - createErr error - markHeaderCheckedErr error - markHeaderCheckedPassedHeaderID int64 - missingHeaders []core.Header - missingHeadersErr error - PassedStartingBlockNumber int64 - PassedEndingBlockNumber int64 - PassedHeaderID int64 - PassedModels []chop_lump.CatFileChopLumpModel -} - -func (repository *MockCatFileChopLumpRepository) Create(headerID int64, models []chop_lump.CatFileChopLumpModel) error { - repository.PassedHeaderID = headerID - repository.PassedModels = models - return repository.createErr -} - -func (repository *MockCatFileChopLumpRepository) MarkHeaderChecked(headerID int64) error { - repository.markHeaderCheckedPassedHeaderID = headerID - return repository.markHeaderCheckedErr -} - -func (repository *MockCatFileChopLumpRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { - repository.PassedStartingBlockNumber = startingBlockNumber - repository.PassedEndingBlockNumber = endingBlockNumber - return repository.missingHeaders, repository.missingHeadersErr -} - -func (repository *MockCatFileChopLumpRepository) SetMissingHeadersErr(e error) { - repository.missingHeadersErr = e -} - -func (repository *MockCatFileChopLumpRepository) SetMissingHeaders(headers []core.Header) { - repository.missingHeaders = headers -} - -func (repository *MockCatFileChopLumpRepository) SetCreateError(e error) { - repository.createErr = e -} - -func (repository *MockCatFileChopLumpRepository) SetMarkHeaderCheckedErr(e error) { - repository.markHeaderCheckedErr = e -} - -func (repository *MockCatFileChopLumpRepository) AssertMarkHeaderCheckedCalledWith(i int64) { - Expect(repository.markHeaderCheckedPassedHeaderID).To(Equal(i)) -} diff --git a/pkg/transformers/test_data/mocks/cat_file/flip/repository.go b/pkg/transformers/test_data/mocks/cat_file/flip/repository.go deleted file mode 100644 index 72fba300..00000000 --- a/pkg/transformers/test_data/mocks/cat_file/flip/repository.go +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright 2018 Vulcanize -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package flip - -import ( - . "github.com/onsi/gomega" - - "github.com/vulcanize/vulcanizedb/pkg/core" - "github.com/vulcanize/vulcanizedb/pkg/transformers/cat_file/flip" -) - -type MockCatFileFlipRepository struct { - createErr error - markHeaderCheckedErr error - markHeaderCheckedPassedHeaderID int64 - missingHeadersErr error - missingHeaders []core.Header - PassedStartingBlockNumber int64 - PassedEndingBlockNumber int64 - PassedHeaderID int64 - PassedModels []flip.CatFileFlipModel -} - -func (repository *MockCatFileFlipRepository) Create(headerID int64, models []flip.CatFileFlipModel) error { - repository.PassedHeaderID = headerID - repository.PassedModels = models - return repository.createErr -} - -func (repository *MockCatFileFlipRepository) MarkHeaderChecked(headerID int64) error { - repository.markHeaderCheckedPassedHeaderID = headerID - return repository.markHeaderCheckedErr -} - -func (repository *MockCatFileFlipRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { - repository.PassedStartingBlockNumber = startingBlockNumber - repository.PassedEndingBlockNumber = endingBlockNumber - return repository.missingHeaders, repository.missingHeadersErr -} - -func (repository *MockCatFileFlipRepository) SetMissingHeadersErr(e error) { - repository.missingHeadersErr = e -} - -func (repository *MockCatFileFlipRepository) SetMissingHeaders(headers []core.Header) { - repository.missingHeaders = headers -} - -func (repository *MockCatFileFlipRepository) SetCreateError(e error) { - repository.createErr = e -} - -func (repository *MockCatFileFlipRepository) SetMarkHeaderCheckedErr(e error) { - repository.markHeaderCheckedErr = e -} - -func (repository *MockCatFileFlipRepository) AssertMarkHeaderCheckedCalledWith(i int64) { - Expect(repository.markHeaderCheckedPassedHeaderID).To(Equal(i)) -} diff --git a/pkg/transformers/test_data/mocks/cat_file/pit_vow/repository.go b/pkg/transformers/test_data/mocks/cat_file/pit_vow/repository.go deleted file mode 100644 index f9d7e557..00000000 --- a/pkg/transformers/test_data/mocks/cat_file/pit_vow/repository.go +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright 2018 Vulcanize -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package pit_vow - -import ( - . "github.com/onsi/gomega" - - "github.com/vulcanize/vulcanizedb/pkg/core" - "github.com/vulcanize/vulcanizedb/pkg/transformers/cat_file/pit_vow" -) - -type MockCatFilePitVowRepository struct { - createErr error - markHeaderCheckedErr error - markHeaderCheckedPassedHeaderID int64 - missingHeaders []core.Header - missingHeadersErr error - PassedStartingBlockNumber int64 - PassedEndingBlockNumber int64 - PassedHeaderID int64 - PassedModels []pit_vow.CatFilePitVowModel -} - -func (repository *MockCatFilePitVowRepository) Create(headerID int64, models []pit_vow.CatFilePitVowModel) error { - repository.PassedHeaderID = headerID - repository.PassedModels = models - return repository.createErr -} - -func (repository *MockCatFilePitVowRepository) MarkHeaderChecked(headerID int64) error { - repository.markHeaderCheckedPassedHeaderID = headerID - return repository.markHeaderCheckedErr -} - -func (repository *MockCatFilePitVowRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { - repository.PassedStartingBlockNumber = startingBlockNumber - repository.PassedEndingBlockNumber = endingBlockNumber - return repository.missingHeaders, repository.missingHeadersErr -} - -func (repository *MockCatFilePitVowRepository) SetMissingHeadersErr(e error) { - repository.missingHeadersErr = e -} - -func (repository *MockCatFilePitVowRepository) SetMissingHeaders(headers []core.Header) { - repository.missingHeaders = headers -} - -func (repository *MockCatFilePitVowRepository) SetCreateError(e error) { - repository.createErr = e -} - -func (repository *MockCatFilePitVowRepository) SetMarkHeaderCheckedErr(e error) { - repository.markHeaderCheckedErr = e -} - -func (repository *MockCatFilePitVowRepository) AssertMarkHeaderCheckedCalledWith(i int64) { - Expect(repository.markHeaderCheckedPassedHeaderID).To(Equal(i)) -} diff --git a/pkg/transformers/transformers.go b/pkg/transformers/transformers.go index 22ed1ea7..dfa6f955 100644 --- a/pkg/transformers/transformers.go +++ b/pkg/transformers/transformers.go @@ -16,7 +16,6 @@ package transformers import ( "github.com/vulcanize/vulcanizedb/pkg/transformers/bite" - "github.com/vulcanize/vulcanizedb/pkg/transformers/cat_file" "github.com/vulcanize/vulcanizedb/pkg/transformers/cat_file/chop_lump" "github.com/vulcanize/vulcanizedb/pkg/transformers/cat_file/flip" "github.com/vulcanize/vulcanizedb/pkg/transformers/cat_file/pit_vow" @@ -50,14 +49,31 @@ import ( var ( BiteTransformerInitializer = bite.BiteTransformerInitializer{Config: bite.BiteConfig}.NewBiteTransformer - catFileConfig = cat_file.CatFileConfig - CatFileChopLumpTransformerInitializer = chop_lump.CatFileChopLumpTransformerInitializer{Config: catFileConfig}.NewCatFileChopLumpTransformer - CatFileFlipTransformerInitializer = flip.CatFileFlipTransformerInitializer{Config: catFileConfig}.NewCatFileFlipTransformer - CatFilePitVowTransformerInitializer = pit_vow.CatFilePitVowTransformerInitializer{Config: catFileConfig}.NewCatFilePitVowTransformer - DealTransformerInitializer = deal.DealTransformerInitializer{Config: deal.Config}.NewDealTransformer - DentTransformerInitializer = dent.DentTransformerInitializer{Config: dent.DentConfig}.NewDentTransformer - DripDripTransformerInitializer = drip_drip.DripDripTransformerInitializer{Config: drip_drip.DripDripConfig}.NewDripDripTransformer - DripFileIlkTransformerInitializer = factories.Transformer{ + CatFileChopLumpTransformerInitializer = factories.Transformer{ + Config: chop_lump.CatFileChopLumpConfig, + Converter: &chop_lump.CatFileChopLumpConverter{}, + Repository: &chop_lump.CatFileChopLumpRepository{}, + Fetcher: &shared.Fetcher{}, + }.NewTransformer + + CatFileFlipTransformerInitializer = factories.Transformer{ + Config: flip.CatFileFlipConfig, + Converter: &flip.CatFileFlipConverter{}, + Repository: &flip.CatFileFlipRepository{}, + Fetcher: &shared.Fetcher{}, + }.NewTransformer + + CatFilePitVowTransformerInitializer = factories.Transformer{ + Config: pit_vow.CatFilePitVowConfig, + Converter: &pit_vow.CatFilePitVowConverter{}, + Repository: &pit_vow.CatFilePitVowRepository{}, + Fetcher: &shared.Fetcher{}, + }.NewTransformer + + DealTransformerInitializer = deal.DealTransformerInitializer{Config: deal.Config}.NewDealTransformer + DentTransformerInitializer = dent.DentTransformerInitializer{Config: dent.DentConfig}.NewDentTransformer + DripDripTransformerInitializer = drip_drip.DripDripTransformerInitializer{Config: drip_drip.DripDripConfig}.NewDripDripTransformer + DripFileIlkTransformerInitializer = factories.Transformer{ Config: ilk2.DripFileIlkConfig, Converter: &ilk2.DripFileIlkConverter{}, Repository: &ilk2.DripFileIlkRepository{},