Factorise cat_file transformers

This commit is contained in:
Edvard 2018-10-25 17:16:21 +02:00 committed by Rob Mulholand
parent 47a3c35938
commit 28ab5f92ab
18 changed files with 126 additions and 607 deletions

View File

@ -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,
}

View File

@ -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 {

View File

@ -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
}

View File

@ -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
}

View File

@ -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,
}

View File

@ -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 {

View File

@ -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
}

View File

@ -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
}

View File

@ -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,
}

View File

@ -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,

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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))
}

View File

@ -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))
}

View File

@ -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))
}

View File

@ -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{},