Extract common repository methods

- Inject column names to reduce duplication across common behavior
- Extract checked headers column names to constants
This commit is contained in:
Rob Mulholand 2018-11-08 11:07:54 -06:00
parent 8c168ed332
commit 0b58efb56a
32 changed files with 186 additions and 387 deletions

View File

@ -18,6 +18,8 @@ import (
"fmt" "fmt"
"github.com/vulcanize/vulcanizedb/pkg/core" "github.com/vulcanize/vulcanizedb/pkg/core"
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
) )
type CatFileChopLumpRepository struct { type CatFileChopLumpRepository struct {
@ -47,10 +49,8 @@ func (repository CatFileChopLumpRepository) Create(headerID int64, models []inte
return err return err
} }
} }
_, err = tx.Exec(`INSERT INTO public.checked_headers (header_id, cat_file_chop_lump_checked)
VALUES ($1, $2) err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.CatFileChopLumpChecked)
ON CONFLICT (header_id) DO
UPDATE SET cat_file_chop_lump_checked = $2`, headerID, true)
if err != nil { if err != nil {
tx.Rollback() tx.Rollback()
return err return err
@ -59,28 +59,11 @@ func (repository CatFileChopLumpRepository) Create(headerID int64, models []inte
} }
func (repository CatFileChopLumpRepository) MarkHeaderChecked(headerID int64) error { func (repository CatFileChopLumpRepository) MarkHeaderChecked(headerID int64) error {
_, err := repository.db.Exec(`INSERT INTO public.checked_headers (header_id, cat_file_chop_lump_checked) return shared.MarkHeaderChecked(headerID, repository.db, constants.CatFileChopLumpChecked)
VALUES ($1, $2)
ON CONFLICT (header_id) DO
UPDATE SET cat_file_chop_lump_checked = $2`, headerID, true)
return err
} }
func (repository CatFileChopLumpRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { func (repository CatFileChopLumpRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) {
var result []core.Header return shared.MissingHeaders(startingBlockNumber, endingBlockNumber, repository.db, constants.CatFileChopLumpChecked)
err := repository.db.Select(
&result,
`SELECT headers.id, headers.block_number FROM headers
LEFT JOIN checked_headers on headers.id = header_id
WHERE (header_id ISNULL OR cat_file_chop_lump_checked IS FALSE)
AND headers.block_number >= $1
AND headers.block_number <= $2
AND headers.eth_node_fingerprint = $3`,
startingBlockNumber,
endingBlockNumber,
repository.db.Node.ID,
)
return result, err
} }
func (repository *CatFileChopLumpRepository) SetDB(db *postgres.DB) { func (repository *CatFileChopLumpRepository) SetDB(db *postgres.DB) {

View File

@ -21,6 +21,7 @@ import (
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories"
"github.com/vulcanize/vulcanizedb/pkg/fakes" "github.com/vulcanize/vulcanizedb/pkg/fakes"
"github.com/vulcanize/vulcanizedb/pkg/transformers/cat_file/chop_lump" "github.com/vulcanize/vulcanizedb/pkg/transformers/cat_file/chop_lump"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/shared_behaviors" "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/shared_behaviors"
"github.com/vulcanize/vulcanizedb/test_config" "github.com/vulcanize/vulcanizedb/test_config"
@ -43,7 +44,7 @@ var _ = Describe("Cat file chop lump repository", func() {
modelWithDifferentLogIdx := test_data.CatFileChopLumpModel modelWithDifferentLogIdx := test_data.CatFileChopLumpModel
modelWithDifferentLogIdx.LogIndex++ modelWithDifferentLogIdx.LogIndex++
inputs := shared_behaviors.CreateBehaviorInputs{ inputs := shared_behaviors.CreateBehaviorInputs{
CheckedHeaderColumnName: "cat_file_chop_lump_checked", CheckedHeaderColumnName: constants.CatFileChopLumpChecked,
LogEventTableName: "maker.cat_file_chop_lump", LogEventTableName: "maker.cat_file_chop_lump",
TestModel: test_data.CatFileChopLumpModel, TestModel: test_data.CatFileChopLumpModel,
ModelWithDifferentLogIdx: modelWithDifferentLogIdx, ModelWithDifferentLogIdx: modelWithDifferentLogIdx,
@ -73,7 +74,7 @@ var _ = Describe("Cat file chop lump repository", func() {
Describe("MarkHeaderChecked", func() { Describe("MarkHeaderChecked", func() {
inputs := shared_behaviors.MarkedHeaderCheckedBehaviorInputs{ inputs := shared_behaviors.MarkedHeaderCheckedBehaviorInputs{
CheckedHeaderColumnName: "cat_file_chop_lump_checked", CheckedHeaderColumnName: constants.CatFileChopLumpChecked,
Repository: &catFileRepository, Repository: &catFileRepository,
} }

View File

@ -18,6 +18,8 @@ import (
"fmt" "fmt"
"github.com/vulcanize/vulcanizedb/pkg/core" "github.com/vulcanize/vulcanizedb/pkg/core"
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
) )
type CatFileFlipRepository struct { type CatFileFlipRepository struct {
@ -46,11 +48,8 @@ func (repository CatFileFlipRepository) Create(headerID int64, models []interfac
return err return err
} }
} }
_, err = tx.Exec(`INSERT INTO public.checked_headers (header_id, cat_file_flip_checked)
VALUES ($1, $2)
ON CONFLICT (header_id) DO
UPDATE SET cat_file_flip_checked = $2`, headerID, true)
err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.CatFileFlipChecked)
if err != nil { if err != nil {
tx.Rollback() tx.Rollback()
return err return err
@ -59,28 +58,11 @@ func (repository CatFileFlipRepository) Create(headerID int64, models []interfac
} }
func (repository CatFileFlipRepository) MarkHeaderChecked(headerID int64) error { func (repository CatFileFlipRepository) MarkHeaderChecked(headerID int64) error {
_, err := repository.db.Exec(`INSERT INTO public.checked_headers (header_id, cat_file_flip_checked) return shared.MarkHeaderChecked(headerID, repository.db, constants.CatFileFlipChecked)
VALUES ($1, $2)
ON CONFLICT (header_id) DO
UPDATE SET cat_file_flip_checked = $2`, headerID, true)
return err
} }
func (repository CatFileFlipRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { func (repository CatFileFlipRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) {
var result []core.Header return shared.MissingHeaders(startingBlockNumber, endingBlockNumber, repository.db, constants.CatFileFlipChecked)
err := repository.db.Select(
&result,
`SELECT headers.id, headers.block_number FROM headers
LEFT JOIN checked_headers on headers.id = header_id
WHERE (header_id ISNULL OR cat_file_flip_checked IS FALSE)
AND headers.block_number >= $1
AND headers.block_number <= $2
AND headers.eth_node_fingerprint = $3`,
startingBlockNumber,
endingBlockNumber,
repository.db.Node.ID,
)
return result, err
} }
func (repository *CatFileFlipRepository) SetDB(db *postgres.DB) { func (repository *CatFileFlipRepository) SetDB(db *postgres.DB) {

View File

@ -23,6 +23,7 @@ import (
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories"
"github.com/vulcanize/vulcanizedb/pkg/fakes" "github.com/vulcanize/vulcanizedb/pkg/fakes"
"github.com/vulcanize/vulcanizedb/pkg/transformers/cat_file/flip" "github.com/vulcanize/vulcanizedb/pkg/transformers/cat_file/flip"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/shared_behaviors" "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/shared_behaviors"
"github.com/vulcanize/vulcanizedb/test_config" "github.com/vulcanize/vulcanizedb/test_config"
@ -47,7 +48,7 @@ var _ = Describe("Cat file flip repository", func() {
catFileFlipWithDifferentIdx := test_data.CatFileFlipModel catFileFlipWithDifferentIdx := test_data.CatFileFlipModel
catFileFlipWithDifferentIdx.LogIndex++ catFileFlipWithDifferentIdx.LogIndex++
inputs := shared_behaviors.CreateBehaviorInputs{ inputs := shared_behaviors.CreateBehaviorInputs{
CheckedHeaderColumnName: "cat_file_flip_checked", CheckedHeaderColumnName: constants.CatFileFlipChecked,
LogEventTableName: "maker.cat_file_flip", LogEventTableName: "maker.cat_file_flip",
TestModel: test_data.CatFileFlipModel, TestModel: test_data.CatFileFlipModel,
ModelWithDifferentLogIdx: catFileFlipWithDifferentIdx, ModelWithDifferentLogIdx: catFileFlipWithDifferentIdx,
@ -76,7 +77,7 @@ var _ = Describe("Cat file flip repository", func() {
Describe("MarkHeaderChecked", func() { Describe("MarkHeaderChecked", func() {
inputs := shared_behaviors.MarkedHeaderCheckedBehaviorInputs{ inputs := shared_behaviors.MarkedHeaderCheckedBehaviorInputs{
CheckedHeaderColumnName: "cat_file_flip_checked", CheckedHeaderColumnName: constants.CatFileFlipChecked,
Repository: &catFileFlipRepository, Repository: &catFileFlipRepository,
} }

View File

@ -18,6 +18,8 @@ import (
"fmt" "fmt"
"github.com/vulcanize/vulcanizedb/pkg/core" "github.com/vulcanize/vulcanizedb/pkg/core"
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
) )
type CatFilePitVowRepository struct { type CatFilePitVowRepository struct {
@ -46,10 +48,8 @@ func (repository CatFilePitVowRepository) Create(headerID int64, models []interf
return err return err
} }
} }
_, err = tx.Exec(`INSERT INTO public.checked_headers (header_id, cat_file_pit_vow_checked)
VALUES ($1, $2) err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.CatFilePitVowChecked)
ON CONFLICT (header_id) DO
UPDATE SET cat_file_pit_vow_checked = $2`, headerID, true)
if err != nil { if err != nil {
tx.Rollback() tx.Rollback()
return err return err
@ -58,28 +58,11 @@ func (repository CatFilePitVowRepository) Create(headerID int64, models []interf
} }
func (repository CatFilePitVowRepository) MarkHeaderChecked(headerID int64) error { func (repository CatFilePitVowRepository) MarkHeaderChecked(headerID int64) error {
_, err := repository.db.Exec(`INSERT INTO public.checked_headers (header_id, cat_file_pit_vow_checked) return shared.MarkHeaderChecked(headerID, repository.db, constants.CatFilePitVowChecked)
VALUES ($1, $2)
ON CONFLICT (header_id) DO
UPDATE SET cat_file_pit_vow_checked = $2`, headerID, true)
return err
} }
func (repository CatFilePitVowRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { func (repository CatFilePitVowRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) {
var result []core.Header return shared.MissingHeaders(startingBlockNumber, endingBlockNumber, repository.db, constants.CatFilePitVowChecked)
err := repository.db.Select(
&result,
`SELECT headers.id, headers.block_number FROM headers
LEFT JOIN checked_headers on headers.id = header_id
WHERE (header_id ISNULL OR cat_file_pit_vow_checked IS FALSE)
AND headers.block_number >= $1
AND headers.block_number <= $2
AND headers.eth_node_fingerprint = $3`,
startingBlockNumber,
endingBlockNumber,
repository.db.Node.ID,
)
return result, err
} }
func (repository *CatFilePitVowRepository) SetDB(db *postgres.DB) { func (repository *CatFilePitVowRepository) SetDB(db *postgres.DB) {

View File

@ -23,6 +23,7 @@ import (
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories"
"github.com/vulcanize/vulcanizedb/pkg/fakes" "github.com/vulcanize/vulcanizedb/pkg/fakes"
"github.com/vulcanize/vulcanizedb/pkg/transformers/cat_file/pit_vow" "github.com/vulcanize/vulcanizedb/pkg/transformers/cat_file/pit_vow"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/shared_behaviors" "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/shared_behaviors"
"github.com/vulcanize/vulcanizedb/test_config" "github.com/vulcanize/vulcanizedb/test_config"
@ -47,7 +48,7 @@ var _ = Describe("Cat file pit vow repository", func() {
modelWithDifferentLogIdx := test_data.CatFilePitVowModel modelWithDifferentLogIdx := test_data.CatFilePitVowModel
modelWithDifferentLogIdx.LogIndex++ modelWithDifferentLogIdx.LogIndex++
inputs := shared_behaviors.CreateBehaviorInputs{ inputs := shared_behaviors.CreateBehaviorInputs{
CheckedHeaderColumnName: "cat_file_pit_vow_checked", CheckedHeaderColumnName: constants.CatFilePitVowChecked,
LogEventTableName: "maker.cat_file_pit_vow", LogEventTableName: "maker.cat_file_pit_vow",
TestModel: test_data.CatFilePitVowModel, TestModel: test_data.CatFilePitVowModel,
ModelWithDifferentLogIdx: modelWithDifferentLogIdx, ModelWithDifferentLogIdx: modelWithDifferentLogIdx,
@ -75,7 +76,7 @@ var _ = Describe("Cat file pit vow repository", func() {
Describe("MarkHeaderChecked", func() { Describe("MarkHeaderChecked", func() {
inputs := shared_behaviors.MarkedHeaderCheckedBehaviorInputs{ inputs := shared_behaviors.MarkedHeaderCheckedBehaviorInputs{
CheckedHeaderColumnName: "cat_file_pit_vow_checked", CheckedHeaderColumnName: constants.CatFilePitVowChecked,
Repository: &catFilePitVowRepository, Repository: &catFilePitVowRepository,
} }
shared_behaviors.SharedRepositoryMarkHeaderCheckedBehaviors(&inputs) shared_behaviors.SharedRepositoryMarkHeaderCheckedBehaviors(&inputs)

View File

@ -18,6 +18,8 @@ import (
"fmt" "fmt"
"github.com/vulcanize/vulcanizedb/pkg/core" "github.com/vulcanize/vulcanizedb/pkg/core"
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
) )
type DealRepository struct { type DealRepository struct {
@ -47,11 +49,8 @@ func (repository DealRepository) Create(headerId int64, models []interface{}) er
return err return err
} }
} }
_, err = tx.Exec(`INSERT INTO public.checked_headers (header_id, deal_checked)
VALUES ($1, $2)
ON CONFLICT (header_id) DO
UPDATE SET deal_checked = $2`, headerId, true)
err = shared.MarkHeaderCheckedInTransaction(headerId, tx, constants.DealChecked)
if err != nil { if err != nil {
tx.Rollback() tx.Rollback()
return err return err
@ -60,27 +59,11 @@ func (repository DealRepository) Create(headerId int64, models []interface{}) er
} }
func (repository DealRepository) MarkHeaderChecked(headerID int64) error { func (repository DealRepository) MarkHeaderChecked(headerID int64) error {
_, err := repository.db.Exec(`INSERT INTO public.checked_headers (header_id, deal_checked) return shared.MarkHeaderChecked(headerID, repository.db, constants.DealChecked)
VALUES ($1, $2)
ON CONFLICT (header_id) DO
UPDATE SET deal_checked = $2`, headerID, true)
return err
} }
func (repository DealRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { func (repository DealRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) {
var missingHeaders []core.Header return shared.MissingHeaders(startingBlockNumber, endingBlockNumber, repository.db, constants.DealChecked)
err := repository.db.Select(&missingHeaders,
`SELECT headers.id, headers.block_number FROM headers
LEFT JOIN checked_headers on headers.id = header_id
WHERE (header_id ISNULL OR deal_checked IS FALSE)
AND headers.block_number >= $1
AND headers.block_number <= $2
AND headers.eth_node_fingerprint = $3`,
startingBlockNumber,
endingBlockNumber,
repository.db.Node.ID,
)
return missingHeaders, err
} }
func (repository *DealRepository) SetDB(db *postgres.DB) { func (repository *DealRepository) SetDB(db *postgres.DB) {

View File

@ -22,6 +22,7 @@ import (
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories"
"github.com/vulcanize/vulcanizedb/pkg/fakes" "github.com/vulcanize/vulcanizedb/pkg/fakes"
"github.com/vulcanize/vulcanizedb/pkg/transformers/deal" "github.com/vulcanize/vulcanizedb/pkg/transformers/deal"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/shared_behaviors" "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/shared_behaviors"
"github.com/vulcanize/vulcanizedb/test_config" "github.com/vulcanize/vulcanizedb/test_config"
@ -46,7 +47,7 @@ var _ = Describe("Deal Repository", func() {
modelWithDifferentLogIdx := test_data.DealModel modelWithDifferentLogIdx := test_data.DealModel
modelWithDifferentLogIdx.LogIndex = modelWithDifferentLogIdx.LogIndex + 1 modelWithDifferentLogIdx.LogIndex = modelWithDifferentLogIdx.LogIndex + 1
inputs := shared_behaviors.CreateBehaviorInputs{ inputs := shared_behaviors.CreateBehaviorInputs{
CheckedHeaderColumnName: "deal_checked", CheckedHeaderColumnName: constants.DealChecked,
LogEventTableName: "maker.deal", LogEventTableName: "maker.deal",
TestModel: test_data.DealModel, TestModel: test_data.DealModel,
ModelWithDifferentLogIdx: modelWithDifferentLogIdx, ModelWithDifferentLogIdx: modelWithDifferentLogIdx,
@ -77,7 +78,7 @@ var _ = Describe("Deal Repository", func() {
Describe("MarkHeaderChecked", func() { Describe("MarkHeaderChecked", func() {
inputs := shared_behaviors.MarkedHeaderCheckedBehaviorInputs{ inputs := shared_behaviors.MarkedHeaderCheckedBehaviorInputs{
CheckedHeaderColumnName: "deal_checked", CheckedHeaderColumnName: constants.DealChecked,
Repository: &dealRepository, Repository: &dealRepository,
} }

View File

@ -18,6 +18,8 @@ import (
"fmt" "fmt"
"github.com/vulcanize/vulcanizedb/pkg/core" "github.com/vulcanize/vulcanizedb/pkg/core"
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
) )
type DentRepository struct { type DentRepository struct {
@ -48,10 +50,7 @@ func (r DentRepository) Create(headerId int64, models []interface{}) error {
} }
} }
_, err = tx.Exec(`INSERT INTO public.checked_headers (header_id, dent_checked) err = shared.MarkHeaderCheckedInTransaction(headerId, tx, constants.DentChecked)
VALUES ($1, $2)
ON CONFLICT (header_id) DO
UPDATE SET dent_checked = $2`, headerId, true)
if err != nil { if err != nil {
tx.Rollback() tx.Rollback()
return err return err
@ -60,30 +59,11 @@ func (r DentRepository) Create(headerId int64, models []interface{}) error {
} }
func (r DentRepository) MarkHeaderChecked(headerId int64) error { func (r DentRepository) MarkHeaderChecked(headerId int64) error {
_, err := r.db.Exec(`INSERT INTO public.checked_headers (header_id, dent_checked) return shared.MarkHeaderChecked(headerId, r.db, constants.DentChecked)
VALUES ($1, $2)
ON CONFLICT (header_id) DO
UPDATE SET dent_checked = $2`, headerId, true)
return err
} }
func (r DentRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { func (r DentRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) {
var missingHeaders []core.Header return shared.MissingHeaders(startingBlockNumber, endingBlockNumber, r.db, constants.DentChecked)
err := r.db.Select(
&missingHeaders,
`SELECT headers.id, headers.block_number FROM headers
LEFT JOIN checked_headers on headers.id = header_id
WHERE (header_id ISNULL OR dent_checked IS FALSE)
AND headers.block_number >= $1
AND headers.block_number <= $2
AND headers.eth_node_fingerprint = $3`,
startingBlockNumber,
endingBlockNumber,
r.db.Node.ID,
)
return missingHeaders, err
} }
func (repository *DentRepository) SetDB(db *postgres.DB) { func (repository *DentRepository) SetDB(db *postgres.DB) {

View File

@ -22,6 +22,7 @@ import (
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories"
"github.com/vulcanize/vulcanizedb/pkg/fakes" "github.com/vulcanize/vulcanizedb/pkg/fakes"
"github.com/vulcanize/vulcanizedb/pkg/transformers/dent" "github.com/vulcanize/vulcanizedb/pkg/transformers/dent"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/shared_behaviors" "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/shared_behaviors"
"github.com/vulcanize/vulcanizedb/test_config" "github.com/vulcanize/vulcanizedb/test_config"
@ -46,7 +47,7 @@ var _ = Describe("Dent Repository", func() {
modelWithDifferentLogIdx := test_data.DentModel modelWithDifferentLogIdx := test_data.DentModel
modelWithDifferentLogIdx.LogIndex++ modelWithDifferentLogIdx.LogIndex++
inputs := shared_behaviors.CreateBehaviorInputs{ inputs := shared_behaviors.CreateBehaviorInputs{
CheckedHeaderColumnName: "dent_checked", CheckedHeaderColumnName: constants.DentChecked,
LogEventTableName: "maker.dent", LogEventTableName: "maker.dent",
TestModel: test_data.DentModel, TestModel: test_data.DentModel,
ModelWithDifferentLogIdx: modelWithDifferentLogIdx, ModelWithDifferentLogIdx: modelWithDifferentLogIdx,
@ -81,7 +82,7 @@ var _ = Describe("Dent Repository", func() {
Describe("MarkHeaderChecked", func() { Describe("MarkHeaderChecked", func() {
inputs := shared_behaviors.MarkedHeaderCheckedBehaviorInputs{ inputs := shared_behaviors.MarkedHeaderCheckedBehaviorInputs{
CheckedHeaderColumnName: "dent_checked", CheckedHeaderColumnName: constants.DentChecked,
Repository: &dentRepository, Repository: &dentRepository,
} }

View File

@ -18,6 +18,8 @@ import (
"fmt" "fmt"
"github.com/vulcanize/vulcanizedb/pkg/core" "github.com/vulcanize/vulcanizedb/pkg/core"
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
) )
type DripDripRepository struct { type DripDripRepository struct {
@ -46,10 +48,8 @@ func (repository DripDripRepository) Create(headerID int64, models []interface{}
return err return err
} }
} }
_, err = tx.Exec(`INSERT INTO public.checked_headers (header_id, drip_drip_checked)
VALUES ($1, $2) err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.DripDripChecked)
ON CONFLICT (header_id) DO
UPDATE SET drip_drip_checked = $2`, headerID, true)
if err != nil { if err != nil {
tx.Rollback() tx.Rollback()
return err return err
@ -58,28 +58,11 @@ func (repository DripDripRepository) Create(headerID int64, models []interface{}
} }
func (repository DripDripRepository) MarkHeaderChecked(headerID int64) error { func (repository DripDripRepository) MarkHeaderChecked(headerID int64) error {
_, err := repository.db.Exec(`INSERT INTO public.checked_headers (header_id, drip_drip_checked) return shared.MarkHeaderChecked(headerID, repository.db, constants.DripDripChecked)
VALUES ($1, $2)
ON CONFLICT (header_id) DO
UPDATE SET drip_drip_checked = $2`, headerID, true)
return err
} }
func (repository DripDripRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { func (repository DripDripRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) {
var result []core.Header return shared.MissingHeaders(startingBlockNumber, endingBlockNumber, repository.db, constants.DripDripChecked)
err := repository.db.Select(
&result,
`SELECT headers.id, headers.block_number FROM headers
LEFT JOIN checked_headers on headers.id = header_id
WHERE (header_id ISNULL OR drip_drip_checked IS FALSE)
AND headers.block_number >= $1
AND headers.block_number <= $2
AND headers.eth_node_fingerprint = $3`,
startingBlockNumber,
endingBlockNumber,
repository.db.Node.ID,
)
return result, err
} }
func (repository *DripDripRepository) SetDB(db *postgres.DB) { func (repository *DripDripRepository) SetDB(db *postgres.DB) {

View File

@ -22,6 +22,7 @@ import (
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories"
"github.com/vulcanize/vulcanizedb/pkg/fakes" "github.com/vulcanize/vulcanizedb/pkg/fakes"
"github.com/vulcanize/vulcanizedb/pkg/transformers/drip_drip" "github.com/vulcanize/vulcanizedb/pkg/transformers/drip_drip"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/shared_behaviors" "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/shared_behaviors"
"github.com/vulcanize/vulcanizedb/test_config" "github.com/vulcanize/vulcanizedb/test_config"
@ -46,7 +47,7 @@ var _ = Describe("Drip drip repository", func() {
modelWithDifferentLogIdx := test_data.DripDripModel modelWithDifferentLogIdx := test_data.DripDripModel
modelWithDifferentLogIdx.LogIndex++ modelWithDifferentLogIdx.LogIndex++
inputs := shared_behaviors.CreateBehaviorInputs{ inputs := shared_behaviors.CreateBehaviorInputs{
CheckedHeaderColumnName: "drip_drip_checked", CheckedHeaderColumnName: constants.DripDripChecked,
LogEventTableName: "maker.drip_drip", LogEventTableName: "maker.drip_drip",
TestModel: test_data.DripDripModel, TestModel: test_data.DripDripModel,
ModelWithDifferentLogIdx: modelWithDifferentLogIdx, ModelWithDifferentLogIdx: modelWithDifferentLogIdx,
@ -73,7 +74,7 @@ var _ = Describe("Drip drip repository", func() {
Describe("MarkHeaderChecked", func() { Describe("MarkHeaderChecked", func() {
inputs := shared_behaviors.MarkedHeaderCheckedBehaviorInputs{ inputs := shared_behaviors.MarkedHeaderCheckedBehaviorInputs{
CheckedHeaderColumnName: "drip_drip_checked", CheckedHeaderColumnName: constants.DripDripChecked,
Repository: &dripDripRepository, Repository: &dripDripRepository,
} }

View File

@ -18,6 +18,8 @@ import (
"fmt" "fmt"
"github.com/vulcanize/vulcanizedb/pkg/core" "github.com/vulcanize/vulcanizedb/pkg/core"
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
) )
type DripFileIlkRepository struct { type DripFileIlkRepository struct {
@ -48,10 +50,8 @@ func (repository DripFileIlkRepository) Create(headerID int64, models []interfac
return err return err
} }
} }
_, err = tx.Exec(`INSERT INTO public.checked_headers (header_id, drip_file_ilk_checked)
VALUES ($1, $2) err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.DripFileIlkChecked)
ON CONFLICT (header_id) DO
UPDATE SET drip_file_ilk_checked = $2`, headerID, true)
if err != nil { if err != nil {
tx.Rollback() tx.Rollback()
return err return err
@ -61,28 +61,11 @@ func (repository DripFileIlkRepository) Create(headerID int64, models []interfac
} }
func (repository DripFileIlkRepository) MarkHeaderChecked(headerID int64) error { func (repository DripFileIlkRepository) MarkHeaderChecked(headerID int64) error {
_, err := repository.db.Exec(`INSERT INTO public.checked_headers (header_id, drip_file_ilk_checked) return shared.MarkHeaderChecked(headerID, repository.db, constants.DripFileIlkChecked)
VALUES ($1, $2)
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) { func (repository DripFileIlkRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) {
var result []core.Header return shared.MissingHeaders(startingBlockNumber, endingBlockNumber, repository.db, constants.DripFileIlkChecked)
err := repository.db.Select(
&result,
`SELECT headers.id, headers.block_number FROM headers
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`,
startingBlockNumber,
endingBlockNumber,
repository.db.Node.ID,
)
return result, err
} }
func (repository *DripFileIlkRepository) SetDB(db *postgres.DB) { func (repository *DripFileIlkRepository) SetDB(db *postgres.DB) {

View File

@ -22,6 +22,7 @@ import (
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories"
"github.com/vulcanize/vulcanizedb/pkg/fakes" "github.com/vulcanize/vulcanizedb/pkg/fakes"
"github.com/vulcanize/vulcanizedb/pkg/transformers/drip_file/ilk" "github.com/vulcanize/vulcanizedb/pkg/transformers/drip_file/ilk"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/shared_behaviors" "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/shared_behaviors"
"github.com/vulcanize/vulcanizedb/test_config" "github.com/vulcanize/vulcanizedb/test_config"
@ -46,7 +47,7 @@ var _ = Describe("Drip file ilk repository", func() {
modelWithDifferentLogIdx := test_data.DripFileIlkModel modelWithDifferentLogIdx := test_data.DripFileIlkModel
modelWithDifferentLogIdx.LogIndex++ modelWithDifferentLogIdx.LogIndex++
inputs := shared_behaviors.CreateBehaviorInputs{ inputs := shared_behaviors.CreateBehaviorInputs{
CheckedHeaderColumnName: "drip_file_ilk_checked", CheckedHeaderColumnName: constants.DripFileIlkChecked,
LogEventTableName: "maker.drip_file_ilk", LogEventTableName: "maker.drip_file_ilk",
TestModel: test_data.DripFileIlkModel, TestModel: test_data.DripFileIlkModel,
ModelWithDifferentLogIdx: modelWithDifferentLogIdx, ModelWithDifferentLogIdx: modelWithDifferentLogIdx,
@ -75,7 +76,7 @@ var _ = Describe("Drip file ilk repository", func() {
Describe("MarkHeaderChecked", func() { Describe("MarkHeaderChecked", func() {
inputs := shared_behaviors.MarkedHeaderCheckedBehaviorInputs{ inputs := shared_behaviors.MarkedHeaderCheckedBehaviorInputs{
CheckedHeaderColumnName: "drip_file_ilk_checked", CheckedHeaderColumnName: constants.DripFileIlkChecked,
Repository: &dripFileIlkRepository, Repository: &dripFileIlkRepository,
} }

View File

@ -18,6 +18,8 @@ import (
"fmt" "fmt"
"github.com/vulcanize/vulcanizedb/pkg/core" "github.com/vulcanize/vulcanizedb/pkg/core"
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
) )
type DripFileRepoRepository struct { type DripFileRepoRepository struct {
@ -49,11 +51,7 @@ func (repository DripFileRepoRepository) Create(headerID int64, models []interfa
} }
} }
_, err = tx.Exec(`INSERT INTO public.checked_headers (header_id, drip_file_repo_checked) err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.DripFileRepoChecked)
VALUES ($1, $2)
ON CONFLICT (header_id) DO
UPDATE SET drip_file_repo_checked = $2`, headerID, true)
if err != nil { if err != nil {
tx.Rollback() tx.Rollback()
return err return err
@ -63,28 +61,11 @@ func (repository DripFileRepoRepository) Create(headerID int64, models []interfa
} }
func (repository DripFileRepoRepository) MarkHeaderChecked(headerID int64) error { func (repository DripFileRepoRepository) MarkHeaderChecked(headerID int64) error {
_, err := repository.db.Exec(`INSERT INTO public.checked_headers (header_id, drip_file_repo_checked) return shared.MarkHeaderChecked(headerID, repository.db, constants.DripFileRepoChecked)
VALUES ($1, $2)
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) { func (repository DripFileRepoRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) {
var result []core.Header return shared.MissingHeaders(startingBlockNumber, endingBlockNumber, repository.db, constants.DripFileRepoChecked)
err := repository.db.Select(
&result,
`SELECT headers.id, headers.block_number FROM headers
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`,
startingBlockNumber,
endingBlockNumber,
repository.db.Node.ID,
)
return result, err
} }
func (repository *DripFileRepoRepository) SetDB(db *postgres.DB) { func (repository *DripFileRepoRepository) SetDB(db *postgres.DB) {

View File

@ -23,6 +23,7 @@ import (
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories"
"github.com/vulcanize/vulcanizedb/pkg/fakes" "github.com/vulcanize/vulcanizedb/pkg/fakes"
"github.com/vulcanize/vulcanizedb/pkg/transformers/drip_file/repo" "github.com/vulcanize/vulcanizedb/pkg/transformers/drip_file/repo"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/shared_behaviors" "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/shared_behaviors"
"github.com/vulcanize/vulcanizedb/test_config" "github.com/vulcanize/vulcanizedb/test_config"
@ -47,7 +48,7 @@ var _ = Describe("Drip file repo repository", func() {
modelWithDifferentLogIdx := test_data.DripFileRepoModel modelWithDifferentLogIdx := test_data.DripFileRepoModel
modelWithDifferentLogIdx.LogIndex++ modelWithDifferentLogIdx.LogIndex++
inputs := shared_behaviors.CreateBehaviorInputs{ inputs := shared_behaviors.CreateBehaviorInputs{
CheckedHeaderColumnName: "drip_file_repo_checked", CheckedHeaderColumnName: constants.DripFileRepoChecked,
LogEventTableName: "maker.drip_file_repo", LogEventTableName: "maker.drip_file_repo",
TestModel: test_data.DripFileRepoModel, TestModel: test_data.DripFileRepoModel,
ModelWithDifferentLogIdx: modelWithDifferentLogIdx, ModelWithDifferentLogIdx: modelWithDifferentLogIdx,
@ -75,7 +76,7 @@ var _ = Describe("Drip file repo repository", func() {
Describe("MarkHeaderChecked", func() { Describe("MarkHeaderChecked", func() {
inputs := shared_behaviors.MarkedHeaderCheckedBehaviorInputs{ inputs := shared_behaviors.MarkedHeaderCheckedBehaviorInputs{
CheckedHeaderColumnName: "drip_file_repo_checked", CheckedHeaderColumnName: constants.DripFileRepoChecked,
Repository: &dripFileRepoRepository, Repository: &dripFileRepoRepository,
} }

View File

@ -18,6 +18,8 @@ import (
"fmt" "fmt"
"github.com/vulcanize/vulcanizedb/pkg/core" "github.com/vulcanize/vulcanizedb/pkg/core"
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
) )
type DripFileVowRepository struct { type DripFileVowRepository struct {
@ -48,11 +50,7 @@ func (repository DripFileVowRepository) Create(headerID int64, models []interfac
} }
} }
_, err = tx.Exec(`INSERT INTO public.checked_headers (header_id, drip_file_vow_checked) err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.DripFileVowChecked)
VALUES ($1, $2)
ON CONFLICT (header_id) DO
UPDATE SET drip_file_vow_checked = $2`, headerID, true)
if err != nil { if err != nil {
tx.Rollback() tx.Rollback()
return err return err
@ -62,28 +60,11 @@ func (repository DripFileVowRepository) Create(headerID int64, models []interfac
} }
func (repository DripFileVowRepository) MarkHeaderChecked(headerID int64) error { func (repository DripFileVowRepository) MarkHeaderChecked(headerID int64) error {
_, err := repository.db.Exec(`INSERT INTO public.checked_headers (header_id, drip_file_vow_checked) return shared.MarkHeaderChecked(headerID, repository.db, constants.DripFileVowChecked)
VALUES ($1, $2)
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) { func (repository DripFileVowRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) {
var result []core.Header return shared.MissingHeaders(startingBlockNumber, endingBlockNumber, repository.db, constants.DripFileVowChecked)
err := repository.db.Select(
&result,
`SELECT headers.id, headers.block_number FROM headers
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`,
startingBlockNumber,
endingBlockNumber,
repository.db.Node.ID,
)
return result, err
} }
func (repository *DripFileVowRepository) SetDB(db *postgres.DB) { func (repository *DripFileVowRepository) SetDB(db *postgres.DB) {

View File

@ -22,6 +22,7 @@ import (
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories"
"github.com/vulcanize/vulcanizedb/pkg/fakes" "github.com/vulcanize/vulcanizedb/pkg/fakes"
"github.com/vulcanize/vulcanizedb/pkg/transformers/drip_file/vow" "github.com/vulcanize/vulcanizedb/pkg/transformers/drip_file/vow"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/shared_behaviors" "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/shared_behaviors"
"github.com/vulcanize/vulcanizedb/test_config" "github.com/vulcanize/vulcanizedb/test_config"
@ -46,7 +47,7 @@ var _ = Describe("Drip file vow repository", func() {
modelWithDifferentLogIdx := test_data.DripFileVowModel modelWithDifferentLogIdx := test_data.DripFileVowModel
modelWithDifferentLogIdx.LogIndex++ modelWithDifferentLogIdx.LogIndex++
inputs := shared_behaviors.CreateBehaviorInputs{ inputs := shared_behaviors.CreateBehaviorInputs{
CheckedHeaderColumnName: "drip_file_vow_checked", CheckedHeaderColumnName: constants.DripFileVowChecked,
LogEventTableName: "maker.drip_file_vow", LogEventTableName: "maker.drip_file_vow",
TestModel: test_data.DripFileVowModel, TestModel: test_data.DripFileVowModel,
ModelWithDifferentLogIdx: modelWithDifferentLogIdx, ModelWithDifferentLogIdx: modelWithDifferentLogIdx,
@ -83,7 +84,7 @@ var _ = Describe("Drip file vow repository", func() {
Describe("MissingHeaders", func() { Describe("MissingHeaders", func() {
inputs := shared_behaviors.MarkedHeaderCheckedBehaviorInputs{ inputs := shared_behaviors.MarkedHeaderCheckedBehaviorInputs{
CheckedHeaderColumnName: "drip_file_vow_checked", CheckedHeaderColumnName: constants.DripFileVowChecked,
Repository: &dripFileVowRepository, Repository: &dripFileVowRepository,
} }

View File

@ -18,6 +18,8 @@ import (
"fmt" "fmt"
"github.com/vulcanize/vulcanizedb/pkg/core" "github.com/vulcanize/vulcanizedb/pkg/core"
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
) )
type FlapKickRepository struct { type FlapKickRepository struct {
@ -44,10 +46,8 @@ func (repository *FlapKickRepository) Create(headerID int64, models []interface{
return err return err
} }
} }
_, err = tx.Exec(`INSERT INTO public.checked_headers (header_id, flap_kick_checked)
VALUES ($1, $2) err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.FlapKickChecked)
ON CONFLICT (header_id) DO
UPDATE SET flap_kick_checked = $2`, headerID, true)
if err != nil { if err != nil {
tx.Rollback() tx.Rollback()
return err return err
@ -56,34 +56,11 @@ func (repository *FlapKickRepository) Create(headerID int64, models []interface{
} }
func (repository *FlapKickRepository) MarkHeaderChecked(headerID int64) error { func (repository *FlapKickRepository) MarkHeaderChecked(headerID int64) error {
_, err := repository.db.Exec(`INSERT INTO public.checked_headers (header_id, flap_kick_checked) return shared.MarkHeaderChecked(headerID, repository.db, constants.FlapKickChecked)
VALUES ($1, $2)
ON CONFLICT (header_id) DO
UPDATE SET flap_kick_checked = $2`, headerID, true)
return err
} }
func (repository FlapKickRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { func (repository FlapKickRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) {
var result []core.Header return shared.MissingHeaders(startingBlockNumber, endingBlockNumber, repository.db, constants.FlapKickChecked)
err := repository.db.Select(
&result,
`SELECT headers.id, headers.block_number FROM headers
LEFT JOIN checked_headers on headers.id = header_id
WHERE (header_id ISNULL OR flap_kick_checked IS FALSE)
AND headers.block_number >= $1
AND headers.block_number <= $2
AND headers.eth_node_fingerprint = $3`,
startingBlockNumber,
endingBlockNumber,
repository.db.Node.ID,
)
if err != nil {
fmt.Println("Error:", err)
return result, err
}
return result, nil
} }
func (repository *FlapKickRepository) SetDB(db *postgres.DB) { func (repository *FlapKickRepository) SetDB(db *postgres.DB) {

View File

@ -22,6 +22,7 @@ import (
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories"
"github.com/vulcanize/vulcanizedb/pkg/fakes" "github.com/vulcanize/vulcanizedb/pkg/fakes"
"github.com/vulcanize/vulcanizedb/pkg/transformers/flap_kick" "github.com/vulcanize/vulcanizedb/pkg/transformers/flap_kick"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/shared_behaviors" "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/shared_behaviors"
"github.com/vulcanize/vulcanizedb/test_config" "github.com/vulcanize/vulcanizedb/test_config"
@ -46,7 +47,7 @@ var _ = Describe("Flap Kick Repository", func() {
modelWithDifferentLogIdx := test_data.FlapKickModel modelWithDifferentLogIdx := test_data.FlapKickModel
modelWithDifferentLogIdx.LogIndex = modelWithDifferentLogIdx.LogIndex + 1 modelWithDifferentLogIdx.LogIndex = modelWithDifferentLogIdx.LogIndex + 1
inputs := shared_behaviors.CreateBehaviorInputs{ inputs := shared_behaviors.CreateBehaviorInputs{
CheckedHeaderColumnName: "flap_kick_checked", CheckedHeaderColumnName: constants.FlapKickChecked,
LogEventTableName: "maker.flap_kick", LogEventTableName: "maker.flap_kick",
TestModel: test_data.FlapKickModel, TestModel: test_data.FlapKickModel,
ModelWithDifferentLogIdx: modelWithDifferentLogIdx, ModelWithDifferentLogIdx: modelWithDifferentLogIdx,
@ -80,7 +81,7 @@ var _ = Describe("Flap Kick Repository", func() {
Describe("MarkHeaderChecked", func() { Describe("MarkHeaderChecked", func() {
inputs := shared_behaviors.MarkedHeaderCheckedBehaviorInputs{ inputs := shared_behaviors.MarkedHeaderCheckedBehaviorInputs{
CheckedHeaderColumnName: "flap_kick_checked", CheckedHeaderColumnName: constants.FlapKickChecked,
Repository: &flapKickRepository, Repository: &flapKickRepository,
} }

View File

@ -18,6 +18,8 @@ import (
"fmt" "fmt"
"github.com/vulcanize/vulcanizedb/pkg/core" "github.com/vulcanize/vulcanizedb/pkg/core"
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
) )
type PitFileDebtCeilingRepository struct { type PitFileDebtCeilingRepository struct {
@ -49,11 +51,7 @@ func (repository PitFileDebtCeilingRepository) Create(headerID int64, models []i
} }
} }
_, err = tx.Exec(`INSERT INTO public.checked_headers (header_id, pit_file_debt_ceiling_checked) err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.PitFileDebtCeilingChecked)
VALUES ($1, $2)
ON CONFLICT (header_id) DO
UPDATE SET pit_file_debt_ceiling_checked = $2`, headerID, true)
if err != nil { if err != nil {
tx.Rollback() tx.Rollback()
return err return err
@ -63,28 +61,11 @@ func (repository PitFileDebtCeilingRepository) Create(headerID int64, models []i
} }
func (repository PitFileDebtCeilingRepository) MarkHeaderChecked(headerID int64) error { func (repository PitFileDebtCeilingRepository) MarkHeaderChecked(headerID int64) error {
_, err := repository.db.Exec(`INSERT INTO public.checked_headers (header_id, pit_file_debt_ceiling_checked) return shared.MarkHeaderChecked(headerID, repository.db, constants.PitFileDebtCeilingChecked)
VALUES ($1, $2)
ON CONFLICT (header_id) DO
UPDATE SET pit_file_debt_ceiling_checked = $2`, headerID, true)
return err
} }
func (repository PitFileDebtCeilingRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { func (repository PitFileDebtCeilingRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) {
var result []core.Header return shared.MissingHeaders(startingBlockNumber, endingBlockNumber, repository.db, constants.PitFileDebtCeilingChecked)
err := repository.db.Select(
&result,
`SELECT headers.id, headers.block_number FROM headers
LEFT JOIN checked_headers on headers.id = header_id
WHERE (header_id ISNULL OR pit_file_debt_ceiling_checked IS FALSE)
AND headers.block_number >= $1
AND headers.block_number <= $2
AND headers.eth_node_fingerprint = $3`,
startingBlockNumber,
endingBlockNumber,
repository.db.Node.ID,
)
return result, err
} }
func (repository *PitFileDebtCeilingRepository) SetDB(db *postgres.DB) { func (repository *PitFileDebtCeilingRepository) SetDB(db *postgres.DB) {

View File

@ -22,6 +22,7 @@ import (
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories"
"github.com/vulcanize/vulcanizedb/pkg/fakes" "github.com/vulcanize/vulcanizedb/pkg/fakes"
"github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file/debt_ceiling" "github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file/debt_ceiling"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/shared_behaviors" "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/shared_behaviors"
"github.com/vulcanize/vulcanizedb/test_config" "github.com/vulcanize/vulcanizedb/test_config"
@ -46,7 +47,7 @@ var _ = Describe("Pit file debt ceiling repository", func() {
modelWithDifferentLogIdx := test_data.PitFileDebtCeilingModel modelWithDifferentLogIdx := test_data.PitFileDebtCeilingModel
modelWithDifferentLogIdx.LogIndex = modelWithDifferentLogIdx.LogIndex + 1 modelWithDifferentLogIdx.LogIndex = modelWithDifferentLogIdx.LogIndex + 1
inputs := shared_behaviors.CreateBehaviorInputs{ inputs := shared_behaviors.CreateBehaviorInputs{
CheckedHeaderColumnName: "pit_file_debt_ceiling_checked", CheckedHeaderColumnName: constants.PitFileDebtCeilingChecked,
LogEventTableName: "maker.pit_file_debt_ceiling", LogEventTableName: "maker.pit_file_debt_ceiling",
TestModel: test_data.PitFileDebtCeilingModel, TestModel: test_data.PitFileDebtCeilingModel,
ModelWithDifferentLogIdx: modelWithDifferentLogIdx, ModelWithDifferentLogIdx: modelWithDifferentLogIdx,
@ -74,7 +75,7 @@ var _ = Describe("Pit file debt ceiling repository", func() {
Describe("MarkHeaderChecked", func() { Describe("MarkHeaderChecked", func() {
inputs := shared_behaviors.MarkedHeaderCheckedBehaviorInputs{ inputs := shared_behaviors.MarkedHeaderCheckedBehaviorInputs{
CheckedHeaderColumnName: "pit_file_debt_ceiling_checked", CheckedHeaderColumnName: constants.PitFileDebtCeilingChecked,
Repository: &pitFileDebtCeilingRepository, Repository: &pitFileDebtCeilingRepository,
} }

View File

@ -18,6 +18,8 @@ import (
"fmt" "fmt"
"github.com/vulcanize/vulcanizedb/pkg/core" "github.com/vulcanize/vulcanizedb/pkg/core"
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
) )
type PitFileIlkRepository struct { type PitFileIlkRepository struct {
@ -47,10 +49,8 @@ func (repository PitFileIlkRepository) Create(headerID int64, models []interface
return err return err
} }
} }
_, err = tx.Exec(`INSERT INTO public.checked_headers (header_id, pit_file_ilk_checked)
VALUES ($1, $2) err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.PitFileIlkChecked)
ON CONFLICT (header_id) DO
UPDATE SET pit_file_ilk_checked = $2`, headerID, true)
if err != nil { if err != nil {
tx.Rollback() tx.Rollback()
return err return err
@ -59,28 +59,11 @@ func (repository PitFileIlkRepository) Create(headerID int64, models []interface
} }
func (repository PitFileIlkRepository) MarkHeaderChecked(headerID int64) error { func (repository PitFileIlkRepository) MarkHeaderChecked(headerID int64) error {
_, err := repository.db.Exec(`INSERT INTO public.checked_headers (header_id, pit_file_ilk_checked) return shared.MarkHeaderChecked(headerID, repository.db, constants.PitFileIlkChecked)
VALUES ($1, $2)
ON CONFLICT (header_id) DO
UPDATE SET pit_file_ilk_checked = $2`, headerID, true)
return err
} }
func (repository PitFileIlkRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { func (repository PitFileIlkRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) {
var result []core.Header return shared.MissingHeaders(startingBlockNumber, endingBlockNumber, repository.db, constants.PitFileIlkChecked)
err := repository.db.Select(
&result,
`SELECT headers.id, headers.block_number FROM headers
LEFT JOIN checked_headers on headers.id = header_id
WHERE (header_id ISNULL OR pit_file_ilk_checked IS FALSE)
AND headers.block_number >= $1
AND headers.block_number <= $2
AND headers.eth_node_fingerprint = $3`,
startingBlockNumber,
endingBlockNumber,
repository.db.Node.ID,
)
return result, err
} }
func (repository *PitFileIlkRepository) SetDB(db *postgres.DB) { func (repository *PitFileIlkRepository) SetDB(db *postgres.DB) {

View File

@ -22,6 +22,7 @@ import (
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories"
"github.com/vulcanize/vulcanizedb/pkg/fakes" "github.com/vulcanize/vulcanizedb/pkg/fakes"
"github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file/ilk" "github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file/ilk"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/shared_behaviors" "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/shared_behaviors"
"github.com/vulcanize/vulcanizedb/test_config" "github.com/vulcanize/vulcanizedb/test_config"
@ -46,7 +47,7 @@ var _ = Describe("Pit file ilk repository", func() {
modelWithDifferentLogIdx := test_data.PitFileIlkModel modelWithDifferentLogIdx := test_data.PitFileIlkModel
modelWithDifferentLogIdx.LogIndex = modelWithDifferentLogIdx.LogIndex + 1 modelWithDifferentLogIdx.LogIndex = modelWithDifferentLogIdx.LogIndex + 1
inputs := shared_behaviors.CreateBehaviorInputs{ inputs := shared_behaviors.CreateBehaviorInputs{
CheckedHeaderColumnName: "pit_file_ilk_checked", CheckedHeaderColumnName: constants.PitFileIlkChecked,
LogEventTableName: "maker.pit_file_ilk", LogEventTableName: "maker.pit_file_ilk",
TestModel: test_data.PitFileIlkModel, TestModel: test_data.PitFileIlkModel,
ModelWithDifferentLogIdx: modelWithDifferentLogIdx, ModelWithDifferentLogIdx: modelWithDifferentLogIdx,
@ -75,7 +76,7 @@ var _ = Describe("Pit file ilk repository", func() {
Describe("MarkHeaderChecked", func() { Describe("MarkHeaderChecked", func() {
inputs := shared_behaviors.MarkedHeaderCheckedBehaviorInputs{ inputs := shared_behaviors.MarkedHeaderCheckedBehaviorInputs{
CheckedHeaderColumnName: "pit_file_ilk_checked", CheckedHeaderColumnName: constants.PitFileIlkChecked,
Repository: &pitFileIlkRepository, Repository: &pitFileIlkRepository,
} }

View File

@ -18,6 +18,8 @@ import (
"fmt" "fmt"
"github.com/vulcanize/vulcanizedb/pkg/core" "github.com/vulcanize/vulcanizedb/pkg/core"
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
) )
type PitFileStabilityFeeRepository struct { type PitFileStabilityFeeRepository struct {
@ -49,11 +51,7 @@ func (repository PitFileStabilityFeeRepository) Create(headerID int64, models []
} }
} }
_, err = tx.Exec(`INSERT INTO public.checked_headers (header_id, pit_file_stability_fee_checked) err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.PitFileStabilityFeeChecked)
VALUES ($1, $2)
ON CONFLICT (header_id) DO
UPDATE SET pit_file_stability_fee_checked = $2`, headerID, true)
if err != nil { if err != nil {
tx.Rollback() tx.Rollback()
return err return err
@ -63,28 +61,11 @@ func (repository PitFileStabilityFeeRepository) Create(headerID int64, models []
} }
func (repository PitFileStabilityFeeRepository) MarkHeaderChecked(headerID int64) error { func (repository PitFileStabilityFeeRepository) MarkHeaderChecked(headerID int64) error {
_, err := repository.db.Exec(`INSERT INTO public.checked_headers (header_id, pit_file_stability_fee_checked) return shared.MarkHeaderChecked(headerID, repository.db, constants.PitFileStabilityFeeChecked)
VALUES ($1, $2)
ON CONFLICT (header_id) DO
UPDATE SET pit_file_stability_fee_checked = $2`, headerID, true)
return err
} }
func (repository PitFileStabilityFeeRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { func (repository PitFileStabilityFeeRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) {
var result []core.Header return shared.MissingHeaders(startingBlockNumber, endingBlockNumber, repository.db, constants.PitFileStabilityFeeChecked)
err := repository.db.Select(
&result,
`SELECT headers.id, headers.block_number FROM headers
LEFT JOIN checked_headers on headers.id = header_id
WHERE (header_id ISNULL OR pit_file_stability_fee_checked IS FALSE)
AND headers.block_number >= $1
AND headers.block_number <= $2
AND headers.eth_node_fingerprint = $3`,
startingBlockNumber,
endingBlockNumber,
repository.db.Node.ID,
)
return result, err
} }
func (repository *PitFileStabilityFeeRepository) SetDB(db *postgres.DB) { func (repository *PitFileStabilityFeeRepository) SetDB(db *postgres.DB) {

View File

@ -22,6 +22,7 @@ import (
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories"
"github.com/vulcanize/vulcanizedb/pkg/fakes" "github.com/vulcanize/vulcanizedb/pkg/fakes"
"github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file/stability_fee" "github.com/vulcanize/vulcanizedb/pkg/transformers/pit_file/stability_fee"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/shared_behaviors" "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/shared_behaviors"
"github.com/vulcanize/vulcanizedb/test_config" "github.com/vulcanize/vulcanizedb/test_config"
@ -46,7 +47,7 @@ var _ = Describe("Pit file stability fee repository", func() {
modelWithDifferentLogIdx := test_data.PitFileStabilityFeeModel modelWithDifferentLogIdx := test_data.PitFileStabilityFeeModel
modelWithDifferentLogIdx.LogIndex = modelWithDifferentLogIdx.LogIndex + 1 modelWithDifferentLogIdx.LogIndex = modelWithDifferentLogIdx.LogIndex + 1
inputs := shared_behaviors.CreateBehaviorInputs{ inputs := shared_behaviors.CreateBehaviorInputs{
CheckedHeaderColumnName: "pit_file_stability_fee_checked", CheckedHeaderColumnName: constants.PitFileStabilityFeeChecked,
LogEventTableName: "maker.pit_file_stability_fee", LogEventTableName: "maker.pit_file_stability_fee",
TestModel: test_data.PitFileStabilityFeeModel, TestModel: test_data.PitFileStabilityFeeModel,
ModelWithDifferentLogIdx: modelWithDifferentLogIdx, ModelWithDifferentLogIdx: modelWithDifferentLogIdx,
@ -74,7 +75,7 @@ var _ = Describe("Pit file stability fee repository", func() {
Describe("MarkHeaderChecked", func() { Describe("MarkHeaderChecked", func() {
inputs := shared_behaviors.MarkedHeaderCheckedBehaviorInputs{ inputs := shared_behaviors.MarkedHeaderCheckedBehaviorInputs{
CheckedHeaderColumnName: "pit_file_stability_fee_checked", CheckedHeaderColumnName: constants.PitFileStabilityFeeChecked,
Repository: &pitFileStabilityFeeRepository, Repository: &pitFileStabilityFeeRepository,
} }

View File

@ -18,6 +18,8 @@ import (
"fmt" "fmt"
"github.com/vulcanize/vulcanizedb/pkg/core" "github.com/vulcanize/vulcanizedb/pkg/core"
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
) )
type PriceFeedRepository struct { type PriceFeedRepository struct {
@ -43,10 +45,8 @@ func (repository PriceFeedRepository) Create(headerID int64, models []interface{
return err return err
} }
} }
_, err = tx.Exec(`INSERT INTO public.checked_headers (header_id, price_feeds_checked)
VALUES ($1, $2) err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.PriceFeedsChecked)
ON CONFLICT (header_id) DO
UPDATE SET price_feeds_checked = $2`, headerID, true)
if err != nil { if err != nil {
tx.Rollback() tx.Rollback()
return err return err
@ -55,28 +55,11 @@ func (repository PriceFeedRepository) Create(headerID int64, models []interface{
} }
func (repository PriceFeedRepository) MarkHeaderChecked(headerID int64) error { func (repository PriceFeedRepository) MarkHeaderChecked(headerID int64) error {
_, err := repository.db.Exec(`INSERT INTO public.checked_headers (header_id, price_feeds_checked) return shared.MarkHeaderChecked(headerID, repository.db, constants.PriceFeedsChecked)
VALUES ($1, $2)
ON CONFLICT (header_id) DO
UPDATE SET price_feeds_checked = $2`, headerID, true)
return err
} }
func (repository PriceFeedRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { func (repository PriceFeedRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) {
var result []core.Header return shared.MissingHeaders(startingBlockNumber, endingBlockNumber, repository.db, constants.PriceFeedsChecked)
err := repository.db.Select(
&result,
`SELECT headers.id, headers.block_number FROM headers
LEFT JOIN checked_headers on headers.id = header_id
WHERE (header_id ISNULL OR price_feeds_checked IS FALSE)
AND headers.block_number >= $1
AND headers.block_number <= $2
AND headers.eth_node_fingerprint = $3`,
startingBlockNumber,
endingBlockNumber,
repository.db.Node.ID,
)
return result, err
} }
func (repository *PriceFeedRepository) SetDB(db *postgres.DB) { func (repository *PriceFeedRepository) SetDB(db *postgres.DB) {

View File

@ -22,6 +22,7 @@ import (
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories"
"github.com/vulcanize/vulcanizedb/pkg/fakes" "github.com/vulcanize/vulcanizedb/pkg/fakes"
"github.com/vulcanize/vulcanizedb/pkg/transformers/price_feeds" "github.com/vulcanize/vulcanizedb/pkg/transformers/price_feeds"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/shared_behaviors" "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/shared_behaviors"
"github.com/vulcanize/vulcanizedb/test_config" "github.com/vulcanize/vulcanizedb/test_config"
@ -46,7 +47,7 @@ var _ = Describe("Price feeds repository", func() {
modelWithDifferentLogIdx := test_data.PriceFeedModel modelWithDifferentLogIdx := test_data.PriceFeedModel
modelWithDifferentLogIdx.LogIndex = modelWithDifferentLogIdx.LogIndex + 1 modelWithDifferentLogIdx.LogIndex = modelWithDifferentLogIdx.LogIndex + 1
inputs := shared_behaviors.CreateBehaviorInputs{ inputs := shared_behaviors.CreateBehaviorInputs{
CheckedHeaderColumnName: "price_feeds_checked", CheckedHeaderColumnName: constants.PriceFeedsChecked,
LogEventTableName: "maker.price_feeds", LogEventTableName: "maker.price_feeds",
TestModel: test_data.PriceFeedModel, TestModel: test_data.PriceFeedModel,
ModelWithDifferentLogIdx: modelWithDifferentLogIdx, ModelWithDifferentLogIdx: modelWithDifferentLogIdx,
@ -75,7 +76,7 @@ var _ = Describe("Price feeds repository", func() {
Describe("MarkHeaderChecked", func() { Describe("MarkHeaderChecked", func() {
inputs := shared_behaviors.MarkedHeaderCheckedBehaviorInputs{ inputs := shared_behaviors.MarkedHeaderCheckedBehaviorInputs{
CheckedHeaderColumnName: "price_feeds_checked", CheckedHeaderColumnName: constants.PriceFeedsChecked,
Repository: &priceFeedRepository, Repository: &priceFeedRepository,
} }

View File

@ -0,0 +1,19 @@
package constants
var (
CatFileChopLumpChecked = "cat_file_chop_lump_checked"
CatFileFlipChecked = "cat_file_flip_checked"
CatFilePitVowChecked = "cat_file_pit_vow_checked"
DealChecked = "deal_checked"
DentChecked = "dent_checked"
DripDripChecked = "drip_drip_checked"
DripFileIlkChecked = "drip_file_ilk_checked"
DripFileRepoChecked = "drip_file_repo_checked"
DripFileVowChecked = "drip_file_vow_checked"
FlapKickChecked = "flap_kick_checked"
PitFileDebtCeilingChecked = "pit_file_debt_ceiling_checked"
PitFileIlkChecked = "pit_file_ilk_checked"
PitFileStabilityFeeChecked = "pit_file_stability_fee_checked"
PriceFeedsChecked = "price_feeds_checked"
TendChecked = "tend_checked"
)

View File

@ -0,0 +1,40 @@
package shared
import (
"database/sql"
"github.com/vulcanize/vulcanizedb/pkg/core"
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
)
func MarkHeaderChecked(headerID int64, db *postgres.DB, checkedHeadersColumn string) error {
_, err := db.Exec(`INSERT INTO public.checked_headers (header_id, `+checkedHeadersColumn+`)
VALUES ($1, $2)
ON CONFLICT (header_id) DO
UPDATE SET `+checkedHeadersColumn+` = $2`, headerID, true)
return err
}
func MarkHeaderCheckedInTransaction(headerID int64, tx *sql.Tx, checkedHeadersColumn string) error {
_, err := tx.Exec(`INSERT INTO public.checked_headers (header_id, `+checkedHeadersColumn+`)
VALUES ($1, $2)
ON CONFLICT (header_id) DO
UPDATE SET `+checkedHeadersColumn+` = $2`, headerID, true)
return err
}
func MissingHeaders(startingBlockNumber, endingBlockNumber int64, db *postgres.DB, checkedHeadersColumn string) ([]core.Header, error) {
var result []core.Header
err := db.Select(
&result,
`SELECT headers.id, headers.block_number FROM headers
LEFT JOIN checked_headers on headers.id = header_id
WHERE (header_id ISNULL OR `+checkedHeadersColumn+` IS FALSE)
AND headers.block_number >= $1
AND headers.block_number <= $2
AND headers.eth_node_fingerprint = $3`,
startingBlockNumber,
endingBlockNumber,
db.Node.ID,
)
return result, err
}

View File

@ -18,6 +18,8 @@ import (
"fmt" "fmt"
"github.com/vulcanize/vulcanizedb/pkg/core" "github.com/vulcanize/vulcanizedb/pkg/core"
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
) )
type TendRepository struct { type TendRepository struct {
@ -48,11 +50,8 @@ func (repository TendRepository) Create(headerId int64, models []interface{}) er
return err return err
} }
} }
_, err = tx.Exec(`INSERT INTO public.checked_headers (header_id, tend_checked)
VALUES ($1, $2)
ON CONFLICT (header_id) DO
UPDATE SET tend_checked = $2`, headerId, true)
err = shared.MarkHeaderCheckedInTransaction(headerId, tx, constants.TendChecked)
if err != nil { if err != nil {
tx.Rollback() tx.Rollback()
return err return err
@ -61,29 +60,11 @@ func (repository TendRepository) Create(headerId int64, models []interface{}) er
} }
func (repository TendRepository) MarkHeaderChecked(headerId int64) error { func (repository TendRepository) MarkHeaderChecked(headerId int64) error {
_, err := repository.db.Exec(`INSERT INTO public.checked_headers (header_id, tend_checked) return shared.MarkHeaderChecked(headerId, repository.db, constants.TendChecked)
VALUES ($1, $2)
ON CONFLICT (header_id) DO
UPDATE SET tend_checked = $2`, headerId, true)
return err
} }
func (repository TendRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) { func (repository TendRepository) MissingHeaders(startingBlockNumber, endingBlockNumber int64) ([]core.Header, error) {
var result []core.Header return shared.MissingHeaders(startingBlockNumber, endingBlockNumber, repository.db, constants.TendChecked)
err := repository.db.Select(
&result,
`SELECT headers.id, headers.block_number FROM headers
LEFT JOIN checked_headers on headers.id = header_id
WHERE (header_id ISNULL OR tend_checked IS FALSE)
AND headers.block_number >= $1
AND headers.block_number <= $2
AND headers.eth_node_fingerprint = $3`,
startingBlockNumber,
endingBlockNumber,
repository.db.Node.ID,
)
return result, err
} }
func (repository *TendRepository) SetDB(db *postgres.DB) { func (repository *TendRepository) SetDB(db *postgres.DB) {

View File

@ -21,6 +21,7 @@ import (
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories"
"github.com/vulcanize/vulcanizedb/pkg/fakes" "github.com/vulcanize/vulcanizedb/pkg/fakes"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
"github.com/vulcanize/vulcanizedb/pkg/transformers/tend" "github.com/vulcanize/vulcanizedb/pkg/transformers/tend"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/shared_behaviors" "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/shared_behaviors"
@ -46,7 +47,7 @@ var _ = Describe("TendRepository", func() {
modelWithDifferentLogIdx := test_data.TendModel modelWithDifferentLogIdx := test_data.TendModel
modelWithDifferentLogIdx.LogIndex = modelWithDifferentLogIdx.LogIndex + 1 modelWithDifferentLogIdx.LogIndex = modelWithDifferentLogIdx.LogIndex + 1
inputs := shared_behaviors.CreateBehaviorInputs{ inputs := shared_behaviors.CreateBehaviorInputs{
CheckedHeaderColumnName: "tend_checked", CheckedHeaderColumnName: constants.TendChecked,
LogEventTableName: "maker.tend", LogEventTableName: "maker.tend",
TestModel: test_data.TendModel, TestModel: test_data.TendModel,
ModelWithDifferentLogIdx: modelWithDifferentLogIdx, ModelWithDifferentLogIdx: modelWithDifferentLogIdx,
@ -84,7 +85,7 @@ var _ = Describe("TendRepository", func() {
Describe("MarkHeaderChecked", func() { Describe("MarkHeaderChecked", func() {
inputs := shared_behaviors.MarkedHeaderCheckedBehaviorInputs{ inputs := shared_behaviors.MarkedHeaderCheckedBehaviorInputs{
CheckedHeaderColumnName: "tend_checked", CheckedHeaderColumnName: constants.TendChecked,
Repository: &tendRepository, Repository: &tendRepository,
} }