Implement SingleTransformerConfig

This commit is contained in:
Edvard 2018-10-19 14:53:02 +02:00
parent 7d3bf1f0f6
commit 33f1f62c11
11 changed files with 33 additions and 26 deletions

View File

@ -16,11 +16,11 @@ package ilk
import "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" import "github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
var DripFileIlkConfig = shared.TransformerConfig{ var DripFileIlkConfig = shared.SingleTransformerConfig{
TransformerName: "drip file ilk", TransformerName: "drip file ilk",
ContractAddresses: []string{shared.DripContractAddress}, ContractAddresses: []string{shared.DripContractAddress},
ContractAbi: shared.DripABI, ContractAbi: shared.DripABI,
Topics: []string{shared.DripFileIlkSignature}, Topic: shared.DripFileIlkSignature,
StartingBlockNumber: 0, StartingBlockNumber: 0,
EndingBlockNumber: 10000000, EndingBlockNumber: 10000000,
} }

View File

@ -16,11 +16,11 @@ package repo
import "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" import "github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
var DripFileRepoConfig = shared.TransformerConfig{ var DripFileRepoConfig = shared.SingleTransformerConfig{
TransformerName: "drip file repo", TransformerName: "drip file repo",
ContractAddresses: []string{shared.DripContractAddress}, ContractAddresses: []string{shared.DripContractAddress},
ContractAbi: shared.DripABI, ContractAbi: shared.DripABI,
Topics: []string{shared.DripFileRepoSignature}, Topic: shared.DripFileRepoSignature,
StartingBlockNumber: 0, StartingBlockNumber: 0,
EndingBlockNumber: 10000000, EndingBlockNumber: 10000000,
} }

View File

@ -16,11 +16,11 @@ package vow
import "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" import "github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
var DripFileVowConfig = shared.TransformerConfig{ var DripFileVowConfig = shared.SingleTransformerConfig{
TransformerName: "drip file vow", TransformerName: "drip file vow",
ContractAddresses: []string{shared.DripContractAddress}, ContractAddresses: []string{shared.DripContractAddress},
ContractAbi: shared.DripABI, ContractAbi: shared.DripABI,
Topics: []string{shared.DripFileVowSignature}, Topic: shared.DripFileVowSignature,
StartingBlockNumber: 0, StartingBlockNumber: 0,
EndingBlockNumber: 10000000, EndingBlockNumber: 10000000,
} }

View File

