Refactor drip_file transformers
This commit is contained in:
parent
ccca6e0229
commit
dc4eb009c1
@ -12,14 +12,15 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package drip_file
|
||||
package ilk
|
||||
|
||||
import "github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
||||
|
||||
var DripFileConfig = shared.TransformerConfig{
|
||||
var DripFileIlkConfig = shared.TransformerConfig{
|
||||
TransformerName: "drip file ilk",
|
||||
ContractAddresses: []string{shared.DripContractAddress},
|
||||
ContractAbi: shared.DripABI,
|
||||
Topics: []string{shared.DripFileIlkSignature, shared.DripFileRepoSignature},
|
||||
Topics: []string{shared.DripFileIlkSignature},
|
||||
StartingBlockNumber: 0,
|
||||
EndingBlockNumber: 10000000,
|
||||
}
|
@ -30,13 +30,14 @@ type Converter interface {
|
||||
|
||||
type DripFileIlkConverter struct{}
|
||||
|
||||
func (DripFileIlkConverter) ToModels(ethLogs []types.Log) ([]DripFileIlkModel, error) {
|
||||
var models []DripFileIlkModel
|
||||
func (DripFileIlkConverter) ToModels(ethLogs []types.Log) ([]interface{}, error) {
|
||||
var models []interface{}
|
||||
for _, ethLog := range ethLogs {
|
||||
err := verifyLog(ethLog)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ilk := string(bytes.Trim(ethLog.Topics[2].Bytes(), "\x00"))
|
||||
vow := string(bytes.Trim(ethLog.Topics[3].Bytes(), "\x00"))
|
||||
taxBytes := ethLog.Data[len(ethLog.Data)-shared.DataItemLength:]
|
||||
@ -45,6 +46,7 @@ func (DripFileIlkConverter) ToModels(ethLogs []types.Log) ([]DripFileIlkModel, e
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
model := DripFileIlkModel{
|
||||
Ilk: ilk,
|
||||
Vow: vow,
|
||||
|
@ -19,31 +19,25 @@ import (
|
||||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
||||
)
|
||||
|
||||
type Repository interface {
|
||||
Create(headerID int64, models []DripFileIlkModel) error
|
||||
MarkHeaderChecked(headerID int64) error
|
||||
MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error)
|
||||
}
|
||||
|
||||
type DripFileIlkRepository struct {
|
||||
db *postgres.DB
|
||||
DB *postgres.DB
|
||||
}
|
||||
|
||||
func NewDripFileIlkRepository(db *postgres.DB) DripFileIlkRepository {
|
||||
return DripFileIlkRepository{db: db}
|
||||
}
|
||||
|
||||
func (repository DripFileIlkRepository) Create(headerID int64, models []DripFileIlkModel) error {
|
||||
tx, err := repository.db.Begin()
|
||||
func (repository DripFileIlkRepository) Create(headerID int64, models []interface{}) error {
|
||||
tx, err := repository.DB.Begin()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var ilk DripFileIlkModel
|
||||
for _, model := range models {
|
||||
ilk = model.(DripFileIlkModel)
|
||||
_, err = tx.Exec(
|
||||
`INSERT into maker.drip_file_ilk (header_id, ilk, vow, tax, log_idx, tx_idx, raw_log)
|
||||
VALUES($1, $2, $3, $4::NUMERIC, $5, $6, $7)`,
|
||||
headerID, model.Ilk, model.Vow, model.Tax, model.LogIndex, model.TransactionIndex, model.Raw,
|
||||
VALUES($1, $2, $3, $4::NUMERIC, $5, $6, $7)`,
|
||||
headerID, ilk.Ilk, ilk.Vow, ilk.Tax, ilk.LogIndex, ilk.TransactionIndex, ilk.Raw,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
@ -51,36 +45,41 @@ func (repository DripFileIlkRepository) Create(headerID int64, models []DripFile
|
||||
}
|
||||
_, err = tx.Exec(`INSERT INTO public.checked_headers (header_id, drip_file_ilk_checked)
|
||||
VALUES ($1, $2)
|
||||
ON CONFLICT (header_id) DO
|
||||
UPDATE SET drip_file_ilk_checked = $2`, headerID, true)
|
||||
ON CONFLICT (header_id) DO
|
||||
UPDATE SET drip_file_ilk_checked = $2`, headerID, true)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.Commit()
|
||||
}
|
||||
|
||||
func (repository DripFileIlkRepository) MarkHeaderChecked(headerID int64) error {
|
||||
_, err := repository.db.Exec(`INSERT INTO public.checked_headers (header_id, drip_file_ilk_checked)
|
||||
_, err := repository.DB.Exec(`INSERT INTO public.checked_headers (header_id, drip_file_ilk_checked)
|
||||
VALUES ($1, $2)
|
||||
ON CONFLICT (header_id) DO
|
||||
UPDATE SET drip_file_ilk_checked = $2`, headerID, true)
|
||||
ON CONFLICT (header_id) DO
|
||||
UPDATE SET drip_file_ilk_checked = $2`, headerID, true)
|
||||
return err
|
||||
}
|
||||
|
||||
func (repository DripFileIlkRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) {
|
||||
var result []core.Header
|
||||
err := repository.db.Select(
|
||||
err := repository.DB.Select(
|
||||
&result,
|
||||
`SELECT headers.id, headers.block_number FROM headers
|
||||
LEFT JOIN checked_headers on headers.id = header_id
|
||||
LEFT JOIN checked_headers on headers.id = header_id
|
||||
WHERE (header_id ISNULL OR drip_file_ilk_checked IS FALSE)
|
||||
AND headers.block_number >= $1
|
||||
AND headers.block_number <= $2
|
||||
AND headers.eth_node_fingerprint = $3`,
|
||||
AND headers.block_number >= $1
|
||||
AND headers.block_number <= $2
|
||||
AND headers.eth_node_fingerprint = $3`,
|
||||
startingBlockNumber,
|
||||
endingBlockNumber,
|
||||
repository.db.Node.ID,
|
||||
repository.DB.Node.ID,
|
||||
)
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (repository *DripFileIlkRepository) SetDB(db *postgres.DB) {
|
||||
repository.DB = db
|
||||
}
|
||||
|
@ -1,79 +0,0 @@
|
||||
// Copyright 2018 Vulcanize
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package ilk
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
|
||||
"github.com/vulcanize/vulcanizedb/pkg/core"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/drip_file"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
||||
)
|
||||
|
||||
type DripFileIlkTransformer struct {
|
||||
Config shared.TransformerConfig
|
||||
Converter Converter
|
||||
Fetcher shared.LogFetcher
|
||||
Repository Repository
|
||||
}
|
||||
|
||||
type DripFileIlkTransformerInitializer struct {
|
||||
Config shared.TransformerConfig
|
||||
}
|
||||
|
||||
func (initializer DripFileIlkTransformerInitializer) NewDripFileIlkTransformer(db *postgres.DB, blockChain core.BlockChain) shared.Transformer {
|
||||
converter := DripFileIlkConverter{}
|
||||
fetcher := shared.NewFetcher(blockChain)
|
||||
repository := NewDripFileIlkRepository(db)
|
||||
return DripFileIlkTransformer{
|
||||
Config: initializer.Config,
|
||||
Converter: converter,
|
||||
Fetcher: fetcher,
|
||||
Repository: repository,
|
||||
}
|
||||
}
|
||||
|
||||
func (transformer DripFileIlkTransformer) Execute() error {
|
||||
missingHeaders, err := transformer.Repository.MissingHeaders(transformer.Config.StartingBlockNumber, transformer.Config.EndingBlockNumber)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
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.ContractAddresses, topics, header.BlockNumber)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(matchingLogs) < 1 {
|
||||
err = transformer.Repository.MarkHeaderChecked(header.Id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
model, err := transformer.Converter.ToModels(matchingLogs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = transformer.Repository.Create(header.Id, model)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
26
pkg/transformers/drip_file/repo/config.go
Normal file
26
pkg/transformers/drip_file/repo/config.go
Normal file
@ -0,0 +1,26 @@
|
||||
// Copyright 2018 Vulcanize
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package repo
|
||||
|
||||
import "github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
||||
|
||||
var DripFileRepoConfig = shared.TransformerConfig{
|
||||
TransformerName: "drip file repo",
|
||||
ContractAddresses: []string{shared.DripContractAddress},
|
||||
ContractAbi: shared.DripABI,
|
||||
Topics: []string{shared.DripFileRepoSignature},
|
||||
StartingBlockNumber: 0,
|
||||
EndingBlockNumber: 10000000,
|
||||
}
|
@ -22,25 +22,23 @@ import (
|
||||
"math/big"
|
||||
)
|
||||
|
||||
type Converter interface {
|
||||
ToModels(ethLogs []types.Log) ([]DripFileRepoModel, error)
|
||||
}
|
||||
|
||||
type DripFileRepoConverter struct{}
|
||||
|
||||
func (DripFileRepoConverter) ToModels(ethLogs []types.Log) ([]DripFileRepoModel, error) {
|
||||
var models []DripFileRepoModel
|
||||
func (DripFileRepoConverter) ToModels(ethLogs []types.Log) ([]interface{}, error) {
|
||||
var models []interface{}
|
||||
for _, ethLog := range ethLogs {
|
||||
err := verifyLog(ethLog)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
what := string(bytes.Trim(ethLog.Topics[2].Bytes(), "\x00"))
|
||||
data := big.NewInt(0).SetBytes(ethLog.Topics[3].Bytes()).String()
|
||||
raw, err := json.Marshal(ethLog)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
model := DripFileRepoModel{
|
||||
What: what,
|
||||
Data: data,
|
||||
|
@ -19,68 +19,69 @@ import (
|
||||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
||||
)
|
||||
|
||||
type Repository interface {
|
||||
Create(headerID int64, models []DripFileRepoModel) error
|
||||
MarkHeaderChecked(headerID int64) error
|
||||
MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error)
|
||||
}
|
||||
|
||||
type DripFileRepoRepository struct {
|
||||
db *postgres.DB
|
||||
DB *postgres.DB
|
||||
}
|
||||
|
||||
func NewDripFileRepoRepository(db *postgres.DB) DripFileRepoRepository {
|
||||
return DripFileRepoRepository{db: db}
|
||||
}
|
||||
|
||||
func (repository DripFileRepoRepository) Create(headerID int64, models []DripFileRepoModel) error {
|
||||
tx, err := repository.db.Begin()
|
||||
func (repository DripFileRepoRepository) Create(headerID int64, models []interface{}) error {
|
||||
tx, err := repository.DB.Begin()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var repo DripFileRepoModel
|
||||
for _, model := range models {
|
||||
repo = model.(DripFileRepoModel)
|
||||
_, err = tx.Exec(
|
||||
`INSERT into maker.drip_file_repo (header_id, what, data, log_idx, tx_idx, raw_log)
|
||||
VALUES($1, $2, $3::NUMERIC, $4, $5, $6)`,
|
||||
headerID, model.What, model.Data, model.LogIndex, model.TransactionIndex, model.Raw,
|
||||
VALUES($1, $2, $3::NUMERIC, $4, $5, $6)`,
|
||||
headerID, repo.What, repo.Data, repo.LogIndex, repo.TransactionIndex, repo.Raw,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
_, err = tx.Exec(`INSERT INTO public.checked_headers (header_id, drip_file_repo_checked)
|
||||
VALUES ($1, $2)
|
||||
ON CONFLICT (header_id) DO
|
||||
UPDATE SET drip_file_repo_checked = $2`, headerID, true)
|
||||
ON CONFLICT (header_id) DO
|
||||
UPDATE SET drip_file_repo_checked = $2`, headerID, true)
|
||||
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.Commit()
|
||||
}
|
||||
|
||||
func (repository DripFileRepoRepository) MarkHeaderChecked(headerID int64) error {
|
||||
_, err := repository.db.Exec(`INSERT INTO public.checked_headers (header_id, drip_file_repo_checked)
|
||||
_, err := repository.DB.Exec(`INSERT INTO public.checked_headers (header_id, drip_file_repo_checked)
|
||||
VALUES ($1, $2)
|
||||
ON CONFLICT (header_id) DO
|
||||
UPDATE SET drip_file_repo_checked = $2`, headerID, true)
|
||||
ON CONFLICT (header_id) DO
|
||||
UPDATE SET drip_file_repo_checked = $2`, headerID, true)
|
||||
return err
|
||||
}
|
||||
|
||||
func (repository DripFileRepoRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) {
|
||||
var result []core.Header
|
||||
err := repository.db.Select(
|
||||
err := repository.DB.Select(
|
||||
&result,
|
||||
`SELECT headers.id, headers.block_number FROM headers
|
||||
LEFT JOIN checked_headers on headers.id = header_id
|
||||
LEFT JOIN checked_headers on headers.id = header_id
|
||||
WHERE (header_id ISNULL OR drip_file_repo_checked IS FALSE)
|
||||
AND headers.block_number >= $1
|
||||
AND headers.block_number <= $2
|
||||
AND headers.eth_node_fingerprint = $3`,
|
||||
AND headers.block_number >= $1
|
||||
AND headers.block_number <= $2
|
||||
AND headers.eth_node_fingerprint = $3`,
|
||||
startingBlockNumber,
|
||||
endingBlockNumber,
|
||||
repository.db.Node.ID,
|
||||
repository.DB.Node.ID,
|
||||
)
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (repository *DripFileRepoRepository) SetDB(db *postgres.DB) {
|
||||
repository.DB = db
|
||||
}
|
||||
|
@ -1,79 +0,0 @@
|
||||
// Copyright 2018 Vulcanize
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package repo
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
|
||||
"github.com/vulcanize/vulcanizedb/pkg/core"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/drip_file"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
||||
)
|
||||
|
||||
type DripFileRepoTransformer struct {
|
||||
Config shared.TransformerConfig
|
||||
Converter Converter
|
||||
Fetcher shared.LogFetcher
|
||||
Repository Repository
|
||||
}
|
||||
|
||||
type DripFileRepoTransformerInitializer struct {
|
||||
Config shared.TransformerConfig
|
||||
}
|
||||
|
||||
func (initializer DripFileRepoTransformerInitializer) NewDripFileRepoTransformer(db *postgres.DB, blockChain core.BlockChain) shared.Transformer {
|
||||
converter := DripFileRepoConverter{}
|
||||
fetcher := shared.NewFetcher(blockChain)
|
||||
repository := NewDripFileRepoRepository(db)
|
||||
return DripFileRepoTransformer{
|
||||
Config: initializer.Config,
|
||||
Converter: converter,
|
||||
Fetcher: fetcher,
|
||||
Repository: repository,
|
||||
}
|
||||
}
|
||||
|
||||
func (transformer DripFileRepoTransformer) Execute() error {
|
||||
missingHeaders, err := transformer.Repository.MissingHeaders(transformer.Config.StartingBlockNumber, transformer.Config.EndingBlockNumber)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
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.ContractAddresses, topics, header.BlockNumber)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(matchingLogs) < 1 {
|
||||
err = transformer.Repository.MarkHeaderChecked(header.Id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
model, err := transformer.Converter.ToModels(matchingLogs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = transformer.Repository.Create(header.Id, model)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
26
pkg/transformers/drip_file/vow/config.go
Normal file
26
pkg/transformers/drip_file/vow/config.go
Normal file
@ -0,0 +1,26 @@
|
||||
// Copyright 2018 Vulcanize
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package vow
|
||||
|
||||
import "github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
||||
|
||||
var DripFileVowConfig = shared.TransformerConfig{
|
||||
TransformerName: "drip file vow",
|
||||
ContractAddresses: []string{shared.DripContractAddress},
|
||||
ContractAbi: shared.DripABI,
|
||||
Topics: []string{shared.DripFileVowSignature},
|
||||
StartingBlockNumber: 0,
|
||||
EndingBlockNumber: 10000000,
|
||||
}
|
@ -28,19 +28,21 @@ type Converter interface {
|
||||
|
||||
type DripFileVowConverter struct{}
|
||||
|
||||
func (DripFileVowConverter) ToModels(ethLogs []types.Log) ([]DripFileVowModel, error) {
|
||||
var models []DripFileVowModel
|
||||
func (DripFileVowConverter) ToModels(ethLogs []types.Log) ([]interface{}, error) {
|
||||
var models []interface{}
|
||||
for _, ethLog := range ethLogs {
|
||||
err := verifyLog(ethLog)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
what := string(bytes.Trim(ethLog.Topics[2].Bytes(), "\x00"))
|
||||
data := common.BytesToAddress(ethLog.Topics[3].Bytes()).String()
|
||||
raw, err := json.Marshal(ethLog)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
model := DripFileVowModel{
|
||||
What: what,
|
||||
Data: data,
|
||||
|
@ -19,68 +19,68 @@ import (
|
||||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
||||
)
|
||||
|
||||
type Repository interface {
|
||||
Create(headerID int64, models []DripFileVowModel) error
|
||||
MarkHeaderChecked(headerID int64) error
|
||||
MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error)
|
||||
}
|
||||
|
||||
type DripFileVowRepository struct {
|
||||
db *postgres.DB
|
||||
DB *postgres.DB
|
||||
}
|
||||
|
||||
func NewDripFileVowRepository(db *postgres.DB) DripFileVowRepository {
|
||||
return DripFileVowRepository{db: db}
|
||||
}
|
||||
|
||||
func (repository DripFileVowRepository) Create(headerID int64, models []DripFileVowModel) error {
|
||||
tx, err := repository.db.Begin()
|
||||
func (repository DripFileVowRepository) Create(headerID int64, models []interface{}) error {
|
||||
tx, err := repository.DB.Begin()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var vow DripFileVowModel
|
||||
for _, model := range models {
|
||||
vow = model.(DripFileVowModel)
|
||||
_, err = tx.Exec(
|
||||
`INSERT into maker.drip_file_vow (header_id, what, data, log_idx, tx_idx, raw_log)
|
||||
VALUES($1, $2, $3, $4, $5, $6)`,
|
||||
headerID, model.What, model.Data, model.LogIndex, model.TransactionIndex, model.Raw,
|
||||
VALUES($1, $2, $3, $4, $5, $6)`,
|
||||
headerID, vow.What, vow.Data, vow.LogIndex, vow.TransactionIndex, vow.Raw,
|
||||
)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
_, err = tx.Exec(`INSERT INTO public.checked_headers (header_id, drip_file_vow_checked)
|
||||
VALUES ($1, $2)
|
||||
ON CONFLICT (header_id) DO
|
||||
UPDATE SET drip_file_vow_checked = $2`, headerID, true)
|
||||
ON CONFLICT (header_id) DO
|
||||
UPDATE SET drip_file_vow_checked = $2`, headerID, true)
|
||||
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.Commit()
|
||||
}
|
||||
|
||||
func (repository DripFileVowRepository) MarkHeaderChecked(headerID int64) error {
|
||||
_, err := repository.db.Exec(`INSERT INTO public.checked_headers (header_id, drip_file_vow_checked)
|
||||
_, err := repository.DB.Exec(`INSERT INTO public.checked_headers (header_id, drip_file_vow_checked)
|
||||
VALUES ($1, $2)
|
||||
ON CONFLICT (header_id) DO
|
||||
UPDATE SET drip_file_vow_checked = $2`, headerID, true)
|
||||
ON CONFLICT (header_id) DO
|
||||
UPDATE SET drip_file_vow_checked = $2`, headerID, true)
|
||||
return err
|
||||
}
|
||||
|
||||
func (repository DripFileVowRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) {
|
||||
var result []core.Header
|
||||
err := repository.db.Select(
|
||||
err := repository.DB.Select(
|
||||
&result,
|
||||
`SELECT headers.id, headers.block_number FROM headers
|
||||
LEFT JOIN checked_headers on headers.id = header_id
|
||||
LEFT JOIN checked_headers on headers.id = header_id
|
||||
WHERE (header_id ISNULL OR drip_file_vow_checked IS FALSE)
|
||||
AND headers.block_number >= $1
|
||||
AND headers.block_number <= $2
|
||||
AND headers.eth_node_fingerprint = $3`,
|
||||
AND headers.block_number >= $1
|
||||
AND headers.block_number <= $2
|
||||
AND headers.eth_node_fingerprint = $3`,
|
||||
startingBlockNumber,
|
||||
endingBlockNumber,
|
||||
repository.db.Node.ID,
|
||||
repository.DB.Node.ID,
|
||||
)
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (repository *DripFileVowRepository) SetDB(db *postgres.DB) {
|
||||
repository.DB = db
|
||||
}
|
||||
|
@ -1,79 +0,0 @@
|
||||
// Copyright 2018 Vulcanize
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package vow
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
|
||||
"github.com/vulcanize/vulcanizedb/pkg/core"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/drip_file"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
||||
)
|
||||
|
||||
type DripFileVowTransformerInitializer struct {
|
||||
Config shared.TransformerConfig
|
||||
}
|
||||
|
||||
func (initializer DripFileVowTransformerInitializer) NewDripFileVowTransformer(db *postgres.DB, blockChain core.BlockChain) shared.Transformer {
|
||||
converter := DripFileVowConverter{}
|
||||
fetcher := shared.NewFetcher(blockChain)
|
||||
repository := NewDripFileVowRepository(db)
|
||||
return DripFileVowTransformer{
|
||||
Config: initializer.Config,
|
||||
Converter: converter,
|
||||
Fetcher: fetcher,
|
||||
Repository: repository,
|
||||
}
|
||||
}
|
||||
|
||||
type DripFileVowTransformer struct {
|
||||
Config shared.TransformerConfig
|
||||
Converter Converter
|
||||
Fetcher shared.LogFetcher
|
||||
Repository Repository
|
||||
}
|
||||
|
||||
func (transformer DripFileVowTransformer) Execute() error {
|
||||
missingHeaders, err := transformer.Repository.MissingHeaders(transformer.Config.StartingBlockNumber, transformer.Config.EndingBlockNumber)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
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.ContractAddresses, topics, header.BlockNumber)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(matchingLogs) < 1 {
|
||||
err = transformer.Repository.MarkHeaderChecked(header.Id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
model, err := transformer.Converter.ToModels(matchingLogs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = transformer.Repository.Create(header.Id, model)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
@ -23,7 +23,6 @@ import (
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/deal"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/dent"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/drip_drip"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/drip_file"
|
||||
ilk2 "github.com/vulcanize/vulcanizedb/pkg/transformers/drip_file/ilk"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/drip_file/repo"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/drip_file/vow"
|
||||
@ -49,31 +48,46 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
BiteTransformerInitializer = bite.BiteTransformerInitializer{Config: bite.BiteConfig}.NewBiteTransformer
|
||||
catFileConfig = cat_file.CatFileConfig
|
||||
CatFileChopLumpTransformerInitializer = chop_lump.CatFileChopLumpTransformerInitializer{Config: catFileConfig}.NewCatFileChopLumpTransformer
|
||||
CatFileFlipTransformerInitializer = flip.CatFileFlipTransformerInitializer{Config: catFileConfig}.NewCatFileFlipTransformer
|
||||
CatFilePitVowTransformerInitializer = pit_vow.CatFilePitVowTransformerInitializer{Config: catFileConfig}.NewCatFilePitVowTransformer
|
||||
DealTransformerInitializer = deal.DealTransformerInitializer{Config: deal.Config}.NewDealTransformer
|
||||
DentTransformerInitializer = dent.DentTransformerInitializer{Config: dent.DentConfig}.NewDentTransformer
|
||||
DripDripTransformerInitializer = drip_drip.DripDripTransformerInitializer{Config: drip_drip.DripDripConfig}.NewDripDripTransformer
|
||||
dripFileConfig = drip_file.DripFileConfig
|
||||
DripFileIlkTransformerInitializer = ilk2.DripFileIlkTransformerInitializer{Config: dripFileConfig}.NewDripFileIlkTransformer
|
||||
DripFileRepoTransformerInitializer = repo.DripFileRepoTransformerInitializer{Config: dripFileConfig}.NewDripFileRepoTransformer
|
||||
DripFileVowTransfromerInitializer = vow.DripFileVowTransformerInitializer{Config: dripFileConfig}.NewDripFileVowTransformer
|
||||
FlipKickTransformerInitializer = flip_kick.FlipKickTransformerInitializer{Config: flip_kick.FlipKickConfig}.NewFlipKickTransformer
|
||||
FlopKickTransformerInitializer = flop_kick.FlopKickTransformerInitializer{Config: flop_kick.Config}.NewFlopKickTransformer
|
||||
FrobTransformerInitializer = frob.FrobTransformerInitializer{Config: frob.FrobConfig}.NewFrobTransformer
|
||||
PriceFeedTransformerInitializer = price_feeds.PriceFeedTransformerInitializer{Config: price_feeds.PriceFeedConfig}.NewPriceFeedTransformer
|
||||
VatGrabTransformerInitializer = vat_grab.VatGrabTransformerInitializer{Config: vat_grab.VatGrabConfig}.NewVatGrabTransformer
|
||||
PitFileDebtCeilingTransformerInitializer = factories.Transformer{
|
||||
BiteTransformerInitializer = bite.BiteTransformerInitializer{Config: bite.BiteConfig}.NewBiteTransformer
|
||||
catFileConfig = cat_file.CatFileConfig
|
||||
CatFileChopLumpTransformerInitializer = chop_lump.CatFileChopLumpTransformerInitializer{Config: catFileConfig}.NewCatFileChopLumpTransformer
|
||||
CatFileFlipTransformerInitializer = flip.CatFileFlipTransformerInitializer{Config: catFileConfig}.NewCatFileFlipTransformer
|
||||
CatFilePitVowTransformerInitializer = pit_vow.CatFilePitVowTransformerInitializer{Config: catFileConfig}.NewCatFilePitVowTransformer
|
||||
DealTransformerInitializer = deal.DealTransformerInitializer{Config: deal.Config}.NewDealTransformer
|
||||
DentTransformerInitializer = dent.DentTransformerInitializer{Config: dent.DentConfig}.NewDentTransformer
|
||||
DripDripTransformerInitializer = drip_drip.DripDripTransformerInitializer{Config: drip_drip.DripDripConfig}.NewDripDripTransformer
|
||||
DripFileIlkTransformerInitializer = factories.Transformer{
|
||||
Config: ilk2.DripFileIlkConfig,
|
||||
Converter: &ilk2.DripFileIlkConverter{},
|
||||
Repository: &ilk2.DripFileIlkRepository{},
|
||||
Fetcher: &shared.Fetcher{},
|
||||
}.NewTransformer
|
||||
|
||||
DripFileRepoTransformerInitializer = factories.Transformer{
|
||||
Config: repo.DripFileRepoConfig,
|
||||
Converter: &repo.DripFileRepoConverter{},
|
||||
Repository: &repo.DripFileRepoRepository{},
|
||||
Fetcher: &shared.Fetcher{},
|
||||
}.NewTransformer
|
||||
|
||||
DripFileVowTransfromerInitializer = factories.Transformer{
|
||||
Config: vow.DripFileVowConfig,
|
||||
Converter: &vow.DripFileVowConverter{},
|
||||
Repository: &vow.DripFileVowRepository{},
|
||||
Fetcher: &shared.Fetcher{},
|
||||
}.NewTransformer
|
||||
|
||||
FlipKickTransformerInitializer = flip_kick.FlipKickTransformerInitializer{Config: flip_kick.FlipKickConfig}.NewFlipKickTransformer
|
||||
FlopKickTransformerInitializer = flop_kick.FlopKickTransformerInitializer{Config: flop_kick.Config}.NewFlopKickTransformer
|
||||
FrobTransformerInitializer = frob.FrobTransformerInitializer{Config: frob.FrobConfig}.NewFrobTransformer
|
||||
PitFileDebtCeilingTransformerInitializer = factories.Transformer{
|
||||
Config: debt_ceiling.DebtCeilingFileConfig,
|
||||
Converter: &debt_ceiling.PitFileDebtCeilingConverter{},
|
||||
Repository: &debt_ceiling.PitFileDebtCeilingRepository{},
|
||||
Fetcher: &shared.Fetcher{},
|
||||
}.NewTransformer
|
||||
|
||||
PitFileIlkTransformerInitializer = factories.Transformer{
|
||||
PitFileIlkTransformerInitializer = factories.Transformer{
|
||||
Config: ilk.IlkFileConfig,
|
||||
Converter: &ilk.PitFileIlkConverter{},
|
||||
Repository: &ilk.PitFileIlkRepository{},
|
||||
@ -87,6 +101,7 @@ var (
|
||||
Fetcher: &shared.Fetcher{},
|
||||
}.NewTransformer
|
||||
|
||||
PriceFeedTransformerInitializer = price_feeds.PriceFeedTransformerInitializer{Config: price_feeds.PriceFeedConfig}.NewPriceFeedTransformer
|
||||
TendTransformerInitializer = factories.Transformer{
|
||||
Config: tend.TendConfig,
|
||||
Converter: &tend.TendConverter{},
|
||||
@ -100,15 +115,15 @@ var (
|
||||
Repository: &vat_init.VatInitRepository{},
|
||||
Fetcher: &shared.Fetcher{},
|
||||
}.NewTransformer
|
||||
|
||||
VatGrabTransformerInitializer = vat_grab.VatGrabTransformerInitializer{Config: vat_grab.VatGrabConfig}.NewVatGrabTransformer
|
||||
VatHealTransformerInitializer = vat_heal.VatHealTransformerInitializer{Config: vat_heal.VatHealConfig}.NewVatHealTransformer
|
||||
VatFoldTransformerInitializer = vat_fold.VatFoldTransformerInitializer{Config: vat_fold.VatFoldConfig}.NewVatFoldTransformer
|
||||
VatMoveTransformerInitializer = factories.Transformer{
|
||||
Config: vat_move.VatMoveConfig,
|
||||
Converter: &vat_move.VatMoveConverter{},
|
||||
Repository: &vat_move.VatMoveRepository{},
|
||||
Fetcher: &shared.Fetcher{},
|
||||
}.NewTransformer
|
||||
VatHealTransformerInitializer = vat_heal.VatHealTransformerInitializer{Config: vat_heal.VatHealConfig}.NewVatHealTransformer
|
||||
VatFoldTransformerInitializer = vat_fold.VatFoldTransformerInitializer{Config: vat_fold.VatFoldConfig}.NewVatFoldTransformer
|
||||
VatSlipTransformerInitializer = vat_slip.VatSlipTransformerInitializer{Config: vat_slip.VatSlipConfig}.NewVatSlipTransformer
|
||||
VatTollTransformerInitializer = vat_toll.VatTollTransformerInitializer{Config: vat_toll.VatTollConfig}.NewVatTollTransformer
|
||||
VatTuneTransformerInitializer = vat_tune.VatTuneTransformerInitializer{Config: vat_tune.VatTuneConfig}.NewVatTuneTransformer
|
||||
|
Loading…
Reference in New Issue
Block a user