Flop deal (#39)

*Refactor deal transformer to take in several contract addresses
* Add flop address to deal transformer
This commit is contained in:
Elizabeth 2018-09-27 10:12:29 -05:00 committed by GitHub
parent 369939ad84
commit b0cd852aa3
66 changed files with 145 additions and 137 deletions

View File

@ -0,0 +1,2 @@
ALTER TABLE maker.deal
DROP COLUMN contract_address;

View File

@ -0,0 +1,2 @@
ALTER TABLE maker.deal
ADD COLUMN contract_address VARCHAR;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -43,6 +43,7 @@ var dealRawJson, _ = json.Marshal(DealLogNote)
var DealModel = deal.DealModel{
BidId: "123",
ContractAddress: shared.FlipperContractAddress,
TransactionIndex: 74,
Raw: dealRawJson,
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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