forked from cerc-io/ipld-eth-server
Flop deal (#39)
*Refactor deal transformer to take in several contract addresses * Add flop address to deal transformer
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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"`
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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))
|
||||
})
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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}))
|
||||
|
||||
Reference in New Issue
Block a user