@ -26,7 +26,7 @@ import (
) )
type Transformer struct { type Transformer struct {
Config shared.TransformerConfig Config shared.SingleTransformerConfig
Converter Converter Converter Converter
Repository Repository Repository Repository
Fetcher shared.SettableLogFetcher Fetcher shared.SettableLogFetcher
@ -57,16 +57,14 @@ func (transformer Transformer) Execute() error {
return err return err
} }
// Grab event signature from transformer config
// (Double-array structure required for go-ethereum FilterQuery)
var topic = [][]common.Hash{{common.HexToHash(transformer.Config.Topic)}}
log.Printf("Fetching %v event logs for %d headers \n", transformerName, len(missingHeaders)) log.Printf("Fetching %v event logs for %d headers \n", transformerName, len(missingHeaders))
for _, header := range missingHeaders { for _, header := range missingHeaders {
// Grab topics from config
var topics [][]common.Hash
for _, topic := range transformer.Config.Topics {
topics = append(topics, []common.Hash{common.HexToHash(topic)})
}
// Fetch the missing logs for a given header // Fetch the missing logs for a given header
matchingLogs, err := transformer.Fetcher.FetchLogs(transformer.Config.ContractAddresses, topics, header.BlockNumber) matchingLogs, err := transformer.Fetcher.FetchLogs(transformer.Config.ContractAddresses, topic, header.BlockNumber)
if err != nil { if err != nil {
log.Printf("Error fetching matching logs in %v transformer: %v", transformerName, err) log.Printf("Error fetching matching logs in %v transformer: %v", transformerName, err)
return err return err

View File

@ -18,11 +18,11 @@ import (
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
) )
var DebtCeilingFileConfig = shared.TransformerConfig{ var DebtCeilingFileConfig = shared.SingleTransformerConfig{
TransformerName: "pit file debt ceiling", TransformerName: "pit file debt ceiling",
ContractAddresses: []string{shared.PitContractAddress}, ContractAddresses: []string{shared.PitContractAddress},
ContractAbi: shared.PitABI, ContractAbi: shared.PitABI,
Topics: []string{shared.PitFileDebtCeilingSignature}, Topic: shared.PitFileDebtCeilingSignature,
StartingBlockNumber: 0, StartingBlockNumber: 0,
EndingBlockNumber: 10000000, EndingBlockNumber: 10000000,
} }

View File

@ -18,11 +18,11 @@ import (
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
) )
var IlkFileConfig = shared.TransformerConfig{ var IlkFileConfig = shared.SingleTransformerConfig{
TransformerName: "pit file ilk", TransformerName: "pit file ilk",
ContractAddresses: []string{shared.PitContractAddress}, ContractAddresses: []string{shared.PitContractAddress},
ContractAbi: shared.PitABI, ContractAbi: shared.PitABI,
Topics: []string{shared.PitFileIlkSignature}, Topic: shared.PitFileIlkSignature,
StartingBlockNumber: 0, StartingBlockNumber: 0,
EndingBlockNumber: 10000000, EndingBlockNumber: 10000000,
} }

View File

@ -18,11 +18,11 @@ import (
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
) )
var StabilityFeeFileConfig = shared.TransformerConfig{ var StabilityFeeFileConfig = shared.SingleTransformerConfig{
TransformerName: "pit file stability fee", TransformerName: "pit file stability fee",
ContractAddresses: []string{shared.PitContractAddress}, ContractAddresses: []string{shared.PitContractAddress},
ContractAbi: shared.PitABI, ContractAbi: shared.PitABI,
Topics: []string{shared.PitFileStabilityFeeSignature}, Topic: shared.PitFileStabilityFeeSignature,
StartingBlockNumber: 0, StartingBlockNumber: 0,
EndingBlockNumber: 10000000, EndingBlockNumber: 10000000,
} }

View File

@ -36,6 +36,15 @@ type TransformerConfig struct {
EndingBlockNumber int64 EndingBlockNumber int64
} }
type SingleTransformerConfig struct {
TransformerName string
ContractAddresses []string
ContractAbi string
Topic string
StartingBlockNumber int64
EndingBlockNumber int64
}
func HexToInt64(byteString string) int64 { func HexToInt64(byteString string) int64 {
value := common.HexToHash(byteString) value := common.HexToHash(byteString)
return value.Big().Int64() return value.Big().Int64()

View File

@ -16,11 +16,11 @@ package tend
import "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" import "github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
var TendConfig = shared.TransformerConfig{ var TendConfig = shared.SingleTransformerConfig{
TransformerName: "tend", TransformerName: "tend",
ContractAddresses: []string{shared.FlipperContractAddress}, ContractAddresses: []string{shared.FlipperContractAddress},
ContractAbi: shared.FlipperABI, ContractAbi: shared.FlipperABI,
Topics: []string{shared.TendFunctionSignature}, Topic: shared.TendFunctionSignature,
StartingBlockNumber: 0, StartingBlockNumber: 0,
EndingBlockNumber: 10000000, EndingBlockNumber: 10000000,
} }

View File

@ -18,11 +18,11 @@ import (
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
) )
var VatInitConfig = shared.TransformerConfig{ var VatInitConfig = shared.SingleTransformerConfig{
TransformerName: "vat init", TransformerName: "vat init",
ContractAddresses: []string{shared.VatContractAddress}, ContractAddresses: []string{shared.VatContractAddress},
ContractAbi: shared.VatABI, ContractAbi: shared.VatABI,
Topics: []string{shared.VatInitSignature}, Topic: shared.VatInitSignature,
StartingBlockNumber: 0, StartingBlockNumber: 0,
EndingBlockNumber: 10000000, EndingBlockNumber: 10000000,
} }

View File

@ -18,11 +18,11 @@ import (
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
) )
var VatMoveConfig = shared.TransformerConfig{ var VatMoveConfig = shared.SingleTransformerConfig{
TransformerName: "vat move", TransformerName: "vat move",
ContractAddresses: []string{shared.VatContractAddress}, ContractAddresses: []string{shared.VatContractAddress},
ContractAbi: shared.VatABI, ContractAbi: shared.VatABI,
Topics: []string{shared.VatMoveSignature}, Topic: shared.VatMoveSignature,
StartingBlockNumber: 0, StartingBlockNumber: 0,
EndingBlockNumber: 10000000, EndingBlockNumber: 10000000,
} }