2018-11-23 18:12:24 +00:00
|
|
|
// VulcanizeDB
|
2019-03-12 15:46:42 +00:00
|
|
|
// Copyright © 2019 Vulcanize
|
2018-11-23 18:12:24 +00:00
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
package transformer
|
|
|
|
|
|
|
|
import (
|
2019-10-04 16:58:44 +00:00
|
|
|
"database/sql"
|
2018-11-23 18:12:24 +00:00
|
|
|
"errors"
|
2019-09-24 03:39:04 +00:00
|
|
|
"fmt"
|
2018-11-24 04:26:07 +00:00
|
|
|
"strings"
|
2018-11-23 18:12:24 +00:00
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
2018-12-18 19:00:26 +00:00
|
|
|
gethTypes "github.com/ethereum/go-ethereum/core/types"
|
2019-09-24 03:39:04 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
2018-11-23 18:12:24 +00:00
|
|
|
|
2019-03-14 21:49:27 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/config"
|
2019-05-01 06:02:30 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/contract_watcher/header/converter"
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/contract_watcher/header/fetcher"
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/contract_watcher/header/repository"
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/contract_watcher/header/retriever"
|
2019-03-11 23:18:54 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/contract_watcher/shared/contract"
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/contract_watcher/shared/parser"
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/contract_watcher/shared/poller"
|
|
|
|
srep "github.com/vulcanize/vulcanizedb/pkg/contract_watcher/shared/repository"
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/contract_watcher/shared/types"
|
2018-11-23 18:12:24 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/core"
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
|
|
|
)
|
|
|
|
|
2019-10-15 18:12:17 +00:00
|
|
|
// Transformer is the top level struct for transforming watched contract data
|
2019-05-01 06:02:30 +00:00
|
|
|
// Requires a header synced vDB (headers) and a running eth node (or infura)
|
2019-03-13 16:14:35 +00:00
|
|
|
type Transformer struct {
|
2018-11-23 18:12:24 +00:00
|
|
|
// Database interfaces
|
2019-03-14 21:49:27 +00:00
|
|
|
EventRepository srep.EventRepository // Holds transformed watched event log data
|
|
|
|
HeaderRepository repository.HeaderRepository // Interface for interaction with header repositories
|
2018-11-23 18:12:24 +00:00
|
|
|
|
|
|
|
// Pre-processing interfaces
|
2019-03-14 21:49:27 +00:00
|
|
|
Parser parser.Parser // Parses events and methods out of contract abi fetched using contract address
|
|
|
|
Retriever retriever.BlockRetriever // Retrieves first block for contract
|
2018-11-23 18:12:24 +00:00
|
|
|
|
|
|
|
// Processing interfaces
|
2019-03-14 21:49:27 +00:00
|
|
|
Fetcher fetcher.Fetcher // Fetches event logs, using header hashes
|
|
|
|
Converter converter.ConverterInterface // Converts watched event logs into custom log
|
|
|
|
Poller poller.Poller // Polls methods using arguments collected from events and persists them using a method datastore
|
2018-11-23 18:12:24 +00:00
|
|
|
|
2019-03-11 16:19:18 +00:00
|
|
|
// Store contract configuration information
|
|
|
|
Config config.ContractConfig
|
2018-11-23 18:12:24 +00:00
|
|
|
|
|
|
|
// Store contract info as mapping to contract address
|
|
|
|
Contracts map[string]*contract.Contract
|
|
|
|
|
2019-01-04 18:15:22 +00:00
|
|
|
// Internally configured transformer variables
|
|
|
|
contractAddresses []string // Holds all contract addresses, for batch fetching of logs
|
|
|
|
sortedEventIds map[string][]string // Map to sort event column ids by contract, for post fetch processing and persisting of logs
|
|
|
|
sortedMethodIds map[string][]string // Map to sort method column ids by contract, for post fetch method polling
|
|
|
|
eventIds []string // Holds event column ids across all contract, for batch fetching of headers
|
|
|
|
eventFilters []common.Hash // Holds topic0 hashes across all contracts, for batch fetching of logs
|
2019-03-14 21:49:27 +00:00
|
|
|
Start int64 // Hold the lowest starting block and the highest ending block
|
2018-11-23 18:12:24 +00:00
|
|
|
}
|
|
|
|
|
2018-12-14 17:52:02 +00:00
|
|
|
// Order-of-operations:
|
|
|
|
// 1. Create new transformer
|
|
|
|
// 2. Load contract addresses and their parameters
|
|
|
|
// 3. Init
|
2019-01-04 18:15:22 +00:00
|
|
|
// 4. Execute
|
2018-12-14 17:52:02 +00:00
|
|
|
|
2019-10-15 18:12:17 +00:00
|
|
|
// NewTransformer takes in a contract config, blockchain, and database, and returns a new Transformer
|
2019-03-13 16:14:35 +00:00
|
|
|
func NewTransformer(con config.ContractConfig, bc core.BlockChain, db *postgres.DB) *Transformer {
|
|
|
|
|
|
|
|
return &Transformer{
|
2019-05-01 06:02:30 +00:00
|
|
|
Poller: poller.NewPoller(bc, db, types.HeaderSync),
|
2019-03-14 21:49:27 +00:00
|
|
|
Fetcher: fetcher.NewFetcher(bc),
|
|
|
|
Parser: parser.NewParser(con.Network),
|
|
|
|
HeaderRepository: repository.NewHeaderRepository(db),
|
|
|
|
Retriever: retriever.NewBlockRetriever(db),
|
|
|
|
Converter: &converter.Converter{},
|
|
|
|
Contracts: map[string]*contract.Contract{},
|
2019-05-01 06:02:30 +00:00
|
|
|
EventRepository: srep.NewEventRepository(db, types.HeaderSync),
|
2019-03-14 21:49:27 +00:00
|
|
|
Config: con,
|
2018-11-23 18:12:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-15 18:12:17 +00:00
|
|
|
// Init initialized the Transformer
|
2018-11-23 18:12:24 +00:00
|
|
|
// Use after creating and setting transformer
|
|
|
|
// Loops over all of the addr => filter sets
|
|
|
|
// Uses parser to pull event info from abi
|
|
|
|
// Use this info to generate event filters
|
2019-03-13 16:14:35 +00:00
|
|
|
func (tr *Transformer) Init() error {
|
2019-01-04 18:15:22 +00:00
|
|
|
// Initialize internally configured transformer settings
|
|
|
|
tr.contractAddresses = make([]string, 0) // Holds all contract addresses, for batch fetching of logs
|
|
|
|
tr.sortedEventIds = make(map[string][]string) // Map to sort event column ids by contract, for post fetch processing and persisting of logs
|
|
|
|
tr.sortedMethodIds = make(map[string][]string) // Map to sort method column ids by contract, for post fetch method polling
|
|
|
|
tr.eventIds = make([]string, 0) // Holds event column ids across all contract, for batch fetching of headers
|
|
|
|
tr.eventFilters = make([]common.Hash, 0) // Holds topic0 hashes across all contracts, for batch fetching of logs
|
2019-03-14 21:49:27 +00:00
|
|
|
tr.Start = 100000000000
|
2019-01-04 18:15:22 +00:00
|
|
|
|
2018-11-24 04:26:07 +00:00
|
|
|
// Iterate through all internal contract addresses
|
2019-03-11 16:19:18 +00:00
|
|
|
for contractAddr := range tr.Config.Addresses {
|
|
|
|
// Configure Abi
|
|
|
|
if tr.Config.Abis[contractAddr] == "" {
|
|
|
|
// If no abi is given in the config, this method will try fetching from internal look-up table and etherscan
|
2019-09-24 03:39:04 +00:00
|
|
|
parseErr := tr.Parser.Parse(contractAddr)
|
|
|
|
if parseErr != nil {
|
|
|
|
return fmt.Errorf("error parsing contract by address: %s", parseErr.Error())
|
2019-03-11 16:19:18 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// If we have an abi from the config, load that into the parser
|
2019-09-24 03:39:04 +00:00
|
|
|
parseErr := tr.Parser.ParseAbiStr(tr.Config.Abis[contractAddr])
|
|
|
|
if parseErr != nil {
|
|
|
|
return fmt.Errorf("error parsing contract abi: %s", parseErr.Error())
|
2019-03-11 16:19:18 +00:00
|
|
|
}
|
2018-11-23 18:12:24 +00:00
|
|
|
}
|
|
|
|
|
2018-11-24 04:26:07 +00:00
|
|
|
// Get first block and most recent block number in the header repo
|
2019-09-24 03:39:04 +00:00
|
|
|
firstBlock, retrieveErr := tr.Retriever.RetrieveFirstBlock()
|
|
|
|
if retrieveErr != nil {
|
2019-10-04 16:58:44 +00:00
|
|
|
if retrieveErr == sql.ErrNoRows {
|
2019-10-28 13:48:06 +00:00
|
|
|
logrus.Error(fmt.Errorf("error retrieving first block: %s", retrieveErr.Error()))
|
2019-10-04 16:58:44 +00:00
|
|
|
firstBlock = 0
|
|
|
|
} else {
|
|
|
|
return fmt.Errorf("error retrieving first block: %s", retrieveErr.Error())
|
|
|
|
}
|
2018-11-23 18:12:24 +00:00
|
|
|
}
|
|
|
|
|
2018-11-24 04:26:07 +00:00
|
|
|
// Set to specified range if it falls within the bounds
|
2019-03-11 16:19:18 +00:00
|
|
|
if firstBlock < tr.Config.StartingBlocks[contractAddr] {
|
|
|
|
firstBlock = tr.Config.StartingBlocks[contractAddr]
|
2018-11-23 18:12:24 +00:00
|
|
|
}
|
|
|
|
|
2018-11-24 04:26:07 +00:00
|
|
|
// Get contract name if it has one
|
2018-11-23 18:12:24 +00:00
|
|
|
var name = new(string)
|
2019-09-24 03:39:04 +00:00
|
|
|
pollingErr := tr.Poller.FetchContractData(tr.Parser.Abi(), contractAddr, "name", nil, name, -1)
|
|
|
|
if pollingErr != nil {
|
|
|
|
// can't return this error because "name" might not exist on the contract
|
|
|
|
logrus.Warnf("error fetching contract data: %s", pollingErr.Error())
|
|
|
|
}
|
2018-11-23 18:12:24 +00:00
|
|
|
|
2019-03-11 16:19:18 +00:00
|
|
|
// Remove any potential accidental duplicate inputs
|
2018-12-07 15:38:46 +00:00
|
|
|
eventArgs := map[string]bool{}
|
2019-03-11 16:19:18 +00:00
|
|
|
for _, arg := range tr.Config.EventArgs[contractAddr] {
|
2018-12-07 15:38:46 +00:00
|
|
|
eventArgs[arg] = true
|
2018-11-23 18:12:24 +00:00
|
|
|
}
|
2018-12-07 15:38:46 +00:00
|
|
|
methodArgs := map[string]bool{}
|
2019-03-11 16:19:18 +00:00
|
|
|
for _, arg := range tr.Config.MethodArgs[contractAddr] {
|
2018-12-07 15:38:46 +00:00
|
|
|
methodArgs[arg] = true
|
2018-11-23 18:12:24 +00:00
|
|
|
}
|
|
|
|
|
2018-12-07 15:38:46 +00:00
|
|
|
// Aggregate info into contract object and store for execution
|
2019-01-04 18:15:22 +00:00
|
|
|
con := contract.Contract{
|
2019-03-11 16:19:18 +00:00
|
|
|
Name: *name,
|
|
|
|
Network: tr.Config.Network,
|
|
|
|
Address: contractAddr,
|
|
|
|
Abi: tr.Parser.Abi(),
|
|
|
|
ParsedAbi: tr.Parser.ParsedAbi(),
|
|
|
|
StartingBlock: firstBlock,
|
|
|
|
Events: tr.Parser.GetEvents(tr.Config.Events[contractAddr]),
|
|
|
|
Methods: tr.Parser.GetSelectMethods(tr.Config.Methods[contractAddr]),
|
|
|
|
FilterArgs: eventArgs,
|
|
|
|
MethodArgs: methodArgs,
|
|
|
|
Piping: tr.Config.Piping[contractAddr],
|
2018-12-07 15:38:46 +00:00
|
|
|
}.Init()
|
2019-01-04 18:15:22 +00:00
|
|
|
tr.Contracts[contractAddr] = con
|
|
|
|
tr.contractAddresses = append(tr.contractAddresses, con.Address)
|
2018-11-23 18:12:24 +00:00
|
|
|
|
2019-01-04 18:15:22 +00:00
|
|
|
// Create checked_headers columns for each event id and append to list of all event ids
|
|
|
|
tr.sortedEventIds[con.Address] = make([]string, 0, len(con.Events))
|
2018-11-23 18:12:24 +00:00
|
|
|
for _, event := range con.Events {
|
2019-10-15 18:12:17 +00:00
|
|
|
eventID := strings.ToLower(event.Name + "_" + con.Address)
|
|
|
|
addColumnErr := tr.HeaderRepository.AddCheckColumn(eventID)
|
2019-09-24 03:39:04 +00:00
|
|
|
if addColumnErr != nil {
|
|
|
|
return fmt.Errorf("error adding check column: %s", addColumnErr.Error())
|
2018-11-24 04:26:07 +00:00
|
|
|
}
|
2018-12-18 19:00:26 +00:00
|
|
|
// Keep track of this event id; sorted and unsorted
|
2019-10-15 18:12:17 +00:00
|
|
|
tr.sortedEventIds[con.Address] = append(tr.sortedEventIds[con.Address], eventID)
|
|
|
|
tr.eventIds = append(tr.eventIds, eventID)
|
2018-12-18 19:00:26 +00:00
|
|
|
// Append this event sig to the filters
|
2019-01-04 18:15:22 +00:00
|
|
|
tr.eventFilters = append(tr.eventFilters, event.Sig())
|
2018-12-18 19:00:26 +00:00
|
|
|
}
|
2018-12-19 18:42:59 +00:00
|
|
|
|
2019-01-04 18:15:22 +00:00
|
|
|
// Create checked_headers columns for each method id and append list of all method ids
|
|
|
|
tr.sortedMethodIds[con.Address] = make([]string, 0, len(con.Methods))
|
2018-12-19 18:42:59 +00:00
|
|
|
for _, m := range con.Methods {
|
2019-10-15 18:12:17 +00:00
|
|
|
methodID := strings.ToLower(m.Name + "_" + con.Address)
|
|
|
|
addColumnErr := tr.HeaderRepository.AddCheckColumn(methodID)
|
2019-09-24 03:39:04 +00:00
|
|
|
if addColumnErr != nil {
|
|
|
|
return fmt.Errorf("error adding check column: %s", addColumnErr.Error())
|
2018-12-19 18:42:59 +00:00
|
|
|
}
|
2019-10-15 18:12:17 +00:00
|
|
|
tr.sortedMethodIds[con.Address] = append(tr.sortedMethodIds[con.Address], methodID)
|
2018-12-19 18:42:59 +00:00
|
|
|
}
|
|
|
|
|
2019-01-04 18:15:22 +00:00
|
|
|
// Update start to the lowest block
|
2019-03-14 21:49:27 +00:00
|
|
|
if con.StartingBlock < tr.Start {
|
|
|
|
tr.Start = con.StartingBlock
|
2018-12-18 17:31:21 +00:00
|
|
|
}
|
2018-12-18 19:00:26 +00:00
|
|
|
}
|
|
|
|
|
2019-01-04 18:15:22 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-10-15 18:12:17 +00:00
|
|
|
// Execute runs the transformation processes
|
2019-03-13 16:14:35 +00:00
|
|
|
func (tr *Transformer) Execute() error {
|
2019-01-04 18:15:22 +00:00
|
|
|
if len(tr.Contracts) == 0 {
|
|
|
|
return errors.New("error: transformer has no initialized contracts")
|
|
|
|
}
|
|
|
|
|
2018-12-19 18:42:59 +00:00
|
|
|
// Find unchecked headers for all events across all contracts; these are returned in asc order
|
2019-09-24 03:39:04 +00:00
|
|
|
missingHeaders, missingHeadersErr := tr.HeaderRepository.MissingHeadersForAll(tr.Start, -1, tr.eventIds)
|
|
|
|
if missingHeadersErr != nil {
|
|
|
|
return fmt.Errorf("error getting missing headers: %s", missingHeadersErr.Error())
|
2018-12-18 19:00:26 +00:00
|
|
|
}
|
2018-11-24 04:26:07 +00:00
|
|
|
|
2018-12-18 19:00:26 +00:00
|
|
|
// Iterate over headers
|
|
|
|
for _, header := range missingHeaders {
|
2019-03-14 21:49:27 +00:00
|
|
|
// Set `start` to this header
|
|
|
|
// This way if we throw an error but don't bring the execution cycle down (how it is currently handled)
|
|
|
|
// we restart the cycle at this header
|
|
|
|
tr.Start = header.BlockNumber
|
|
|
|
// Map to sort batch fetched logs by which contract they belong to, for post fetch processing
|
|
|
|
sortedLogs := make(map[string][]gethTypes.Log)
|
2018-12-18 19:00:26 +00:00
|
|
|
// And fetch all event logs across contracts at this header
|
2019-09-24 03:39:04 +00:00
|
|
|
allLogs, fetchErr := tr.Fetcher.FetchLogs(tr.contractAddresses, tr.eventFilters, header)
|
|
|
|
if fetchErr != nil {
|
|
|
|
return fmt.Errorf("error fetching logs: %s", fetchErr.Error())
|
2018-12-18 17:31:21 +00:00
|
|
|
}
|
2018-12-18 19:00:26 +00:00
|
|
|
|
2019-01-04 18:15:22 +00:00
|
|
|
// If no logs are found mark the header checked for all of these eventIDs
|
|
|
|
// and continue to method polling and onto the next iteration
|
2018-12-18 19:00:26 +00:00
|
|
|
if len(allLogs) < 1 {
|
2019-09-24 03:39:04 +00:00
|
|
|
markCheckedErr := tr.HeaderRepository.MarkHeaderCheckedForAll(header.Id, tr.eventIds)
|
|
|
|
if markCheckedErr != nil {
|
|
|
|
return fmt.Errorf("error marking header checked: %s", markCheckedErr.Error())
|
2019-01-04 18:15:22 +00:00
|
|
|
}
|
2019-09-24 03:39:04 +00:00
|
|
|
pollingErr := tr.methodPolling(header, tr.sortedMethodIds)
|
|
|
|
if pollingErr != nil {
|
|
|
|
return fmt.Errorf("error polling methods: %s", pollingErr.Error())
|
2018-11-23 18:12:24 +00:00
|
|
|
}
|
2019-03-14 21:49:27 +00:00
|
|
|
tr.Start = header.BlockNumber + 1 // Empty header; setup to start at the next header
|
2019-09-24 03:39:04 +00:00
|
|
|
logrus.Tracef("no logs found for block %d, continuing", header.BlockNumber)
|
2019-01-04 18:15:22 +00:00
|
|
|
continue
|
2018-12-18 19:00:26 +00:00
|
|
|
}
|
2018-11-23 18:12:24 +00:00
|
|
|
|
2018-12-18 19:00:26 +00:00
|
|
|
for _, log := range allLogs {
|
2019-01-04 18:15:22 +00:00
|
|
|
addr := strings.ToLower(log.Address.Hex())
|
|
|
|
sortedLogs[addr] = append(sortedLogs[addr], log)
|
2018-12-18 19:00:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Process logs for each contract
|
|
|
|
for conAddr, logs := range sortedLogs {
|
2019-10-28 13:48:06 +00:00
|
|
|
if logs == nil {
|
2019-09-24 03:39:04 +00:00
|
|
|
logrus.Tracef("no logs found for contract %s at block %d, continuing", conAddr, header.BlockNumber)
|
2019-01-04 18:15:22 +00:00
|
|
|
continue
|
|
|
|
}
|
2018-12-18 19:00:26 +00:00
|
|
|
// Configure converter with this contract
|
2019-10-28 13:48:06 +00:00
|
|
|
con := tr.Contracts[conAddr]
|
2019-03-14 21:49:27 +00:00
|
|
|
tr.Converter.Update(con)
|
2018-11-23 18:12:24 +00:00
|
|
|
|
2019-01-04 18:15:22 +00:00
|
|
|
// Convert logs into batches of log mappings (eventName => []types.Logs
|
2019-09-24 03:39:04 +00:00
|
|
|
convertedLogs, convertErr := tr.Converter.ConvertBatch(logs, con.Events, header.Id)
|
|
|
|
if convertErr != nil {
|
|
|
|
return fmt.Errorf("error converting logs: %s", convertErr.Error())
|
2018-12-18 17:31:21 +00:00
|
|
|
}
|
2018-12-18 19:00:26 +00:00
|
|
|
// Cycle through each type of event log and persist them
|
|
|
|
for eventName, logs := range convertedLogs {
|
2018-12-19 18:42:59 +00:00
|
|
|
// If logs for this event are empty, mark them checked at this header and continue
|
2018-11-23 18:12:24 +00:00
|
|
|
if len(logs) < 1 {
|
2019-09-24 03:39:04 +00:00
|
|
|
logrus.Tracef("no logs found for event %s on contract %s at block %d, continuing", eventName, conAddr, header.BlockNumber)
|
2018-11-23 18:12:24 +00:00
|
|
|
continue
|
|
|
|
}
|
2018-11-24 04:26:07 +00:00
|
|
|
// If logs aren't empty, persist them
|
2019-09-24 03:39:04 +00:00
|
|
|
persistErr := tr.EventRepository.PersistLogs(logs, con.Events[eventName], con.Address, con.Name)
|
|
|
|
if persistErr != nil {
|
|
|
|
return fmt.Errorf("error persisting logs: %s", persistErr.Error())
|
2018-11-23 18:12:24 +00:00
|
|
|
}
|
2018-12-14 17:52:02 +00:00
|
|
|
}
|
2018-12-19 18:42:59 +00:00
|
|
|
}
|
2018-12-07 15:38:46 +00:00
|
|
|
|
2019-10-28 13:48:06 +00:00
|
|
|
markCheckedErr := tr.HeaderRepository.MarkHeaderCheckedForAll(header.Id, tr.eventIds)
|
|
|
|
if markCheckedErr != nil {
|
|
|
|
return fmt.Errorf("error marking header checked: %s", markCheckedErr.Error())
|
|
|
|
}
|
|
|
|
|
2018-12-19 18:42:59 +00:00
|
|
|
// Poll contracts at this block height
|
2019-09-24 03:39:04 +00:00
|
|
|
pollingErr := tr.methodPolling(header, tr.sortedMethodIds)
|
|
|
|
if pollingErr != nil {
|
|
|
|
return fmt.Errorf("error polling methods: %s", pollingErr.Error())
|
2018-12-19 18:42:59 +00:00
|
|
|
}
|
2019-03-14 21:49:27 +00:00
|
|
|
// Success; setup to start at the next header
|
|
|
|
tr.Start = header.BlockNumber + 1
|
2018-12-19 18:42:59 +00:00
|
|
|
}
|
2018-12-14 17:52:02 +00:00
|
|
|
|
2018-12-19 18:42:59 +00:00
|
|
|
return nil
|
|
|
|
}
|
2018-12-18 19:00:26 +00:00
|
|
|
|
2018-12-19 18:42:59 +00:00
|
|
|
// Used to poll contract methods at a given header
|
2019-03-13 16:14:35 +00:00
|
|
|
func (tr *Transformer) methodPolling(header core.Header, sortedMethodIds map[string][]string) error {
|
2018-12-19 18:42:59 +00:00
|
|
|
for _, con := range tr.Contracts {
|
|
|
|
// Skip method polling processes if no methods are specified
|
|
|
|
// Also don't try to poll methods below this contract's specified starting block
|
|
|
|
if len(con.Methods) == 0 || header.BlockNumber < con.StartingBlock {
|
2019-09-24 03:39:04 +00:00
|
|
|
logrus.Tracef("not polling contract: %s", con.Address)
|
2018-12-19 18:42:59 +00:00
|
|
|
continue
|
|
|
|
}
|
2018-12-14 17:52:02 +00:00
|
|
|
|
2018-12-19 18:42:59 +00:00
|
|
|
// Poll all methods for this contract at this header
|
2019-09-24 03:39:04 +00:00
|
|
|
pollingErr := tr.Poller.PollContractAt(*con, header.BlockNumber)
|
|
|
|
if pollingErr != nil {
|
|
|
|
return fmt.Errorf("error polling contract %s: %s", con.Address, pollingErr.Error())
|
2018-12-19 18:42:59 +00:00
|
|
|
}
|
2018-12-18 17:31:21 +00:00
|
|
|
|
2018-12-19 18:42:59 +00:00
|
|
|
// Mark this header checked for the methods
|
2019-09-24 03:39:04 +00:00
|
|
|
markCheckedErr := tr.HeaderRepository.MarkHeaderCheckedForAll(header.Id, sortedMethodIds[con.Address])
|
|
|
|
if markCheckedErr != nil {
|
|
|
|
return fmt.Errorf("error marking header checked: %s", markCheckedErr.Error())
|
2018-11-23 18:12:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-10-15 18:12:17 +00:00
|
|
|
// GetConfig returns the transformers config; satisfies the transformer interface
|
2019-03-13 16:14:35 +00:00
|
|
|
func (tr *Transformer) GetConfig() config.ContractConfig {
|
2019-03-11 16:19:18 +00:00
|
|
|
return tr.Config
|
2018-12-14 17:52:02 +00:00
|
|
|
}
|