diff --git a/db/migrations/1537814159_add_contract_address_to_deal.down.sql b/db/migrations/1537814159_add_contract_address_to_deal.down.sql new file mode 100644 index 00000000..f7ee591b --- /dev/null +++ b/db/migrations/1537814159_add_contract_address_to_deal.down.sql @@ -0,0 +1,2 @@ +ALTER TABLE maker.deal + DROP COLUMN contract_address; diff --git a/db/migrations/1537814159_add_contract_address_to_deal.up.sql b/db/migrations/1537814159_add_contract_address_to_deal.up.sql new file mode 100644 index 00000000..979be471 --- /dev/null +++ b/db/migrations/1537814159_add_contract_address_to_deal.up.sql @@ -0,0 +1,2 @@ +ALTER TABLE maker.deal + ADD COLUMN contract_address VARCHAR; diff --git a/db/schema.sql b/db/schema.sql index 52535a9d..779749d1 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -105,7 +105,8 @@ CREATE TABLE maker.deal ( header_id integer NOT NULL, bid_id numeric NOT NULL, tx_idx integer NOT NULL, - raw_log jsonb + raw_log jsonb, + contract_address character varying ); diff --git a/pkg/transformers/bite/config.go b/pkg/transformers/bite/config.go index 4908cd0b..10b7785d 100644 --- a/pkg/transformers/bite/config.go +++ b/pkg/transformers/bite/config.go @@ -21,7 +21,7 @@ import ( ) var BiteConfig = shared.TransformerConfig{ - ContractAddress: shared.CatContractAddress, + ContractAddresses: []string{shared.CatContractAddress}, ContractAbi: shared.CatABI, Topics: []string{shared.BiteSignature}, StartingBlockNumber: 0, diff --git a/pkg/transformers/bite/integration_test.go b/pkg/transformers/bite/integration_test.go index c446b349..30796178 100644 --- a/pkg/transformers/bite/integration_test.go +++ b/pkg/transformers/bite/integration_test.go @@ -51,7 +51,7 @@ var _ = Describe("Integration tests", func() { topic0 := common.HexToHash(shared.BiteSignature) topics := [][]common.Hash{{topic0}} - result, err := realFetcher.FetchLogs(shared.CatContractAddress, topics, int64(26)) + result, err := realFetcher.FetchLogs(bite.BiteConfig.ContractAddresses, topics, int64(26)) Expect(err).NotTo(HaveOccurred()) Expect(len(result) > 0).To(BeTrue()) diff --git a/pkg/transformers/bite/transformer.go b/pkg/transformers/bite/transformer.go index 51828d77..afe793f3 100644 --- a/pkg/transformers/bite/transformer.go +++ b/pkg/transformers/bite/transformer.go @@ -62,14 +62,14 @@ func (b BiteTransformer) Execute() error { log.Printf("Fetching bite event logs for %d headers \n", len(missingHeaders)) for _, header := range missingHeaders { - ethLogs, err := b.Fetcher.FetchLogs(config.ContractAddress, topics, header.BlockNumber) + ethLogs, err := b.Fetcher.FetchLogs(config.ContractAddresses, topics, header.BlockNumber) if err != nil { log.Println("Error fetching matching logs:", err) return err } for _, ethLog := range ethLogs { - entity, err := b.Converter.ToEntity(config.ContractAddress, config.ContractAbi, ethLog) + entity, err := b.Converter.ToEntity(ethLog.Address.Hex(), config.ContractAbi, ethLog) model, err := b.Converter.ToModel(entity) if err != nil { log.Println("Error converting logs:", err) diff --git a/pkg/transformers/bite/transfromer_test.go b/pkg/transformers/bite/transfromer_test.go index 21e43fbb..6193c09b 100644 --- a/pkg/transformers/bite/transfromer_test.go +++ b/pkg/transformers/bite/transfromer_test.go @@ -38,7 +38,6 @@ var _ = Describe("Bite Transformer", func() { var transformer bite.BiteTransformer var blockNumber1 = rand.Int63() var blockNumber2 = rand.Int63() - var testConfig shared.TransformerConfig BeforeEach(func() { repository = bite_mocks.MockBiteRepository{} @@ -52,14 +51,7 @@ var _ = Describe("Bite Transformer", func() { Config: bite.BiteConfig, } - testConfig = shared.TransformerConfig{ - ContractAddress: "0x12345", - ContractAbi: "test abi", - Topics: []string{shared.BiteSignature}, - StartingBlockNumber: blockNumber1, - EndingBlockNumber: blockNumber2, - } - transformer.SetConfig(testConfig) + transformer.SetConfig(bite.BiteConfig) }) It("gets missing headers for blocks in the configured range", func() { @@ -85,7 +77,7 @@ var _ = Describe("Bite Transformer", func() { Expect(err).NotTo(HaveOccurred()) Expect(fetcher.FetchedBlocks).To(Equal([]int64{blockNumber1, blockNumber2})) Expect(fetcher.FetchedTopics).To(Equal(expectedTopics)) - Expect(fetcher.FetchedContractAddress).To(Equal(bite.BiteConfig.ContractAddress)) + Expect(fetcher.FetchedContractAddresses).To(Equal([][]string{bite.BiteConfig.ContractAddresses, bite.BiteConfig.ContractAddresses})) }) It("returns an error if fetching logs fails", func() { @@ -103,7 +95,7 @@ var _ = Describe("Bite Transformer", func() { err := transformer.Execute() Expect(err).NotTo(HaveOccurred()) - Expect(converter.ConverterContract).To(Equal(bite.BiteConfig.ContractAddress)) + Expect(converter.ConverterContract).To(Equal(test_data.EthBiteLog.Address.Hex())) Expect(converter.ConverterAbi).To(Equal(bite.BiteConfig.ContractAbi)) Expect(converter.LogsToConvert).To(Equal([]types.Log{test_data.EthBiteLog})) }) diff --git a/pkg/transformers/deal/config.go b/pkg/transformers/deal/config.go index 6764a6af..19449c57 100644 --- a/pkg/transformers/deal/config.go +++ b/pkg/transformers/deal/config.go @@ -17,7 +17,7 @@ package deal import "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" var Config = shared.TransformerConfig{ - ContractAddress: shared.FlipperContractAddress, + ContractAddresses: []string{shared.FlipperContractAddress, shared.FlopperContractAddress}, ContractAbi: shared.FlipperABI, Topics: []string{shared.DealSignature}, StartingBlockNumber: 0, diff --git a/pkg/transformers/deal/converter.go b/pkg/transformers/deal/converter.go index a544b190..b277ab79 100644 --- a/pkg/transformers/deal/converter.go +++ b/pkg/transformers/deal/converter.go @@ -46,11 +46,13 @@ func (DealConverter) ToModels(ethLogs []types.Log) (result []DealModel, err erro model := DealModel{ BidId: bidId.String(), + ContractAddress: log.Address.Hex(), TransactionIndex: log.TxIndex, Raw: raw, } result = append(result, model) } + return result, nil } diff --git a/pkg/transformers/deal/model.go b/pkg/transformers/deal/model.go index c434b45a..acb4d996 100644 --- a/pkg/transformers/deal/model.go +++ b/pkg/transformers/deal/model.go @@ -16,6 +16,7 @@ package deal type DealModel struct { BidId string `db:"bid_id"` + ContractAddress string `db:"contract_address"` TransactionIndex uint `db:"tx_idx"` Raw []byte `db:"raw_log"` } diff --git a/pkg/transformers/deal/repository.go b/pkg/transformers/deal/repository.go index c851518c..993a805f 100644 --- a/pkg/transformers/deal/repository.go +++ b/pkg/transformers/deal/repository.go @@ -38,9 +38,9 @@ func (r DealRepository) Create(headerId int64, models []DealModel) error { } for _, model := range models { _, err = tx.Exec( - `INSERT into maker.deal (header_id, bid_id, tx_idx, raw_log) - VALUES($1, $2, $3, $4)`, - headerId, model.BidId, model.TransactionIndex, model.Raw, + `INSERT into maker.deal (header_id, bid_id, contract_address, tx_idx, raw_log) + VALUES($1, $2, $3, $4, $5)`, + headerId, model.BidId, model.ContractAddress, model.TransactionIndex, model.Raw, ) if err != nil { tx.Rollback() @@ -48,7 +48,7 @@ func (r DealRepository) Create(headerId int64, models []DealModel) error { } } _, err = tx.Exec(`INSERT INTO public.checked_headers (header_id, deal_checked) - VALUES ($1, $2) + VALUES ($1, $2) ON CONFLICT (header_id) DO UPDATE SET deal_checked = $2`, headerId, true) if err != nil { @@ -60,7 +60,7 @@ func (r DealRepository) Create(headerId int64, models []DealModel) error { func (r DealRepository) MarkHeaderChecked(headerID int64) error { _, err := r.db.Exec(`INSERT INTO public.checked_headers (header_id, deal_checked) - VALUES ($1, $2) + VALUES ($1, $2) ON CONFLICT (header_id) DO UPDATE SET deal_checked = $2`, headerID, true) return err diff --git a/pkg/transformers/deal/repository_test.go b/pkg/transformers/deal/repository_test.go index f0614f57..46c7fc22 100644 --- a/pkg/transformers/deal/repository_test.go +++ b/pkg/transformers/deal/repository_test.go @@ -57,9 +57,10 @@ var _ = Describe("Deal Repository", func() { db.QueryRow(`SELECT count(*) FROM maker.deal`).Scan(&count) Expect(count).To(Equal(1)) var dbResult deal.DealModel - err = db.Get(&dbResult, `SELECT bid_id, tx_idx, raw_log FROM maker.deal WHERE header_id = $1`, headerId) + err = db.Get(&dbResult, `SELECT bid_id, contract_address, tx_idx, raw_log FROM maker.deal WHERE header_id = $1`, headerId) Expect(err).NotTo(HaveOccurred()) Expect(dbResult.BidId).To(Equal(test_data.DealModel.BidId)) + Expect(dbResult.ContractAddress).To(Equal(test_data.DealModel.ContractAddress)) Expect(dbResult.TransactionIndex).To(Equal(test_data.DealModel.TransactionIndex)) Expect(dbResult.Raw).To(MatchJSON(test_data.DealModel.Raw)) }) diff --git a/pkg/transformers/deal/transformer.go b/pkg/transformers/deal/transformer.go index 1325619a..890d36b0 100644 --- a/pkg/transformers/deal/transformer.go +++ b/pkg/transformers/deal/transformer.go @@ -58,7 +58,7 @@ func (t DealTransformer) Execute() error { log.Printf("Fetching deal event logs for %d headers \n", len(headers)) for _, header := range headers { - ethLogs, err := t.Fetcher.FetchLogs(config.ContractAddress, topics, header.BlockNumber) + ethLogs, err := t.Fetcher.FetchLogs(config.ContractAddresses, topics, header.BlockNumber) if err != nil { log.Println("Error fetching deal logs:", err) return err diff --git a/pkg/transformers/deal/transformer_test.go b/pkg/transformers/deal/transformer_test.go index fd0c0ac0..0399797c 100644 --- a/pkg/transformers/deal/transformer_test.go +++ b/pkg/transformers/deal/transformer_test.go @@ -68,7 +68,7 @@ var _ = Describe("DealTransformer", func() { dealRepository.SetMissingHeaders([]core.Header{header1, header2}) err := transformer.Execute() Expect(err).NotTo(HaveOccurred()) - Expect(fetcher.FetchedContractAddress).To(Equal(config.ContractAddress)) + Expect(fetcher.FetchedContractAddresses).To(Equal([][]string{config.ContractAddresses, config.ContractAddresses})) expectedTopics := [][]common.Hash{{common.HexToHash(shared.DealSignature)}} Expect(fetcher.FetchedTopics).To(Equal(expectedTopics)) Expect(fetcher.FetchedBlocks).To(Equal([]int64{header1.BlockNumber, header2.BlockNumber})) diff --git a/pkg/transformers/dent/config.go b/pkg/transformers/dent/config.go index 2b7b5a8d..c39c83b0 100644 --- a/pkg/transformers/dent/config.go +++ b/pkg/transformers/dent/config.go @@ -17,7 +17,7 @@ package dent import "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" var DentConfig = shared.TransformerConfig{ - ContractAddress: shared.FlipperContractAddress, + ContractAddresses: []string{shared.FlipperContractAddress}, ContractAbi: shared.FlipperABI, Topics: []string{shared.DentFunctionSignature}, StartingBlockNumber: 0, diff --git a/pkg/transformers/dent/transformer.go b/pkg/transformers/dent/transformer.go index e0ab0679..61be300a 100644 --- a/pkg/transformers/dent/transformer.go +++ b/pkg/transformers/dent/transformer.go @@ -53,7 +53,8 @@ func (t DentTransformer) Execute() error { headers, err := t.Repository.MissingHeaders(config.StartingBlockNumber, config.EndingBlockNumber) log.Printf("Fetching dent event logs for %d headers \n", len(headers)) for _, header := range headers { - ethLogs, err := t.Fetcher.FetchLogs(config.ContractAddress, topics, header.BlockNumber) + ethLogs, err := t.Fetcher.FetchLogs(config.ContractAddresses, topics, header.BlockNumber) + if err != nil { log.Println("Error fetching dent logs:", err) return err diff --git a/pkg/transformers/dent/transformer_test.go b/pkg/transformers/dent/transformer_test.go index fae5c0f1..8817d301 100644 --- a/pkg/transformers/dent/transformer_test.go +++ b/pkg/transformers/dent/transformer_test.go @@ -73,7 +73,7 @@ var _ = Describe("DentTransformer", func() { err := transformer.Execute() Expect(err).NotTo(HaveOccurred()) - Expect(fetcher.FetchedContractAddress).To(Equal(config.ContractAddress)) + Expect(fetcher.FetchedContractAddresses).To(Equal([][]string{config.ContractAddresses, config.ContractAddresses})) expectedTopics := [][]common.Hash{{common.HexToHash(shared.DentFunctionSignature)}} Expect(fetcher.FetchedTopics).To(Equal(expectedTopics)) Expect(fetcher.FetchedBlocks).To(Equal([]int64{header1.BlockNumber, header2.BlockNumber})) diff --git a/pkg/transformers/drip_drip/config.go b/pkg/transformers/drip_drip/config.go index 407910a9..ec305dbb 100644 --- a/pkg/transformers/drip_drip/config.go +++ b/pkg/transformers/drip_drip/config.go @@ -17,7 +17,7 @@ package drip_drip import "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" var DripDripConfig = shared.TransformerConfig{ - ContractAddress: shared.DripContractAddress, + ContractAddresses: []string{shared.DripContractAddress}, ContractAbi: shared.DripABI, Topics: []string{shared.DripDripSignature}, StartingBlockNumber: 0, diff --git a/pkg/transformers/drip_drip/transformer.go b/pkg/transformers/drip_drip/transformer.go index 5d3d6c14..c8e981f1 100644 --- a/pkg/transformers/drip_drip/transformer.go +++ b/pkg/transformers/drip_drip/transformer.go @@ -55,7 +55,7 @@ func (transformer DripDripTransformer) Execute() error { log.Printf("Fetching drip drip event logs for %d headers \n", len(missingHeaders)) for _, header := range missingHeaders { topics := [][]common.Hash{{common.HexToHash(shared.DripDripSignature)}} - matchingLogs, err := transformer.Fetcher.FetchLogs(transformer.Config.ContractAddress, topics, header.BlockNumber) + matchingLogs, err := transformer.Fetcher.FetchLogs(transformer.Config.ContractAddresses, topics, header.BlockNumber) if err != nil { return err } diff --git a/pkg/transformers/drip_drip/transformer_test.go b/pkg/transformers/drip_drip/transformer_test.go index a0b31321..ff2241be 100644 --- a/pkg/transformers/drip_drip/transformer_test.go +++ b/pkg/transformers/drip_drip/transformer_test.go @@ -76,7 +76,7 @@ var _ = Describe("Drip drip transformer", func() { Expect(err).NotTo(HaveOccurred()) Expect(fetcher.FetchedBlocks).To(Equal([]int64{1, 2})) - Expect(fetcher.FetchedContractAddress).To(Equal(drip_drip.DripDripConfig.ContractAddress)) + Expect(fetcher.FetchedContractAddresses).To(Equal([][]string{drip_drip.DripDripConfig.ContractAddresses, drip_drip.DripDripConfig.ContractAddresses})) Expect(fetcher.FetchedTopics).To(Equal([][]common.Hash{{common.HexToHash(shared.DripDripSignature)}})) }) diff --git a/pkg/transformers/drip_file/config.go b/pkg/transformers/drip_file/config.go index f1d2f503..7acf5252 100644 --- a/pkg/transformers/drip_file/config.go +++ b/pkg/transformers/drip_file/config.go @@ -17,7 +17,7 @@ package drip_file import "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" var DripFileConfig = shared.TransformerConfig{ - ContractAddress: shared.DripContractAddress, + ContractAddresses: []string{shared.DripContractAddress}, ContractAbi: shared.DripABI, Topics: []string{shared.DripFileIlkSignature, shared.DripFileRepoSignature}, StartingBlockNumber: 0, diff --git a/pkg/transformers/drip_file/ilk/transformer.go b/pkg/transformers/drip_file/ilk/transformer.go index 328e1415..fc07ea1a 100644 --- a/pkg/transformers/drip_file/ilk/transformer.go +++ b/pkg/transformers/drip_file/ilk/transformer.go @@ -56,7 +56,7 @@ func (transformer DripFileIlkTransformer) Execute() error { log.Printf("Fetching drip file ilk event logs for %d headers \n", len(missingHeaders)) for _, header := range missingHeaders { topics := [][]common.Hash{{common.HexToHash(shared.DripFileIlkSignature)}} - matchingLogs, err := transformer.Fetcher.FetchLogs(drip_file.DripFileConfig.ContractAddress, topics, header.BlockNumber) + matchingLogs, err := transformer.Fetcher.FetchLogs(drip_file.DripFileConfig.ContractAddresses, topics, header.BlockNumber) if err != nil { return err } diff --git a/pkg/transformers/drip_file/ilk/transformer_test.go b/pkg/transformers/drip_file/ilk/transformer_test.go index a3e12b55..d104cb0a 100644 --- a/pkg/transformers/drip_file/ilk/transformer_test.go +++ b/pkg/transformers/drip_file/ilk/transformer_test.go @@ -75,7 +75,7 @@ var _ = Describe("Drip file ilk transformer", func() { Expect(err).NotTo(HaveOccurred()) Expect(fetcher.FetchedBlocks).To(Equal([]int64{1, 2})) - Expect(fetcher.FetchedContractAddress).To(Equal(drip_file.DripFileConfig.ContractAddress)) + Expect(fetcher.FetchedContractAddresses).To(Equal([][]string{drip_file.DripFileConfig.ContractAddresses, drip_file.DripFileConfig.ContractAddresses})) Expect(fetcher.FetchedTopics).To(Equal([][]common.Hash{{common.HexToHash(shared.DripFileIlkSignature)}})) }) diff --git a/pkg/transformers/drip_file/repo/transformer.go b/pkg/transformers/drip_file/repo/transformer.go index d263bc0e..53920444 100644 --- a/pkg/transformers/drip_file/repo/transformer.go +++ b/pkg/transformers/drip_file/repo/transformer.go @@ -56,7 +56,7 @@ func (transformer DripFileRepoTransformer) Execute() error { log.Printf("Fetching drip file repo event logs for %d headers \n", len(missingHeaders)) for _, header := range missingHeaders { topics := [][]common.Hash{{common.HexToHash(shared.DripFileRepoSignature)}} - matchingLogs, err := transformer.Fetcher.FetchLogs(drip_file.DripFileConfig.ContractAddress, topics, header.BlockNumber) + matchingLogs, err := transformer.Fetcher.FetchLogs(drip_file.DripFileConfig.ContractAddresses, topics, header.BlockNumber) if err != nil { return err } diff --git a/pkg/transformers/drip_file/repo/transformer_test.go b/pkg/transformers/drip_file/repo/transformer_test.go index cc95feef..d526975c 100644 --- a/pkg/transformers/drip_file/repo/transformer_test.go +++ b/pkg/transformers/drip_file/repo/transformer_test.go @@ -76,7 +76,7 @@ var _ = Describe("Drip file repo transformer", func() { Expect(err).NotTo(HaveOccurred()) Expect(fetcher.FetchedBlocks).To(Equal([]int64{1, 2})) - Expect(fetcher.FetchedContractAddress).To(Equal(drip_file.DripFileConfig.ContractAddress)) + Expect(fetcher.FetchedContractAddresses).To(Equal([][]string{drip_file.DripFileConfig.ContractAddresses, drip_file.DripFileConfig.ContractAddresses})) Expect(fetcher.FetchedTopics).To(Equal([][]common.Hash{{common.HexToHash(shared.DripFileRepoSignature)}})) }) diff --git a/pkg/transformers/drip_file/vow/transformer.go b/pkg/transformers/drip_file/vow/transformer.go index 43975268..a37cb904 100644 --- a/pkg/transformers/drip_file/vow/transformer.go +++ b/pkg/transformers/drip_file/vow/transformer.go @@ -56,7 +56,7 @@ func (transformer DripFileVowTransformer) Execute() error { log.Printf("Fetching drip file vow event logs for %d headers \n", len(missingHeaders)) for _, header := range missingHeaders { topics := [][]common.Hash{{common.HexToHash(shared.DripFileVowSignature)}} - matchingLogs, err := transformer.Fetcher.FetchLogs(drip_file.DripFileConfig.ContractAddress, topics, header.BlockNumber) + matchingLogs, err := transformer.Fetcher.FetchLogs(drip_file.DripFileConfig.ContractAddresses, topics, header.BlockNumber) if err != nil { return err } diff --git a/pkg/transformers/drip_file/vow/transformer_test.go b/pkg/transformers/drip_file/vow/transformer_test.go index 9e82a6fa..cb7450d7 100644 --- a/pkg/transformers/drip_file/vow/transformer_test.go +++ b/pkg/transformers/drip_file/vow/transformer_test.go @@ -76,7 +76,7 @@ var _ = Describe("Drip file vow transformer", func() { Expect(err).NotTo(HaveOccurred()) Expect(fetcher.FetchedBlocks).To(Equal([]int64{1, 2})) - Expect(fetcher.FetchedContractAddress).To(Equal(drip_file.DripFileConfig.ContractAddress)) + Expect(fetcher.FetchedContractAddresses).To(Equal([][]string{drip_file.DripFileConfig.ContractAddresses, drip_file.DripFileConfig.ContractAddresses})) Expect(fetcher.FetchedTopics).To(Equal([][]common.Hash{{common.HexToHash(shared.DripFileVowSignature)}})) }) diff --git a/pkg/transformers/flip_kick/config.go b/pkg/transformers/flip_kick/config.go index 7c20c279..98fe2074 100644 --- a/pkg/transformers/flip_kick/config.go +++ b/pkg/transformers/flip_kick/config.go @@ -17,7 +17,7 @@ package flip_kick import "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" var FlipKickConfig = shared.TransformerConfig{ - ContractAddress: shared.FlipperContractAddress, + ContractAddresses: []string{shared.FlipperContractAddress}, ContractAbi: shared.FlipperABI, Topics: []string{shared.FlipKickSignature}, StartingBlockNumber: 0, diff --git a/pkg/transformers/flip_kick/converter.go b/pkg/transformers/flip_kick/converter.go index 9995eb83..8e12a69f 100644 --- a/pkg/transformers/flip_kick/converter.go +++ b/pkg/transformers/flip_kick/converter.go @@ -28,16 +28,16 @@ import ( ) type Converter interface { - ToEntities(contractAddress string, contractAbi string, ethLogs []types.Log) ([]FlipKickEntity, error) + ToEntities(contractAbi string, ethLogs []types.Log) ([]FlipKickEntity, error) ToModels(flipKicks []FlipKickEntity) ([]FlipKickModel, error) } type FlipKickConverter struct{} -func (FlipKickConverter) ToEntities(contractAddress string, contractAbi string, ethLogs []types.Log) (results []FlipKickEntity, err error) { +func (FlipKickConverter) ToEntities(contractAbi string, ethLogs []types.Log) (results []FlipKickEntity, err error) { for _, ethLog := range ethLogs { entity := &FlipKickEntity{} - address := common.HexToAddress(contractAddress) + address := ethLog.Address abi, err := geth.ParseAbi(contractAbi) if err != nil { return nil, err diff --git a/pkg/transformers/flip_kick/converter_test.go b/pkg/transformers/flip_kick/converter_test.go index f8e7f6c9..e867dc4c 100644 --- a/pkg/transformers/flip_kick/converter_test.go +++ b/pkg/transformers/flip_kick/converter_test.go @@ -33,7 +33,7 @@ var _ = Describe("FlipKick Converter", func() { Describe("ToEntity", func() { It("converts an Eth Log to a FlipKickEntity", func() { - entities, err := converter.ToEntities(shared.FlipperContractAddress, shared.FlipperABI, []types.Log{test_data.EthFlipKickLog}) + entities, err := converter.ToEntities(shared.FlipperABI, []types.Log{test_data.EthFlipKickLog}) Expect(err).NotTo(HaveOccurred()) Expect(len(entities)).To(Equal(1)) @@ -49,7 +49,7 @@ var _ = Describe("FlipKick Converter", func() { }) It("returns an error if converting log to entity fails", func() { - _, err := converter.ToEntities(shared.FlipperContractAddress, "error abi", []types.Log{test_data.EthFlipKickLog}) + _, err := converter.ToEntities("error abi", []types.Log{test_data.EthFlipKickLog}) Expect(err).To(HaveOccurred()) }) diff --git a/pkg/transformers/flip_kick/transformer.go b/pkg/transformers/flip_kick/transformer.go index 5d10fa3d..507b6497 100644 --- a/pkg/transformers/flip_kick/transformer.go +++ b/pkg/transformers/flip_kick/transformer.go @@ -91,10 +91,11 @@ func (fkt FlipKickTransformer) Execute() error { log.Printf("Fetching flip kick event logs for %d headers \n", len(headers)) var resultingErrors []error for _, header := range headers { - ethLogs, err := fkt.Fetcher.FetchLogs(config.ContractAddress, topics, header.BlockNumber) + ethLogs, err := fkt.Fetcher.FetchLogs(config.ContractAddresses, topics, header.BlockNumber) if err != nil { resultingErrors = append(resultingErrors, newTransformerError(err, header.BlockNumber, FetcherError)) } + if len(ethLogs) < 1 { err := fkt.Repository.MarkHeaderChecked(header.Id) if err != nil { @@ -102,7 +103,7 @@ func (fkt FlipKickTransformer) Execute() error { } } - entities, err := fkt.Converter.ToEntities(config.ContractAddress, config.ContractAbi, ethLogs) + entities, err := fkt.Converter.ToEntities(config.ContractAbi, ethLogs) if err != nil { resultingErrors = append(resultingErrors, newTransformerError(err, header.BlockNumber, LogToEntityError)) } diff --git a/pkg/transformers/flip_kick/transformer_test.go b/pkg/transformers/flip_kick/transformer_test.go index b9fbac90..e3ac8c22 100644 --- a/pkg/transformers/flip_kick/transformer_test.go +++ b/pkg/transformers/flip_kick/transformer_test.go @@ -36,7 +36,6 @@ var _ = Describe("FlipKick Transformer", func() { var fetcher mocks.MockLogFetcher var converter flip_kick_mocks.MockFlipKickConverter var repository flip_kick_mocks.MockFlipKickRepository - var testConfig shared.TransformerConfig var blockNumber int64 var headerId int64 var headers []core.Header @@ -51,16 +50,7 @@ var _ = Describe("FlipKick Transformer", func() { Converter: &converter, Repository: &repository, } - - startingBlockNumber := rand.Int63() - testConfig = shared.TransformerConfig{ - ContractAddress: "0x12345", - ContractAbi: "test abi", - Topics: []string{shared.FlipKickSignature}, - StartingBlockNumber: startingBlockNumber, - EndingBlockNumber: startingBlockNumber + 5, - } - transformer.SetConfig(testConfig) + transformer.SetConfig(flip_kick.FlipKickConfig) blockNumber = rand.Int63() headerId = rand.Int63() @@ -83,7 +73,7 @@ var _ = Describe("FlipKick Transformer", func() { err := transformer.Execute() Expect(err).NotTo(HaveOccurred()) - Expect(fetcher.FetchedContractAddress).To(Equal(testConfig.ContractAddress)) + Expect(fetcher.FetchedContractAddresses).To(Equal([][]string{flip_kick.FlipKickConfig.ContractAddresses})) Expect(fetcher.FetchedTopics).To(Equal(expectedTopics)) Expect(fetcher.FetchedBlocks).To(Equal([]int64{blockNumber})) }) @@ -136,8 +126,8 @@ var _ = Describe("FlipKick Transformer", func() { err := transformer.Execute() Expect(err).NotTo(HaveOccurred()) - Expect(converter.ConverterContract).To(Equal(testConfig.ContractAddress)) - Expect(converter.ConverterAbi).To(Equal(testConfig.ContractAbi)) + Expect(converter.ConverterContracts).To(Equal(flip_kick.FlipKickConfig.ContractAddresses)) + Expect(converter.ConverterAbi).To(Equal(flip_kick.FlipKickConfig.ContractAbi)) Expect(converter.LogsToConvert).To(Equal(logs)) Expect(converter.EntitiesToConvert).To(Equal([]flip_kick.FlipKickEntity{test_data.FlipKickEntity})) }) @@ -175,7 +165,7 @@ var _ = Describe("FlipKick Transformer", func() { err := transformer.Execute() Expect(err).NotTo(HaveOccurred()) - Expect(repository.StartingBlockNumber).To(Equal(testConfig.StartingBlockNumber)) - Expect(repository.EndingBlockNumber).To(Equal(testConfig.EndingBlockNumber)) + Expect(repository.StartingBlockNumber).To(Equal(flip_kick.FlipKickConfig.StartingBlockNumber)) + Expect(repository.EndingBlockNumber).To(Equal(flip_kick.FlipKickConfig.EndingBlockNumber)) }) }) diff --git a/pkg/transformers/flop_kick/config.go b/pkg/transformers/flop_kick/config.go index 10dd7930..59cec97f 100644 --- a/pkg/transformers/flop_kick/config.go +++ b/pkg/transformers/flop_kick/config.go @@ -17,7 +17,7 @@ package flop_kick import "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" var Config = shared.TransformerConfig{ - ContractAddress: shared.FlopperContractAddress, + ContractAddresses: []string{shared.FlopperContractAddress}, ContractAbi: shared.FlopperABI, Topics: []string{shared.FlopKickSignature}, StartingBlockNumber: 0, diff --git a/pkg/transformers/flop_kick/converter.go b/pkg/transformers/flop_kick/converter.go index ad75d96d..9478b681 100644 --- a/pkg/transformers/flop_kick/converter.go +++ b/pkg/transformers/flop_kick/converter.go @@ -19,7 +19,6 @@ import ( "time" "github.com/ethereum/go-ethereum/accounts/abi/bind" - "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/vulcanize/vulcanizedb/pkg/geth" @@ -27,17 +26,17 @@ import ( ) type Converter interface { - ToEntities(contractAddress, contractAbi string, ethLogs []types.Log) ([]Entity, error) + ToEntities(contractAbi string, ethLogs []types.Log) ([]Entity, error) ToModels(entities []Entity) ([]Model, error) } type FlopKickConverter struct{} -func (FlopKickConverter) ToEntities(contractAddress, contractAbi string, ethLogs []types.Log) ([]Entity, error) { +func (FlopKickConverter) ToEntities(contractAbi string, ethLogs []types.Log) ([]Entity, error) { var results []Entity for _, ethLog := range ethLogs { entity := Entity{} - address := common.HexToAddress(contractAddress) + address := ethLog.Address abi, err := geth.ParseAbi(contractAbi) if err != nil { return nil, err diff --git a/pkg/transformers/flop_kick/converter_test.go b/pkg/transformers/flop_kick/converter_test.go index 70bc1814..6575da73 100644 --- a/pkg/transformers/flop_kick/converter_test.go +++ b/pkg/transformers/flop_kick/converter_test.go @@ -30,7 +30,7 @@ var _ = Describe("FlopKick Converter", func() { Describe("ToEntities", func() { It("converts a log to a FlopKick entity", func() { converter := flop_kick.FlopKickConverter{} - entities, err := converter.ToEntities(shared.FlopperContractAddress, shared.FlopperABI, []types.Log{test_data.FlopKickLog}) + entities, err := converter.ToEntities(shared.FlopperABI, []types.Log{test_data.FlopKickLog}) Expect(err).NotTo(HaveOccurred()) entity := entities[0] @@ -45,7 +45,7 @@ var _ = Describe("FlopKick Converter", func() { It("returns an error if converting the log to an entity fails", func() { converter := flop_kick.FlopKickConverter{} - entities, err := converter.ToEntities(shared.FlopperContractAddress, "error abi", []types.Log{test_data.FlopKickLog}) + entities, err := converter.ToEntities("error abi", []types.Log{test_data.FlopKickLog}) Expect(err).To(HaveOccurred()) Expect(entities).To(BeNil()) diff --git a/pkg/transformers/flop_kick/transformer.go b/pkg/transformers/flop_kick/transformer.go index 67ff93be..1ea25dbb 100644 --- a/pkg/transformers/flop_kick/transformer.go +++ b/pkg/transformers/flop_kick/transformer.go @@ -51,7 +51,7 @@ func (t Transformer) Execute() error { for _, header := range headers { topics := [][]common.Hash{{common.HexToHash(shared.FlopKickSignature)}} - matchingLogs, err := t.Fetcher.FetchLogs(config.ContractAddress, topics, header.BlockNumber) + matchingLogs, err := t.Fetcher.FetchLogs(config.ContractAddresses, topics, header.BlockNumber) if err != nil { return err } @@ -62,7 +62,7 @@ func (t Transformer) Execute() error { } } - entities, err := t.Converter.ToEntities(config.ContractAddress, config.ContractAbi, matchingLogs) + entities, err := t.Converter.ToEntities(config.ContractAbi, matchingLogs) if err != nil { return err } diff --git a/pkg/transformers/flop_kick/transformer_test.go b/pkg/transformers/flop_kick/transformer_test.go index 304cba1a..d1ed392a 100644 --- a/pkg/transformers/flop_kick/transformer_test.go +++ b/pkg/transformers/flop_kick/transformer_test.go @@ -87,7 +87,7 @@ var _ = Describe("FlopKick Transformer", func() { Expect(err).NotTo(HaveOccurred()) Expect(fetcher.FetchedBlocks).To(Equal([]int64{headerOne.BlockNumber, headerTwo.BlockNumber})) - Expect(fetcher.FetchedContractAddress).To(Equal(flop_kick.Config.ContractAddress)) + Expect(fetcher.FetchedContractAddresses).To(Equal([][]string{flop_kick.Config.ContractAddresses, flop_kick.Config.ContractAddresses})) Expect(fetcher.FetchedTopics).To(Equal([][]common.Hash{{common.HexToHash(shared.FlopKickSignature)}})) }) @@ -154,7 +154,7 @@ var _ = Describe("FlopKick Transformer", func() { err := transformer.Execute() Expect(err).NotTo(HaveOccurred()) - Expect(converter.PassedContractAddress).To(Equal(flop_kick.Config.ContractAddress)) + Expect(converter.PassedContractAddresses).To(Equal(flop_kick.Config.ContractAddresses)) Expect(converter.PassedContractABI).To(Equal(flop_kick.Config.ContractAbi)) Expect(converter.PassedLogs).To(Equal([]types.Log{test_data.FlopKickLog})) }) diff --git a/pkg/transformers/frob/config.go b/pkg/transformers/frob/config.go index d658c643..70d139ff 100644 --- a/pkg/transformers/frob/config.go +++ b/pkg/transformers/frob/config.go @@ -17,7 +17,7 @@ package frob import "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" var FrobConfig = shared.TransformerConfig{ - ContractAddress: shared.PitContractAddress, + ContractAddresses: []string{shared.PitContractAddress}, ContractAbi: shared.PitABI, Topics: []string{shared.FrobSignature}, StartingBlockNumber: 0, diff --git a/pkg/transformers/frob/integration_test.go b/pkg/transformers/frob/integration_test.go index ff87a1dc..0e847fed 100644 --- a/pkg/transformers/frob/integration_test.go +++ b/pkg/transformers/frob/integration_test.go @@ -49,7 +49,7 @@ var _ = Describe("Integration tests", func() { topic0 := common.HexToHash(shared.FrobSignature) topics := [][]common.Hash{{topic0}} - result, err := realFetcher.FetchLogs(shared.PitContractAddress, topics, int64(12)) + result, err := realFetcher.FetchLogs(frob.FrobConfig.ContractAddresses, topics, int64(12)) Expect(err).NotTo(HaveOccurred()) Expect(len(result) > 0).To(BeTrue()) diff --git a/pkg/transformers/frob/transformer.go b/pkg/transformers/frob/transformer.go index da076e1f..01073526 100644 --- a/pkg/transformers/frob/transformer.go +++ b/pkg/transformers/frob/transformer.go @@ -55,12 +55,12 @@ func (transformer FrobTransformer) Execute() error { log.Printf("Fetching frob event logs for %d headers \n", len(missingHeaders)) for _, header := range missingHeaders { topics := [][]common.Hash{{common.HexToHash(shared.FrobSignature)}} - matchingLogs, err := transformer.Fetcher.FetchLogs(FrobConfig.ContractAddress, topics, header.BlockNumber) + matchingLogs, err := transformer.Fetcher.FetchLogs(FrobConfig.ContractAddresses, topics, header.BlockNumber) if err != nil { return err } for _, log := range matchingLogs { - entity, err := transformer.Converter.ToEntity(FrobConfig.ContractAddress, FrobConfig.ContractAbi, log) + entity, err := transformer.Converter.ToEntity(log.Address.Hex(), FrobConfig.ContractAbi, log) if err != nil { return err } diff --git a/pkg/transformers/frob/transformer_test.go b/pkg/transformers/frob/transformer_test.go index 58d4348c..a5579cb2 100644 --- a/pkg/transformers/frob/transformer_test.go +++ b/pkg/transformers/frob/transformer_test.go @@ -75,7 +75,7 @@ var _ = Describe("Frob transformer", func() { Expect(err).NotTo(HaveOccurred()) Expect(fetcher.FetchedBlocks).To(Equal([]int64{1, 2})) - Expect(fetcher.FetchedContractAddress).To(Equal(frob.FrobConfig.ContractAddress)) + Expect(fetcher.FetchedContractAddresses).To(Equal([][]string{frob.FrobConfig.ContractAddresses, frob.FrobConfig.ContractAddresses})) Expect(fetcher.FetchedTopics).To(Equal([][]common.Hash{{common.HexToHash(shared.FrobSignature)}})) }) @@ -111,7 +111,7 @@ var _ = Describe("Frob transformer", func() { err := transformer.Execute() Expect(err).NotTo(HaveOccurred()) - Expect(converter.PassedContractAddress).To(Equal(frob.FrobConfig.ContractAddress)) + Expect(converter.PassedContractAddress).To(Equal(test_data.EthFrobLog.Address.Hex())) Expect(converter.PassedContractABI).To(Equal(frob.FrobConfig.ContractAbi)) Expect(converter.PassedLog).To(Equal(test_data.EthFrobLog)) }) diff --git a/pkg/transformers/pit_file/config.go b/pkg/transformers/pit_file/config.go index b0509a2c..73656bd4 100644 --- a/pkg/transformers/pit_file/config.go +++ b/pkg/transformers/pit_file/config.go @@ -19,7 +19,7 @@ import ( ) var PitFileConfig = shared.TransformerConfig{ - ContractAddress: shared.PitContractAddress, + ContractAddresses: []string{shared.PitContractAddress}, ContractAbi: shared.PitABI, Topics: []string{shared.PitFileIlkSignature, shared.PitFileDebtCeilingSignature, shared.PitFileStabilityFeeSignature}, StartingBlockNumber: 0, diff --git a/pkg/transformers/pit_file/debt_ceiling/transformer.go b/pkg/transformers/pit_file/debt_ceiling/transformer.go index 7aef0bab..cdbf5256 100644 --- a/pkg/transformers/pit_file/debt_ceiling/transformer.go +++ b/pkg/transformers/pit_file/debt_ceiling/transformer.go @@ -56,7 +56,7 @@ func (transformer PitFileDebtCeilingTransformer) Execute() error { log.Printf("Fetching pit file debt ceiling event logs for %d headers \n", len(missingHeaders)) for _, header := range missingHeaders { topics := [][]common.Hash{{common.HexToHash(shared.PitFileDebtCeilingSignature)}} - matchingLogs, err := transformer.Fetcher.FetchLogs(pit_file.PitFileConfig.ContractAddress, topics, header.BlockNumber) + matchingLogs, err := transformer.Fetcher.FetchLogs(pit_file.PitFileConfig.ContractAddresses, topics, header.BlockNumber) if err != nil { return err } diff --git a/pkg/transformers/pit_file/debt_ceiling/transformer_test.go b/pkg/transformers/pit_file/debt_ceiling/transformer_test.go index 9b441fd8..b24ca72f 100644 --- a/pkg/transformers/pit_file/debt_ceiling/transformer_test.go +++ b/pkg/transformers/pit_file/debt_ceiling/transformer_test.go @@ -76,7 +76,7 @@ var _ = Describe("", func() { Expect(err).NotTo(HaveOccurred()) Expect(fetcher.FetchedBlocks).To(Equal([]int64{1, 2})) - Expect(fetcher.FetchedContractAddress).To(Equal(pit_file.PitFileConfig.ContractAddress)) + Expect(fetcher.FetchedContractAddresses).To(Equal([][]string{pit_file.PitFileConfig.ContractAddresses, pit_file.PitFileConfig.ContractAddresses})) Expect(fetcher.FetchedTopics).To(Equal([][]common.Hash{{common.HexToHash(shared.PitFileDebtCeilingSignature)}})) }) diff --git a/pkg/transformers/pit_file/ilk/transformer.go b/pkg/transformers/pit_file/ilk/transformer.go index c69a23ee..80e9ecd7 100644 --- a/pkg/transformers/pit_file/ilk/transformer.go +++ b/pkg/transformers/pit_file/ilk/transformer.go @@ -56,7 +56,7 @@ func (transformer PitFileIlkTransformer) Execute() error { log.Printf("Fetching pit file ilk event logs for %d headers \n", len(missingHeaders)) for _, header := range missingHeaders { topics := [][]common.Hash{{common.HexToHash(shared.PitFileIlkSignature)}} - matchingLogs, err := transformer.Fetcher.FetchLogs(pit_file.PitFileConfig.ContractAddress, topics, header.BlockNumber) + matchingLogs, err := transformer.Fetcher.FetchLogs(pit_file.PitFileConfig.ContractAddresses, topics, header.BlockNumber) if err != nil { return err } diff --git a/pkg/transformers/pit_file/ilk/transformer_test.go b/pkg/transformers/pit_file/ilk/transformer_test.go index 5d5769c2..82955149 100644 --- a/pkg/transformers/pit_file/ilk/transformer_test.go +++ b/pkg/transformers/pit_file/ilk/transformer_test.go @@ -76,7 +76,7 @@ var _ = Describe("Pit file ilk transformer", func() { Expect(err).NotTo(HaveOccurred()) Expect(fetcher.FetchedBlocks).To(Equal([]int64{1, 2})) - Expect(fetcher.FetchedContractAddress).To(Equal(pit_file.PitFileConfig.ContractAddress)) + Expect(fetcher.FetchedContractAddresses).To(Equal([][]string{pit_file.PitFileConfig.ContractAddresses, pit_file.PitFileConfig.ContractAddresses})) Expect(fetcher.FetchedTopics).To(Equal([][]common.Hash{{common.HexToHash(shared.PitFileIlkSignature)}})) }) diff --git a/pkg/transformers/pit_file/stability_fee/transformer.go b/pkg/transformers/pit_file/stability_fee/transformer.go index 64d3897d..7e424a4f 100644 --- a/pkg/transformers/pit_file/stability_fee/transformer.go +++ b/pkg/transformers/pit_file/stability_fee/transformer.go @@ -56,7 +56,7 @@ func (transformer PitFileStabilityFeeTransformer) Execute() error { log.Printf("Fetching pit file stability fee event logs for %d headers \n", len(missingHeaders)) for _, header := range missingHeaders { topics := [][]common.Hash{{common.HexToHash(shared.PitFileStabilityFeeSignature)}} - matchingLogs, err := transformer.Fetcher.FetchLogs(pit_file.PitFileConfig.ContractAddress, topics, header.BlockNumber) + matchingLogs, err := transformer.Fetcher.FetchLogs(pit_file.PitFileConfig.ContractAddresses, topics, header.BlockNumber) if err != nil { return err } diff --git a/pkg/transformers/pit_file/stability_fee/transformer_test.go b/pkg/transformers/pit_file/stability_fee/transformer_test.go index 7106c3dd..050732b7 100644 --- a/pkg/transformers/pit_file/stability_fee/transformer_test.go +++ b/pkg/transformers/pit_file/stability_fee/transformer_test.go @@ -76,7 +76,7 @@ var _ = Describe("", func() { Expect(err).NotTo(HaveOccurred()) Expect(fetcher.FetchedBlocks).To(Equal([]int64{1, 2})) - Expect(fetcher.FetchedContractAddress).To(Equal(pit_file.PitFileConfig.ContractAddress)) + Expect(fetcher.FetchedContractAddresses).To(Equal([][]string{pit_file.PitFileConfig.ContractAddresses, pit_file.PitFileConfig.ContractAddresses})) Expect(fetcher.FetchedTopics).To(Equal([][]common.Hash{{common.HexToHash(shared.PitFileStabilityFeeSignature)}})) }) diff --git a/pkg/transformers/shared/constants.go b/pkg/transformers/shared/constants.go index f8bedd72..1b7a329d 100644 --- a/pkg/transformers/shared/constants.go +++ b/pkg/transformers/shared/constants.go @@ -28,8 +28,8 @@ var ( // temporary addresses from Kovan deployment CatContractAddress = "0x2f34f22a00ee4b7a8f8bbc4eaee1658774c624e0" DripContractAddress = "0x891c04639a5edcae088e546fa125b5d7fb6a2b9d" - FlipperContractAddress = "0x32d496ad866d110060866b7125981c73642cc509" // ETH FLIP Contract - FlopperContractAddress = "0x6191c9b0086c2ebf92300cc507009b53996fbffa" // MCD FLOP Contract + FlipperContractAddress = "0x32D496Ad866D110060866B7125981C73642cc509" // ETH FLIP Contract + FlopperContractAddress = "0x6191C9b0086c2eBF92300cC507009b53996FbFFa" // MCD FLOP Contract PepContractAddress = "0xB1997239Cfc3d15578A3a09730f7f84A90BB4975" PipContractAddress = "0x9FfFE440258B79c5d6604001674A4722FfC0f7Bc" PitContractAddress = "0xe7cf3198787c9a4daac73371a38f29aaeeced87e" diff --git a/pkg/transformers/shared/log_fetcher.go b/pkg/transformers/shared/log_fetcher.go index 9d8e1148..a42a18ff 100644 --- a/pkg/transformers/shared/log_fetcher.go +++ b/pkg/transformers/shared/log_fetcher.go @@ -25,7 +25,7 @@ import ( ) type LogFetcher interface { - FetchLogs(contractAddress string, topics [][]common.Hash, blockNumber int64) ([]types.Log, error) + FetchLogs(contractAddresses []string, topics [][]common.Hash, blockNumber int64) ([]types.Log, error) } type Fetcher struct { @@ -38,14 +38,24 @@ func NewFetcher(blockchain core.BlockChain) Fetcher { } } -func (fetcher Fetcher) FetchLogs(contractAddress string, topics [][]common.Hash, blockNumber int64) ([]types.Log, error) { +func (fetcher Fetcher) FetchLogs(contractAddresses []string, topics [][]common.Hash, blockNumber int64) ([]types.Log, error) { block := big.NewInt(blockNumber) - address := common.HexToAddress(contractAddress) + addresses := hexStringsToAddresses(contractAddresses) query := ethereum.FilterQuery{ FromBlock: block, ToBlock: block, - Addresses: []common.Address{address}, + Addresses: addresses, Topics: topics, } return fetcher.blockChain.GetEthLogsWithCustomQuery(query) } + +func hexStringsToAddresses(hexStrings []string) []common.Address { + var addresses []common.Address + for _, hexString := range hexStrings { + address := common.HexToAddress(hexString) + addresses = append(addresses, address) + } + + return addresses +} diff --git a/pkg/transformers/shared/log_fetcher_test.go b/pkg/transformers/shared/log_fetcher_test.go index 93b4ad5a..97f47535 100644 --- a/pkg/transformers/shared/log_fetcher_test.go +++ b/pkg/transformers/shared/log_fetcher_test.go @@ -28,25 +28,25 @@ import ( var _ = Describe("Fetcher", func() { Describe("FetchLogs", func() { - It("fetches logs based on the given query", func() { blockChain := fakes.NewMockBlockChain() fetcher := shared.NewFetcher(blockChain) blockNumber := int64(123) - address := "0xfakeAddress" + addresses := []string{"0xfakeAddress", "0xanotherFakeAddress"} topicZeros := [][]common.Hash{{common.BytesToHash([]byte{1, 2, 3, 4, 5})}} - _, err := fetcher.FetchLogs(address, topicZeros, blockNumber) + _, err := fetcher.FetchLogs(addresses, topicZeros, blockNumber) + address1 := common.HexToAddress("0xfakeAddress") + address2 := common.HexToAddress("0xanotherFakeAddress") Expect(err).NotTo(HaveOccurred()) expectedQuery := ethereum.FilterQuery{ FromBlock: big.NewInt(blockNumber), ToBlock: big.NewInt(blockNumber), - Addresses: []common.Address{common.HexToAddress(address)}, + Addresses: []common.Address{address1, address2}, Topics: topicZeros, } blockChain.AssertGetEthLogsWithCustomQueryCalledWith(expectedQuery) - }) It("returns an error if fetching the logs fails", func() { @@ -54,7 +54,7 @@ var _ = Describe("Fetcher", func() { blockChain.SetGetEthLogsWithCustomQueryErr(fakes.FakeError) fetcher := shared.NewFetcher(blockChain) - _, err := fetcher.FetchLogs("", [][]common.Hash{}, int64(1)) + _, err := fetcher.FetchLogs([]string{}, [][]common.Hash{}, int64(1)) Expect(err).To(HaveOccurred()) Expect(err).To(MatchError(fakes.FakeError)) diff --git a/pkg/transformers/shared/transformer.go b/pkg/transformers/shared/transformer.go index 9632e6cd..1b07026e 100644 --- a/pkg/transformers/shared/transformer.go +++ b/pkg/transformers/shared/transformer.go @@ -28,7 +28,7 @@ type Transformer interface { type TransformerInitializer func(db *postgres.DB, blockChain core.BlockChain) Transformer type TransformerConfig struct { - ContractAddress string + ContractAddresses []string ContractAbi string Topics []string StartingBlockNumber int64 diff --git a/pkg/transformers/tend/config.go b/pkg/transformers/tend/config.go index 1e8b8fa3..7ec52f9b 100644 --- a/pkg/transformers/tend/config.go +++ b/pkg/transformers/tend/config.go @@ -17,7 +17,7 @@ package tend import "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" var TendConfig = shared.TransformerConfig{ - ContractAddress: shared.FlipperContractAddress, + ContractAddresses: []string{shared.FlipperContractAddress}, ContractAbi: shared.FlipperABI, Topics: []string{shared.TendFunctionSignature}, StartingBlockNumber: 0, diff --git a/pkg/transformers/tend/converter.go b/pkg/transformers/tend/converter.go index 827a500d..dd989d08 100644 --- a/pkg/transformers/tend/converter.go +++ b/pkg/transformers/tend/converter.go @@ -24,7 +24,7 @@ import ( ) type Converter interface { - Convert(ethLogs []types.Log) ([]TendModel, error) + ToModels(ethLogs []types.Log) ([]TendModel, error) } type TendConverter struct{} @@ -33,7 +33,7 @@ func NewTendConverter() TendConverter { return TendConverter{} } -func (c TendConverter) Convert(ethLogs []types.Log) (results []TendModel, err error) { +func (c TendConverter) ToModels(ethLogs []types.Log) (results []TendModel, err error) { for _, ethLog := range ethLogs { err := validateLog(ethLog) if err != nil { diff --git a/pkg/transformers/tend/converter_test.go b/pkg/transformers/tend/converter_test.go index d090f9cd..db53220d 100644 --- a/pkg/transformers/tend/converter_test.go +++ b/pkg/transformers/tend/converter_test.go @@ -31,9 +31,9 @@ var _ = Describe("Tend TendConverter", func() { converter = tend.NewTendConverter() }) - Describe("Convert", func() { + Describe("ToModels", func() { It("converts an eth log to a db model", func() { - models, err := converter.Convert([]types.Log{test_data.TendLogNote}) + models, err := converter.ToModels([]types.Log{test_data.TendLogNote}) Expect(err).NotTo(HaveOccurred()) Expect(len(models)).To(Equal(1)) @@ -43,7 +43,7 @@ var _ = Describe("Tend TendConverter", func() { It("returns an error if the log data is empty", func() { emptyDataLog := test_data.TendLogNote emptyDataLog.Data = []byte{} - _, err := converter.Convert([]types.Log{emptyDataLog}) + _, err := converter.ToModels([]types.Log{emptyDataLog}) Expect(err).To(HaveOccurred()) Expect(err).To(MatchError("tend log note data is empty")) @@ -52,7 +52,7 @@ var _ = Describe("Tend TendConverter", func() { It("returns an error if the expected amount of topics aren't in the log", func() { invalidLog := test_data.TendLogNote invalidLog.Topics = []common.Hash{} - _, err := converter.Convert([]types.Log{invalidLog}) + _, err := converter.ToModels([]types.Log{invalidLog}) Expect(err).To(MatchError("tend log does not contain expected topics")) }) diff --git a/pkg/transformers/tend/integration_test.go b/pkg/transformers/tend/integration_test.go index f1cea8d7..33904c34 100644 --- a/pkg/transformers/tend/integration_test.go +++ b/pkg/transformers/tend/integration_test.go @@ -28,6 +28,7 @@ import ( "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" "github.com/vulcanize/vulcanizedb/test_config" + "github.com/vulcanize/vulcanizedb/pkg/transformers/tend" ) // These test are marked as pending until the Flip contract is deployed to Kovan. @@ -48,7 +49,7 @@ var _ = Describe("Integration tests", func() { topic0 := common.HexToHash(shared.TendFunctionSignature) topics := [][]common.Hash{{topic0}} - result, err := realFetcher.FetchLogs(shared.FlipperContractAddress, topics, test_data.FlipKickBlockNumber) + result, err := realFetcher.FetchLogs(tend.TendConfig.ContractAddresses, topics, test_data.FlipKickBlockNumber) Expect(err).NotTo(HaveOccurred()) Expect(len(result) > 0).To(BeTrue()) diff --git a/pkg/transformers/tend/transformer.go b/pkg/transformers/tend/transformer.go index 67c0c648..ea8ce4b8 100644 --- a/pkg/transformers/tend/transformer.go +++ b/pkg/transformers/tend/transformer.go @@ -59,7 +59,7 @@ func (t TendTransformer) Execute() error { log.Printf("Fetching tend event logs for %d headers \n", len(missingHeaders)) for _, header := range missingHeaders { - ethLogs, err := t.Fetcher.FetchLogs(config.ContractAddress, topics, header.BlockNumber) + ethLogs, err := t.Fetcher.FetchLogs(config.ContractAddresses, topics, header.BlockNumber) if err != nil { log.Println("Error fetching matching logs:", err) return err @@ -71,7 +71,7 @@ func (t TendTransformer) Execute() error { } } - models, err := t.Converter.Convert(ethLogs) + models, err := t.Converter.ToModels(ethLogs) if err != nil { log.Println("Error converting logs:", err) return err diff --git a/pkg/transformers/tend/transformer_test.go b/pkg/transformers/tend/transformer_test.go index bd8ca4a9..57181cb3 100644 --- a/pkg/transformers/tend/transformer_test.go +++ b/pkg/transformers/tend/transformer_test.go @@ -75,7 +75,7 @@ var _ = Describe("Tend Transformer", func() { Expect(err).NotTo(HaveOccurred()) Expect(fetcher.FetchedBlocks).To(Equal([]int64{blockNumber1, blockNumber2})) Expect(fetcher.FetchedTopics).To(Equal(expectedTopics)) - Expect(fetcher.FetchedContractAddress).To(Equal(shared.FlipperContractAddress)) + Expect(fetcher.FetchedContractAddresses).To(Equal([][]string{tend.TendConfig.ContractAddresses, tend.TendConfig.ContractAddresses})) }) It("returns an error if fetching logs fails", func() { diff --git a/pkg/transformers/test_data/deal.go b/pkg/transformers/test_data/deal.go index 2e746939..af70ef76 100644 --- a/pkg/transformers/test_data/deal.go +++ b/pkg/transformers/test_data/deal.go @@ -43,6 +43,7 @@ var dealRawJson, _ = json.Marshal(DealLogNote) var DealModel = deal.DealModel{ BidId: "123", + ContractAddress: shared.FlipperContractAddress, TransactionIndex: 74, Raw: dealRawJson, -} +} \ No newline at end of file diff --git a/pkg/transformers/test_data/mocks/flip_kick/converter.go b/pkg/transformers/test_data/mocks/flip_kick/converter.go index 0f0c2225..f214b54b 100644 --- a/pkg/transformers/test_data/mocks/flip_kick/converter.go +++ b/pkg/transformers/test_data/mocks/flip_kick/converter.go @@ -22,15 +22,17 @@ import ( ) type MockFlipKickConverter struct { - ConverterContract string - ConverterAbi string - LogsToConvert []types.Log - EntitiesToConvert []flip_kick.FlipKickEntity - ConverterError error + ConverterContracts []string + ConverterAbi string + LogsToConvert []types.Log + EntitiesToConvert []flip_kick.FlipKickEntity + ConverterError error } -func (mfkc *MockFlipKickConverter) ToEntities(contractAddress string, contractAbi string, ethLogs []types.Log) ([]flip_kick.FlipKickEntity, error) { - mfkc.ConverterContract = contractAddress +func (mfkc *MockFlipKickConverter) ToEntities(contractAbi string, ethLogs []types.Log) ([]flip_kick.FlipKickEntity, error) { + for _, log := range ethLogs { + mfkc.ConverterContracts = append(mfkc.ConverterContracts, log.Address.Hex()) + } mfkc.ConverterAbi = contractAbi mfkc.LogsToConvert = append(mfkc.LogsToConvert, ethLogs...) return []flip_kick.FlipKickEntity{test_data.FlipKickEntity}, mfkc.ConverterError diff --git a/pkg/transformers/test_data/mocks/flop_kick/converter.go b/pkg/transformers/test_data/mocks/flop_kick/converter.go index 2abfaf5e..2d3f9849 100644 --- a/pkg/transformers/test_data/mocks/flop_kick/converter.go +++ b/pkg/transformers/test_data/mocks/flop_kick/converter.go @@ -21,16 +21,18 @@ import ( ) type MockConverter struct { - PassedContractAddress string - PassedContractABI string - PassedLogs []types.Log - PassedEntities []flop_kick.Entity - entityConverterError error - modelConverterError error + PassedContractAddresses []string + PassedContractABI string + PassedLogs []types.Log + PassedEntities []flop_kick.Entity + entityConverterError error + modelConverterError error } -func (c *MockConverter) ToEntities(contractAddress, contractAbi string, ethLogs []types.Log) ([]flop_kick.Entity, error) { - c.PassedContractAddress = contractAddress +func (c *MockConverter) ToEntities(contractAbi string, ethLogs []types.Log) ([]flop_kick.Entity, error) { + for _, log := range ethLogs { + c.PassedContractAddresses = append(c.PassedContractAddresses, log.Address.Hex()) + } c.PassedContractABI = contractAbi c.PassedLogs = ethLogs diff --git a/pkg/transformers/test_data/mocks/log_fetcher.go b/pkg/transformers/test_data/mocks/log_fetcher.go index 3dd75872..463bf878 100644 --- a/pkg/transformers/test_data/mocks/log_fetcher.go +++ b/pkg/transformers/test_data/mocks/log_fetcher.go @@ -20,15 +20,15 @@ import ( ) type MockLogFetcher struct { - FetchedContractAddress string - FetchedTopics [][]common.Hash - FetchedBlocks []int64 - fetcherError error - FetchedLogs []types.Log + FetchedContractAddresses [][]string + FetchedTopics [][]common.Hash + FetchedBlocks []int64 + fetcherError error + FetchedLogs []types.Log } -func (mlf *MockLogFetcher) FetchLogs(contractAddress string, topics [][]common.Hash, blockNumber int64) ([]types.Log, error) { - mlf.FetchedContractAddress = contractAddress +func (mlf *MockLogFetcher) FetchLogs(contractAddresses []string, topics [][]common.Hash, blockNumber int64) ([]types.Log, error) { + mlf.FetchedContractAddresses = append(mlf.FetchedContractAddresses, contractAddresses) mlf.FetchedTopics = topics mlf.FetchedBlocks = append(mlf.FetchedBlocks, blockNumber) diff --git a/pkg/transformers/test_data/mocks/tend/converter.go b/pkg/transformers/test_data/mocks/tend/converter.go index cb36532c..77ec60c9 100644 --- a/pkg/transformers/test_data/mocks/tend/converter.go +++ b/pkg/transformers/test_data/mocks/tend/converter.go @@ -26,7 +26,7 @@ type MockTendConverter struct { ConverterError error } -func (c *MockTendConverter) Convert(ethLogs []types.Log) ([]tend.TendModel, error) { +func (c *MockTendConverter) ToModels(ethLogs []types.Log) ([]tend.TendModel, error) { c.LogsToConvert = append(c.LogsToConvert, ethLogs...) return []tend.TendModel{test_data.TendModel}, c.ConverterError } diff --git a/pkg/transformers/vat_init/config.go b/pkg/transformers/vat_init/config.go index 11c2db4d..dcc9a03e 100644 --- a/pkg/transformers/vat_init/config.go +++ b/pkg/transformers/vat_init/config.go @@ -19,7 +19,7 @@ import ( ) var VatInitConfig = shared.TransformerConfig{ - ContractAddress: shared.VatContractAddress, + ContractAddresses: []string{shared.VatContractAddress}, ContractAbi: shared.VatABI, Topics: []string{shared.VatInitSignature}, StartingBlockNumber: 0, diff --git a/pkg/transformers/vat_init/transformer.go b/pkg/transformers/vat_init/transformer.go index 7209a78f..74783f41 100644 --- a/pkg/transformers/vat_init/transformer.go +++ b/pkg/transformers/vat_init/transformer.go @@ -55,7 +55,7 @@ func (transformer VatInitTransformer) Execute() error { log.Printf("Fetching vat init event logs for %d headers \n", len(missingHeaders)) for _, header := range missingHeaders { topics := [][]common.Hash{{common.HexToHash(shared.VatInitSignature)}} - matchingLogs, err := transformer.Fetcher.FetchLogs(VatInitConfig.ContractAddress, topics, header.BlockNumber) + matchingLogs, err := transformer.Fetcher.FetchLogs(VatInitConfig.ContractAddresses, topics, header.BlockNumber) if err != nil { return err } diff --git a/pkg/transformers/vat_init/transformer_test.go b/pkg/transformers/vat_init/transformer_test.go index 081a42ff..c72e5547 100644 --- a/pkg/transformers/vat_init/transformer_test.go +++ b/pkg/transformers/vat_init/transformer_test.go @@ -75,7 +75,7 @@ var _ = Describe("Vat init transformer", func() { Expect(err).NotTo(HaveOccurred()) Expect(fetcher.FetchedBlocks).To(Equal([]int64{1, 2})) - Expect(fetcher.FetchedContractAddress).To(Equal(vat_init.VatInitConfig.ContractAddress)) + Expect(fetcher.FetchedContractAddresses).To(Equal([][]string{vat_init.VatInitConfig.ContractAddresses, vat_init.VatInitConfig.ContractAddresses})) Expect(fetcher.FetchedTopics).To(Equal([][]common.Hash{{common.HexToHash(shared.VatInitSignature)}})) })