diff --git a/pkg/transformers/bite/repository.go b/pkg/transformers/bite/repository.go index 1e3d860b..a816bfc2 100644 --- a/pkg/transformers/bite/repository.go +++ b/pkg/transformers/bite/repository.go @@ -16,6 +16,7 @@ package bite import ( "fmt" + log "github.com/sirupsen/logrus" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" @@ -30,32 +31,41 @@ func (repository *BiteRepository) SetDB(db *postgres.DB) { } func (repository BiteRepository) Create(headerID int64, models []interface{}) error { - tx, err := repository.db.Begin() - if err != nil { - return err + tx, dBaseErr := repository.db.Begin() + if dBaseErr != nil { + return dBaseErr } for _, model := range models { biteModel, ok := model.(BiteModel) if !ok { - tx.Rollback() + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } return fmt.Errorf("model of type %T, not %T", model, BiteModel{}) } - _, err = tx.Exec( + _, execErr := tx.Exec( `INSERT into maker.bite (header_id, ilk, urn, ink, art, iart, tab, nflip, log_idx, tx_idx, raw_log) VALUES($1, $2, $3, $4::NUMERIC, $5::NUMERIC, $6::NUMERIC, $7::NUMERIC, $8::NUMERIC, $9, $10, $11)`, headerID, biteModel.Ilk, biteModel.Urn, biteModel.Ink, biteModel.Art, biteModel.IArt, biteModel.Tab, biteModel.NFlip, biteModel.LogIndex, biteModel.TransactionIndex, biteModel.Raw, ) - if err != nil { - tx.Rollback() - return err + if execErr != nil { + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } + return execErr } } - err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.BiteChecked) - if err != nil { - tx.Rollback() - return err + checkHeaderErr := shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.BiteChecked) + if checkHeaderErr != nil { + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } + return checkHeaderErr } return tx.Commit() diff --git a/pkg/transformers/cat_file/chop_lump/repository.go b/pkg/transformers/cat_file/chop_lump/repository.go index 9dff41f7..32bd20fd 100644 --- a/pkg/transformers/cat_file/chop_lump/repository.go +++ b/pkg/transformers/cat_file/chop_lump/repository.go @@ -16,6 +16,7 @@ package chop_lump import ( "fmt" + log "github.com/sirupsen/logrus" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" @@ -26,33 +27,42 @@ type CatFileChopLumpRepository struct { } func (repository CatFileChopLumpRepository) Create(headerID int64, models []interface{}) error { - tx, err := repository.db.Begin() - if err != nil { - return err + tx, dBaseErr := repository.db.Begin() + if dBaseErr != nil { + return dBaseErr } for _, model := range models { chopLump, ok := model.(CatFileChopLumpModel) if !ok { - tx.Rollback() + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } return fmt.Errorf("model of type %T, not %T", model, CatFileChopLumpModel{}) } - _, err = tx.Exec( + _, execErr := tx.Exec( `INSERT into maker.cat_file_chop_lump (header_id, ilk, what, data, tx_idx, log_idx, raw_log) VALUES($1, $2, $3, $4::NUMERIC, $5, $6, $7)`, headerID, chopLump.Ilk, chopLump.What, chopLump.Data, chopLump.TransactionIndex, chopLump.LogIndex, chopLump.Raw, ) - if err != nil { - tx.Rollback() - return err + if execErr != nil { + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } + return execErr } } - err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.CatFileChopLumpChecked) - if err != nil { - tx.Rollback() - return err + checkHeaderErr := shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.CatFileChopLumpChecked) + if checkHeaderErr != nil { + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } + return checkHeaderErr } return tx.Commit() } diff --git a/pkg/transformers/cat_file/flip/repository.go b/pkg/transformers/cat_file/flip/repository.go index a07ca207..0cf9ab16 100644 --- a/pkg/transformers/cat_file/flip/repository.go +++ b/pkg/transformers/cat_file/flip/repository.go @@ -16,6 +16,7 @@ package flip import ( "fmt" + log "github.com/sirupsen/logrus" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" @@ -26,32 +27,41 @@ type CatFileFlipRepository struct { } func (repository CatFileFlipRepository) Create(headerID int64, models []interface{}) error { - tx, err := repository.db.Begin() - if err != nil { - return err + tx, dBaseErr := repository.db.Begin() + if dBaseErr != nil { + return dBaseErr } for _, model := range models { flip, ok := model.(CatFileFlipModel) if !ok { - tx.Rollback() + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } return fmt.Errorf("model of type %T, not %T", model, CatFileFlipModel{}) } - _, err = repository.db.Exec( + _, execErr := repository.db.Exec( `INSERT into maker.cat_file_flip (header_id, ilk, what, flip, tx_idx, log_idx, raw_log) VALUES($1, $2, $3, $4, $5, $6, $7)`, headerID, flip.Ilk, flip.What, flip.Flip, flip.TransactionIndex, flip.LogIndex, flip.Raw, ) - if err != nil { - tx.Rollback() - return err + if execErr != nil { + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } + return execErr } } - err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.CatFileFlipChecked) - if err != nil { - tx.Rollback() - return err + checkHeaderErr := shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.CatFileFlipChecked) + if checkHeaderErr != nil { + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } + return checkHeaderErr } return tx.Commit() } diff --git a/pkg/transformers/cat_file/pit_vow/repository.go b/pkg/transformers/cat_file/pit_vow/repository.go index 861dc2a8..1ca0c048 100644 --- a/pkg/transformers/cat_file/pit_vow/repository.go +++ b/pkg/transformers/cat_file/pit_vow/repository.go @@ -16,6 +16,7 @@ package pit_vow import ( "fmt" + log "github.com/sirupsen/logrus" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" @@ -26,32 +27,41 @@ type CatFilePitVowRepository struct { } func (repository CatFilePitVowRepository) Create(headerID int64, models []interface{}) error { - tx, err := repository.db.Begin() - if err != nil { - return err + tx, dBaseErr := repository.db.Begin() + if dBaseErr != nil { + return dBaseErr } for _, model := range models { vow, ok := model.(CatFilePitVowModel) if !ok { - tx.Rollback() + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } return fmt.Errorf("model of type %T, not %T", model, CatFilePitVowModel{}) } - _, err = repository.db.Exec( + _, execErr := repository.db.Exec( `INSERT into maker.cat_file_pit_vow (header_id, what, data, tx_idx, log_idx, raw_log) VALUES($1, $2, $3, $4, $5, $6)`, headerID, vow.What, vow.Data, vow.TransactionIndex, vow.LogIndex, vow.Raw, ) - if err != nil { - tx.Rollback() - return err + if execErr != nil { + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } + return execErr } } - err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.CatFilePitVowChecked) - if err != nil { - tx.Rollback() - return err + checkHeaderErr := shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.CatFilePitVowChecked) + if checkHeaderErr != nil { + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } + return checkHeaderErr } return tx.Commit() } diff --git a/pkg/transformers/deal/repository.go b/pkg/transformers/deal/repository.go index 06f23230..03e229c7 100644 --- a/pkg/transformers/deal/repository.go +++ b/pkg/transformers/deal/repository.go @@ -16,6 +16,7 @@ package deal import ( "fmt" + log "github.com/sirupsen/logrus" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" @@ -26,33 +27,42 @@ type DealRepository struct { } func (repository DealRepository) Create(headerID int64, models []interface{}) error { - tx, err := repository.db.Begin() - if err != nil { - return err + tx, dBaseErr := repository.db.Begin() + if dBaseErr != nil { + return dBaseErr } for _, model := range models { dealModel, ok := model.(DealModel) if !ok { - tx.Rollback() + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } return fmt.Errorf("model of type %T, not %T", model, DealModel{}) } - _, err = tx.Exec( + _, execErr := tx.Exec( `INSERT into maker.deal (header_id, bid_id, contract_address, log_idx, tx_idx, raw_log) VALUES($1, $2, $3, $4, $5, $6)`, headerID, dealModel.BidId, dealModel.ContractAddress, dealModel.LogIndex, dealModel.TransactionIndex, dealModel.Raw, ) - if err != nil { - tx.Rollback() - return err + if execErr != nil { + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } + return execErr } } - err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.DealChecked) - if err != nil { - tx.Rollback() - return err + checkHeaderErr := shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.DealChecked) + if checkHeaderErr != nil { + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } + return checkHeaderErr } return tx.Commit() } diff --git a/pkg/transformers/dent/repository.go b/pkg/transformers/dent/repository.go index 0ff5370b..018711da 100644 --- a/pkg/transformers/dent/repository.go +++ b/pkg/transformers/dent/repository.go @@ -16,6 +16,7 @@ package dent import ( "fmt" + log "github.com/sirupsen/logrus" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" @@ -26,38 +27,51 @@ type DentRepository struct { } func (repository DentRepository) Create(headerID int64, models []interface{}) error { - tx, err := repository.db.Begin() - if err != nil { - return err + tx, dBaseErr := repository.db.Begin() + if dBaseErr != nil { + return dBaseErr } - tic, err := shared.GetTicInTx(headerID, tx) - if err != nil { - return err + tic, getTicErr := shared.GetTicInTx(headerID, tx) + if getTicErr != nil { + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } + return getTicErr } for _, model := range models { dent, ok := model.(DentModel) if !ok { - tx.Rollback() + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } return fmt.Errorf("model of type %T, not %T", model, DentModel{}) } - _, err = tx.Exec( + _, execErr := tx.Exec( `INSERT into maker.dent (header_id, bid_id, lot, bid, guy, tic, log_idx, tx_idx, raw_log) VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9)`, headerID, dent.BidId, dent.Lot, dent.Bid, dent.Guy, tic, dent.LogIndex, dent.TransactionIndex, dent.Raw, ) - if err != nil { - tx.Rollback() - return err + if execErr != nil { + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } + return execErr } } - err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.DentChecked) - if err != nil { - tx.Rollback() - return err + checkHeaderErr := shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.DentChecked) + if checkHeaderErr != nil { + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } + return checkHeaderErr } return tx.Commit() } diff --git a/pkg/transformers/drip_drip/repository.go b/pkg/transformers/drip_drip/repository.go index edb1208a..e28a3748 100644 --- a/pkg/transformers/drip_drip/repository.go +++ b/pkg/transformers/drip_drip/repository.go @@ -16,6 +16,7 @@ package drip_drip import ( "fmt" + log "github.com/sirupsen/logrus" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" @@ -26,32 +27,41 @@ type DripDripRepository struct { } func (repository DripDripRepository) Create(headerID int64, models []interface{}) error { - tx, err := repository.db.Begin() - if err != nil { - return err + tx, dBaseErr := repository.db.Begin() + if dBaseErr != nil { + return dBaseErr } for _, model := range models { dripDrip, ok := model.(DripDripModel) if !ok { - tx.Rollback() + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } return fmt.Errorf("model of type %T, not %T", model, DripDripModel{}) } - _, err = tx.Exec( + _, execErr := tx.Exec( `INSERT into maker.drip_drip (header_id, ilk, log_idx, tx_idx, raw_log) VALUES($1, $2, $3, $4, $5)`, headerID, dripDrip.Ilk, dripDrip.LogIndex, dripDrip.TransactionIndex, dripDrip.Raw, ) - if err != nil { - tx.Rollback() - return err + if execErr != nil { + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } + return execErr } } - err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.DripDripChecked) - if err != nil { - tx.Rollback() - return err + checkHeaderErr := shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.DripDripChecked) + if checkHeaderErr != nil { + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } + return checkHeaderErr } return tx.Commit() } diff --git a/pkg/transformers/drip_file/ilk/repository.go b/pkg/transformers/drip_file/ilk/repository.go index 117a28fd..c986a3d0 100644 --- a/pkg/transformers/drip_file/ilk/repository.go +++ b/pkg/transformers/drip_file/ilk/repository.go @@ -16,6 +16,7 @@ package ilk import ( "fmt" + log "github.com/sirupsen/logrus" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" @@ -26,34 +27,43 @@ type DripFileIlkRepository struct { } func (repository DripFileIlkRepository) Create(headerID int64, models []interface{}) error { - tx, err := repository.db.Begin() - if err != nil { - return err + tx, dBaseErr := repository.db.Begin() + if dBaseErr != nil { + return dBaseErr } for _, model := range models { ilk, ok := model.(DripFileIlkModel) if !ok { - tx.Rollback() + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } return fmt.Errorf("model of type %T, not %T", model, DripFileIlkModel{}) } - _, err = tx.Exec( + _, execErr := 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, ilk.Ilk, ilk.Vow, ilk.Tax, ilk.LogIndex, ilk.TransactionIndex, ilk.Raw, ) - if err != nil { - tx.Rollback() - return err + if execErr != nil { + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } + return execErr } } - err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.DripFileIlkChecked) - if err != nil { - tx.Rollback() - return err + checkHeaderErr := shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.DripFileIlkChecked) + if checkHeaderErr != nil { + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } + return checkHeaderErr } return tx.Commit() diff --git a/pkg/transformers/drip_file/repo/repository.go b/pkg/transformers/drip_file/repo/repository.go index dc9589a7..fab8ade4 100644 --- a/pkg/transformers/drip_file/repo/repository.go +++ b/pkg/transformers/drip_file/repo/repository.go @@ -16,6 +16,7 @@ package repo import ( "fmt" + log "github.com/sirupsen/logrus" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" @@ -26,34 +27,43 @@ type DripFileRepoRepository struct { } func (repository DripFileRepoRepository) Create(headerID int64, models []interface{}) error { - tx, err := repository.db.Begin() - if err != nil { - return err + tx, dBaseErr := repository.db.Begin() + if dBaseErr != nil { + return dBaseErr } for _, model := range models { repo, ok := model.(DripFileRepoModel) if !ok { - tx.Rollback() + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } return fmt.Errorf("model of type %T, not %T", model, DripFileRepoModel{}) } - _, err = tx.Exec( + _, execErr := 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, repo.What, repo.Data, repo.LogIndex, repo.TransactionIndex, repo.Raw, ) - if err != nil { - tx.Rollback() - return err + if execErr != nil { + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } + return execErr } } - err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.DripFileRepoChecked) - if err != nil { - tx.Rollback() - return err + checkHeaderErr := shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.DripFileRepoChecked) + if checkHeaderErr != nil { + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } + return checkHeaderErr } return tx.Commit() diff --git a/pkg/transformers/drip_file/vow/repository.go b/pkg/transformers/drip_file/vow/repository.go index aa23bea8..c6b1a848 100644 --- a/pkg/transformers/drip_file/vow/repository.go +++ b/pkg/transformers/drip_file/vow/repository.go @@ -16,6 +16,7 @@ package vow import ( "fmt" + log "github.com/sirupsen/logrus" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" @@ -26,33 +27,42 @@ type DripFileVowRepository struct { } func (repository DripFileVowRepository) Create(headerID int64, models []interface{}) error { - tx, err := repository.db.Begin() - if err != nil { - return err + tx, dBaseErr := repository.db.Begin() + if dBaseErr != nil { + return dBaseErr } for _, model := range models { vow, ok := model.(DripFileVowModel) if !ok { - tx.Rollback() + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } return fmt.Errorf("model of type %T, not %T", model, DripFileVowModel{}) } - _, err = tx.Exec( + _, execErr := 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, vow.What, vow.Data, vow.LogIndex, vow.TransactionIndex, vow.Raw, ) - if err != nil { - tx.Rollback() - return err + if execErr != nil { + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } + return execErr } } - err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.DripFileVowChecked) - if err != nil { - tx.Rollback() - return err + checkHeaderErr := shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.DripFileVowChecked) + if checkHeaderErr != nil { + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } + return checkHeaderErr } return tx.Commit() diff --git a/pkg/transformers/flap_kick/repository.go b/pkg/transformers/flap_kick/repository.go index f9f11c7a..ed2b95ae 100644 --- a/pkg/transformers/flap_kick/repository.go +++ b/pkg/transformers/flap_kick/repository.go @@ -16,6 +16,7 @@ package flap_kick import ( "fmt" + log "github.com/sirupsen/logrus" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" @@ -26,9 +27,9 @@ type FlapKickRepository struct { } func (repository *FlapKickRepository) Create(headerID int64, models []interface{}) error { - tx, err := repository.db.Begin() - if err != nil { - return err + tx, dBaseErr := repository.db.Begin() + if dBaseErr != nil { + return dBaseErr } for _, model := range models { flapKickModel, ok := model.(FlapKickModel) @@ -36,21 +37,27 @@ func (repository *FlapKickRepository) Create(headerID int64, models []interface{ return fmt.Errorf("model of type %T, not %T", model, FlapKickModel{}) } - _, err = tx.Exec( + _, execErr := tx.Exec( `INSERT into maker.flap_kick (header_id, bid_id, lot, bid, gal, "end", tx_idx, log_idx, raw_log) VALUES($1, $2::NUMERIC, $3::NUMERIC, $4::NUMERIC, $5, $6, $7, $8, $9)`, headerID, flapKickModel.BidId, flapKickModel.Lot, flapKickModel.Bid, flapKickModel.Gal, flapKickModel.End, flapKickModel.TransactionIndex, flapKickModel.LogIndex, flapKickModel.Raw, ) - if err != nil { - tx.Rollback() - return err + if execErr != nil { + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } + return execErr } } - err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.FlapKickChecked) - if err != nil { - tx.Rollback() - return err + checkHeaderErr := shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.FlapKickChecked) + if checkHeaderErr != nil { + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } + return checkHeaderErr } return tx.Commit() } diff --git a/pkg/transformers/flip_kick/repository.go b/pkg/transformers/flip_kick/repository.go index db8a8d01..f4073b87 100644 --- a/pkg/transformers/flip_kick/repository.go +++ b/pkg/transformers/flip_kick/repository.go @@ -16,6 +16,7 @@ package flip_kick import ( "fmt" + log "github.com/sirupsen/logrus" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" @@ -27,9 +28,9 @@ type FlipKickRepository struct { } func (repository FlipKickRepository) Create(headerID int64, models []interface{}) error { - tx, err := repository.db.Begin() - if err != nil { - return err + tx, dBaseErr := repository.db.Begin() + if dBaseErr != nil { + return dBaseErr } for _, model := range models { flipKickModel, ok := model.(FlipKickModel) @@ -37,20 +38,26 @@ func (repository FlipKickRepository) Create(headerID int64, models []interface{} return fmt.Errorf("model of type %T, not %T", model, FlipKickModel{}) } - _, err = tx.Exec( + _, execErr := tx.Exec( `INSERT into maker.flip_kick (header_id, bid_id, lot, bid, gal, "end", urn, tab, tx_idx, log_idx, raw_log) VALUES($1, $2::NUMERIC, $3::NUMERIC, $4::NUMERIC, $5, $6, $7, $8::NUMERIC, $9, $10, $11)`, headerID, flipKickModel.BidId, flipKickModel.Lot, flipKickModel.Bid, flipKickModel.Gal, flipKickModel.End, flipKickModel.Urn, flipKickModel.Tab, flipKickModel.TransactionIndex, flipKickModel.LogIndex, flipKickModel.Raw, ) - if err != nil { - tx.Rollback() - return err + if execErr != nil { + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } + return execErr } } - err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.FlipKickChecked) - if err != nil { - tx.Rollback() - return err + checkHeaderErr := shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.FlipKickChecked) + if checkHeaderErr != nil { + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } + return checkHeaderErr } return tx.Commit() } diff --git a/pkg/transformers/flop_kick/repository.go b/pkg/transformers/flop_kick/repository.go index 7a302c75..910f0dec 100644 --- a/pkg/transformers/flop_kick/repository.go +++ b/pkg/transformers/flop_kick/repository.go @@ -16,6 +16,7 @@ package flop_kick import ( "fmt" + log "github.com/sirupsen/logrus" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" @@ -26,9 +27,9 @@ type FlopKickRepository struct { } func (repository FlopKickRepository) Create(headerID int64, models []interface{}) error { - tx, err := repository.db.Begin() - if err != nil { - return err + tx, dBaseErr := repository.db.Begin() + if dBaseErr != nil { + return dBaseErr } for _, flopKick := range models { flopKickModel, ok := flopKick.(Model) @@ -37,21 +38,27 @@ func (repository FlopKickRepository) Create(headerID int64, models []interface{} return fmt.Errorf("model of type %T, not %T", flopKick, Model{}) } - _, err = tx.Exec( + _, execErr := tx.Exec( `INSERT into maker.flop_kick (header_id, bid_id, lot, bid, gal, "end", tx_idx, log_idx, raw_log) VALUES($1, $2::NUMERIC, $3::NUMERIC, $4::NUMERIC, $5, $6, $7, $8, $9)`, headerID, flopKickModel.BidId, flopKickModel.Lot, flopKickModel.Bid, flopKickModel.Gal, flopKickModel.End, flopKickModel.TransactionIndex, flopKickModel.LogIndex, flopKickModel.Raw, ) - if err != nil { - tx.Rollback() - return err + if execErr != nil { + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } + return execErr } } - err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.FlopKickChecked) - if err != nil { - tx.Rollback() - return err + checkHeaderErr := shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.FlopKickChecked) + if checkHeaderErr != nil { + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } + return checkHeaderErr } return tx.Commit() diff --git a/pkg/transformers/frob/repository.go b/pkg/transformers/frob/repository.go index bf6d4d08..c857013a 100644 --- a/pkg/transformers/frob/repository.go +++ b/pkg/transformers/frob/repository.go @@ -16,6 +16,7 @@ package frob import ( "fmt" + log "github.com/sirupsen/logrus" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" @@ -27,29 +28,38 @@ type FrobRepository struct { } func (repository FrobRepository) Create(headerID int64, models []interface{}) error { - tx, err := repository.db.Begin() - if err != nil { - return err + tx, dBaseErr := repository.db.Begin() + if dBaseErr != nil { + return dBaseErr } for _, model := range models { frobModel, ok := model.(FrobModel) if !ok { - tx.Rollback() + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } return fmt.Errorf("model of type %T, not %T", model, FrobModel{}) } - _, err = tx.Exec(`INSERT INTO maker.frob (header_id, art, dart, dink, iart, ilk, ink, urn, raw_log, log_idx, tx_idx) + _, execErr := tx.Exec(`INSERT INTO maker.frob (header_id, art, dart, dink, iart, ilk, ink, urn, raw_log, log_idx, tx_idx) VALUES($1, $2::NUMERIC, $3::NUMERIC, $4::NUMERIC, $5::NUMERIC, $6, $7::NUMERIC, $8, $9, $10, $11)`, headerID, frobModel.Art, frobModel.Dart, frobModel.Dink, frobModel.IArt, frobModel.Ilk, frobModel.Ink, frobModel.Urn, frobModel.Raw, frobModel.LogIndex, frobModel.TransactionIndex) - if err != nil { - tx.Rollback() - return err + if execErr != nil { + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } + return execErr } } - err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.FrobChecked) - if err != nil { - tx.Rollback() - return err + checkHeaderErr := shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.FrobChecked) + if checkHeaderErr != nil { + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } + return checkHeaderErr } return tx.Commit() } diff --git a/pkg/transformers/pit_file/debt_ceiling/repository.go b/pkg/transformers/pit_file/debt_ceiling/repository.go index 12f69fb2..f2c44c79 100644 --- a/pkg/transformers/pit_file/debt_ceiling/repository.go +++ b/pkg/transformers/pit_file/debt_ceiling/repository.go @@ -16,6 +16,7 @@ package debt_ceiling import ( "fmt" + log "github.com/sirupsen/logrus" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" @@ -26,34 +27,43 @@ type PitFileDebtCeilingRepository struct { } func (repository PitFileDebtCeilingRepository) Create(headerID int64, models []interface{}) error { - tx, err := repository.db.Begin() - if err != nil { - return err + tx, dBaseErr := repository.db.Begin() + if dBaseErr != nil { + return dBaseErr } for _, model := range models { pitFileDC, ok := model.(PitFileDebtCeilingModel) if !ok { - tx.Rollback() + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } return fmt.Errorf("model of type %T, not %T", model, PitFileDebtCeilingModel{}) } - _, err = tx.Exec( + _, execErr := tx.Exec( `INSERT into maker.pit_file_debt_ceiling (header_id, what, data, log_idx, tx_idx, raw_log) VALUES($1, $2, $3::NUMERIC, $4, $5, $6)`, headerID, pitFileDC.What, pitFileDC.Data, pitFileDC.LogIndex, pitFileDC.TransactionIndex, pitFileDC.Raw, ) - if err != nil { - tx.Rollback() - return err + if execErr != nil { + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } + return execErr } } - err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.PitFileDebtCeilingChecked) - if err != nil { - tx.Rollback() - return err + checkHeaderErr := shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.PitFileDebtCeilingChecked) + if checkHeaderErr != nil { + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } + return checkHeaderErr } return tx.Commit() diff --git a/pkg/transformers/pit_file/ilk/repository.go b/pkg/transformers/pit_file/ilk/repository.go index 9a187de7..cdb01d1b 100644 --- a/pkg/transformers/pit_file/ilk/repository.go +++ b/pkg/transformers/pit_file/ilk/repository.go @@ -16,6 +16,7 @@ package ilk import ( "fmt" + log "github.com/sirupsen/logrus" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" @@ -26,33 +27,42 @@ type PitFileIlkRepository struct { } func (repository PitFileIlkRepository) Create(headerID int64, models []interface{}) error { - tx, err := repository.db.Begin() - if err != nil { - return err + tx, dBaseErr := repository.db.Begin() + if dBaseErr != nil { + return dBaseErr } for _, model := range models { pitFileIlk, ok := model.(PitFileIlkModel) if !ok { - tx.Rollback() + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } return fmt.Errorf("model of type %T, not %T", model, PitFileIlkModel{}) } - _, err = tx.Exec( + _, execErr := tx.Exec( `INSERT into maker.pit_file_ilk (header_id, ilk, what, data, log_idx, tx_idx, raw_log) VALUES($1, $2, $3, $4::NUMERIC, $5, $6, $7)`, headerID, pitFileIlk.Ilk, pitFileIlk.What, pitFileIlk.Data, pitFileIlk.LogIndex, pitFileIlk.TransactionIndex, pitFileIlk.Raw, ) - if err != nil { - tx.Rollback() - return err + if execErr != nil { + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } + return execErr } } - err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.PitFileIlkChecked) - if err != nil { - tx.Rollback() - return err + checkHeaderErr := shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.PitFileIlkChecked) + if checkHeaderErr != nil { + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } + return checkHeaderErr } return tx.Commit() } diff --git a/pkg/transformers/price_feeds/repository.go b/pkg/transformers/price_feeds/repository.go index cbb9a012..d3056d8b 100644 --- a/pkg/transformers/price_feeds/repository.go +++ b/pkg/transformers/price_feeds/repository.go @@ -16,6 +16,7 @@ package price_feeds import ( "fmt" + log "github.com/sirupsen/logrus" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" @@ -26,29 +27,38 @@ type PriceFeedRepository struct { } func (repository PriceFeedRepository) Create(headerID int64, models []interface{}) error { - tx, err := repository.db.Begin() - if err != nil { - return err + tx, dBaseErr := repository.db.Begin() + if dBaseErr != nil { + return dBaseErr } for _, model := range models { priceUpdate, ok := model.(PriceFeedModel) if !ok { - tx.Rollback() + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } return fmt.Errorf("model of type %T, not %T", model, PriceFeedModel{}) } - _, err = tx.Exec(`INSERT INTO maker.price_feeds (block_number, header_id, medianizer_address, usd_value, log_idx, tx_idx, raw_log) + _, execErr := tx.Exec(`INSERT INTO maker.price_feeds (block_number, header_id, medianizer_address, usd_value, log_idx, tx_idx, raw_log) VALUES ($1, $2, $3, $4::NUMERIC, $5, $6, $7)`, priceUpdate.BlockNumber, headerID, priceUpdate.MedianizerAddress, priceUpdate.UsdValue, priceUpdate.LogIndex, priceUpdate.TransactionIndex, priceUpdate.Raw) - if err != nil { - tx.Rollback() - return err + if execErr != nil { + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } + return execErr } } - err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.PriceFeedsChecked) - if err != nil { - tx.Rollback() - return err + checkHeaderErr := shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.PriceFeedsChecked) + if checkHeaderErr != nil { + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } + return checkHeaderErr } return tx.Commit() } diff --git a/pkg/transformers/shared/repository.go b/pkg/transformers/shared/repository.go index 65c01c99..9ee55e8f 100644 --- a/pkg/transformers/shared/repository.go +++ b/pkg/transformers/shared/repository.go @@ -7,6 +7,7 @@ import ( "fmt" "github.com/vulcanize/vulcanizedb/pkg/core" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" + "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" ) func MarkHeaderChecked(headerID int64, db *postgres.DB, checkedHeadersColumn string) error { @@ -100,3 +101,14 @@ func CreateNotCheckedSQL(boolColumns []string) string { return result.String() } + +func GetTicInTx(headerID int64, tx *sql.Tx) (int64, error) { + var blockTimestamp int64 + err := tx.QueryRow(`SELECT block_timestamp FROM public.headers WHERE id = $1;`, headerID).Scan(&blockTimestamp) + if err != nil { + return 0, err + } + + tic := blockTimestamp + constants.TTL + return tic, nil +} diff --git a/pkg/transformers/shared/utilities.go b/pkg/transformers/shared/utilities.go index a97aef7b..073f8783 100644 --- a/pkg/transformers/shared/utilities.go +++ b/pkg/transformers/shared/utilities.go @@ -15,7 +15,6 @@ package shared import ( - "database/sql" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" "math/big" ) @@ -79,15 +78,3 @@ func convert(conversion string, value string, precision int) string { } return result.Text('f', precision) } - -// Grabs the block timestamp for an headerID, and adds the TTL constant -func GetTicInTx(headerID int64, tx *sql.Tx) (int64, error) { - var blockTimestamp int64 - err := tx.QueryRow(`SELECT block_timestamp FROM public.headers WHERE id = $1;`, headerID).Scan(&blockTimestamp) - if err != nil { - return 0, err - } - - tic := blockTimestamp + constants.TTL - return tic, nil -} diff --git a/pkg/transformers/tend/repository.go b/pkg/transformers/tend/repository.go index 17620a00..b4ea5475 100644 --- a/pkg/transformers/tend/repository.go +++ b/pkg/transformers/tend/repository.go @@ -16,6 +16,7 @@ package tend import ( "fmt" + log "github.com/sirupsen/logrus" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" @@ -26,39 +27,52 @@ type TendRepository struct { } func (repository TendRepository) Create(headerID int64, models []interface{}) error { - tx, err := repository.db.Begin() - if err != nil { - return err + tx, dBaseErr := repository.db.Begin() + if dBaseErr != nil { + return dBaseErr } - tic, err := shared.GetTicInTx(headerID, tx) - if err != nil { - return err + tic, getTicErr := shared.GetTicInTx(headerID, tx) + if getTicErr != nil { + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } + return getTicErr } for _, model := range models { tend, ok := model.(TendModel) if !ok { - tx.Rollback() + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } return fmt.Errorf("model of type %T, not %T", model, TendModel{}) } - _, err = tx.Exec( + _, execErr := tx.Exec( `INSERT into maker.tend (header_id, bid_id, lot, bid, guy, tic, log_idx, tx_idx, raw_log) VALUES($1, $2, $3::NUMERIC, $4::NUMERIC, $5, $6, $7, $8, $9)`, headerID, tend.BidId, tend.Lot, tend.Bid, tend.Guy, tic, tend.LogIndex, tend.TransactionIndex, tend.Raw, ) - if err != nil { - tx.Rollback() - return err + if execErr != nil { + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } + return execErr } } - err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.TendChecked) - if err != nil { - tx.Rollback() - return err + checkHeaderErr := shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.TendChecked) + if checkHeaderErr != nil { + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } + return checkHeaderErr } return tx.Commit() } diff --git a/pkg/transformers/vat_flux/repository.go b/pkg/transformers/vat_flux/repository.go index 2febe527..60ae66c8 100644 --- a/pkg/transformers/vat_flux/repository.go +++ b/pkg/transformers/vat_flux/repository.go @@ -16,6 +16,7 @@ package vat_flux import ( "fmt" + log "github.com/sirupsen/logrus" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" @@ -26,31 +27,40 @@ type VatFluxRepository struct { } func (repository VatFluxRepository) Create(headerID int64, models []interface{}) error { - tx, err := repository.db.Begin() - if err != nil { - return err + tx, dBaseErr := repository.db.Begin() + if dBaseErr != nil { + return dBaseErr } for _, model := range models { vatFlux, ok := model.(VatFluxModel) if !ok { - tx.Rollback() + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } return fmt.Errorf("model of type %T, not %T", model, VatFluxModel{}) } - _, err = tx.Exec(`INSERT INTO maker.vat_flux (header_id, ilk, dst, src, rad, tx_idx, log_idx, raw_log) + _, execErr := tx.Exec(`INSERT INTO maker.vat_flux (header_id, ilk, dst, src, rad, tx_idx, log_idx, raw_log) VALUES($1, $2, $3, $4, $5::NUMERIC, $6, $7, $8)`, headerID, vatFlux.Ilk, vatFlux.Dst, vatFlux.Src, vatFlux.Rad, vatFlux.TransactionIndex, vatFlux.LogIndex, vatFlux.Raw) - if err != nil { - tx.Rollback() - return err + if execErr != nil { + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } + return execErr } } - err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatFluxChecked) - if err != nil { - tx.Rollback() - return err + checkHeaderErr := shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatFluxChecked) + if checkHeaderErr != nil { + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } + return checkHeaderErr } return tx.Commit() diff --git a/pkg/transformers/vat_fold/repository.go b/pkg/transformers/vat_fold/repository.go index 5d831bca..049350cd 100644 --- a/pkg/transformers/vat_fold/repository.go +++ b/pkg/transformers/vat_fold/repository.go @@ -16,6 +16,7 @@ package vat_fold import ( "fmt" + log "github.com/sirupsen/logrus" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" @@ -27,32 +28,41 @@ type VatFoldRepository struct { } func (repository VatFoldRepository) Create(headerID int64, models []interface{}) error { - tx, err := repository.db.Begin() - if err != nil { - return err + tx, dBaseErr := repository.db.Begin() + if dBaseErr != nil { + return dBaseErr } for _, model := range models { vatFold, ok := model.(VatFoldModel) if !ok { - tx.Rollback() + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } return fmt.Errorf("model of type %T, not %T", model, VatFoldModel{}) } - _, err = tx.Exec( + _, execErr := tx.Exec( `INSERT into maker.vat_fold (header_id, ilk, urn, rate, log_idx, tx_idx, raw_log) VALUES($1, $2, $3, $4::NUMERIC, $5, $6, $7)`, headerID, vatFold.Ilk, vatFold.Urn, vatFold.Rate, vatFold.LogIndex, vatFold.TransactionIndex, vatFold.Raw, ) - if err != nil { - tx.Rollback() - return err + if execErr != nil { + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } + return execErr } } - err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatFoldChecked) - if err != nil { - tx.Rollback() - return err + checkHeaderErr := shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatFoldChecked) + if checkHeaderErr != nil { + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } + return checkHeaderErr } return tx.Commit() diff --git a/pkg/transformers/vat_grab/repository.go b/pkg/transformers/vat_grab/repository.go index a8a274a4..684426e7 100644 --- a/pkg/transformers/vat_grab/repository.go +++ b/pkg/transformers/vat_grab/repository.go @@ -2,6 +2,7 @@ package vat_grab import ( "fmt" + log "github.com/sirupsen/logrus" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" @@ -13,31 +14,40 @@ type VatGrabRepository struct { } func (repository VatGrabRepository) Create(headerID int64, models []interface{}) error { - tx, err := repository.db.Begin() - if err != nil { - return err + tx, dBaseErr := repository.db.Begin() + if dBaseErr != nil { + return dBaseErr } for _, model := range models { vatGrab, ok := model.(VatGrabModel) if !ok { - tx.Rollback() + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } return fmt.Errorf("model of type %T, not %T", model, VatGrabModel{}) } - _, err = tx.Exec( + _, execErr := tx.Exec( `INSERT into maker.vat_grab (header_id, ilk, urn, v, w, dink, dart, log_idx, tx_idx, raw_log) VALUES($1, $2, $3, $4, $5, $6::NUMERIC, $7::NUMERIC, $8, $9, $10)`, headerID, vatGrab.Ilk, vatGrab.Urn, vatGrab.V, vatGrab.W, vatGrab.Dink, vatGrab.Dart, vatGrab.LogIndex, vatGrab.TransactionIndex, vatGrab.Raw, ) - if err != nil { - tx.Rollback() - return err + if execErr != nil { + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } + return execErr } } - err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatGrabChecked) - if err != nil { - tx.Rollback() - return err + checkHeaderErr := shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatGrabChecked) + if checkHeaderErr != nil { + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } + return checkHeaderErr } return tx.Commit() } diff --git a/pkg/transformers/vat_heal/repository.go b/pkg/transformers/vat_heal/repository.go index aed8fcd0..c471cecb 100644 --- a/pkg/transformers/vat_heal/repository.go +++ b/pkg/transformers/vat_heal/repository.go @@ -16,6 +16,7 @@ package vat_heal import ( "fmt" + log "github.com/sirupsen/logrus" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" @@ -31,31 +32,40 @@ func (repository *VatHealRepository) SetDB(db *postgres.DB) { } func (repository VatHealRepository) Create(headerID int64, models []interface{}) error { - tx, err := repository.db.Begin() - if err != nil { - return err + tx, dBaseErr := repository.db.Begin() + if dBaseErr != nil { + return dBaseErr } for _, model := range models { vatHeal, ok := model.(VatHealModel) if !ok { - tx.Rollback() + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } return fmt.Errorf("model of type %T, not %T", model, VatHealModel{}) } - _, err := tx.Exec(`INSERT INTO maker.vat_heal (header_id, urn, v, rad, log_idx, tx_idx, raw_log) + _, execErr := tx.Exec(`INSERT INTO maker.vat_heal (header_id, urn, v, rad, log_idx, tx_idx, raw_log) VALUES($1, $2, $3, $4::NUMERIC, $5, $6, $7)`, headerID, vatHeal.Urn, vatHeal.V, vatHeal.Rad, vatHeal.LogIndex, vatHeal.TransactionIndex, vatHeal.Raw) - if err != nil { - tx.Rollback() - return err + if execErr != nil { + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } + return execErr } } - err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatHealChecked) - if err != nil { - tx.Rollback() - return err + checkHeaderErr := shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatHealChecked) + if checkHeaderErr != nil { + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } + return checkHeaderErr } return tx.Commit() } diff --git a/pkg/transformers/vat_init/repository.go b/pkg/transformers/vat_init/repository.go index 14b2d4c8..49d4eab3 100644 --- a/pkg/transformers/vat_init/repository.go +++ b/pkg/transformers/vat_init/repository.go @@ -16,6 +16,7 @@ package vat_init import ( "fmt" + log "github.com/sirupsen/logrus" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" @@ -26,33 +27,42 @@ type VatInitRepository struct { } func (repository VatInitRepository) Create(headerID int64, models []interface{}) error { - tx, err := repository.db.Begin() - if err != nil { - return err + tx, dBaseErr := repository.db.Begin() + if dBaseErr != nil { + return dBaseErr } for _, model := range models { vatInit, ok := model.(VatInitModel) if !ok { - tx.Rollback() + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } return fmt.Errorf("model of type %T, not %T", model, VatInitModel{}) } - _, err = tx.Exec( + _, execErr := tx.Exec( `INSERT INTO maker.vat_init (header_id, ilk, log_idx, tx_idx, raw_log) VALUES($1, $2, $3, $4, $5)`, headerID, vatInit.Ilk, vatInit.LogIndex, vatInit.TransactionIndex, vatInit.Raw, ) - if err != nil { - tx.Rollback() - return err + if execErr != nil { + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } + return execErr } } - err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatInitChecked) - if err != nil { - tx.Rollback() - return err + checkHeaderErr := shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatInitChecked) + if checkHeaderErr != nil { + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } + return checkHeaderErr } return tx.Commit() diff --git a/pkg/transformers/vat_move/repository.go b/pkg/transformers/vat_move/repository.go index 2548c2b4..cffe70e8 100644 --- a/pkg/transformers/vat_move/repository.go +++ b/pkg/transformers/vat_move/repository.go @@ -16,6 +16,7 @@ package vat_move import ( "fmt" + log "github.com/sirupsen/logrus" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" @@ -26,34 +27,43 @@ type VatMoveRepository struct { } func (repository VatMoveRepository) Create(headerID int64, models []interface{}) error { - tx, err := repository.db.Begin() - if err != nil { - return err + tx, dBaseErr := repository.db.Begin() + if dBaseErr != nil { + return dBaseErr } for _, model := range models { vatMove, ok := model.(VatMoveModel) if !ok { - tx.Rollback() + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } return fmt.Errorf("model of type %T, not %T", model, VatMoveModel{}) } - _, err = tx.Exec( + _, execErr := tx.Exec( `INSERT INTO maker.vat_move (header_id, src, dst, rad, log_idx, tx_idx, raw_log) VALUES ($1, $2, $3, $4::NUMERIC, $5, $6, $7)`, headerID, vatMove.Src, vatMove.Dst, vatMove.Rad, vatMove.LogIndex, vatMove.TransactionIndex, vatMove.Raw, ) - if err != nil { - tx.Rollback() - return err + if execErr != nil { + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } + return execErr } } - err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatMoveChecked) - if err != nil { - tx.Rollback() - return err + checkHeaderErr := shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatMoveChecked) + if checkHeaderErr != nil { + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } + return checkHeaderErr } return tx.Commit() diff --git a/pkg/transformers/vat_slip/repository.go b/pkg/transformers/vat_slip/repository.go index 15f412ca..b7e0713f 100644 --- a/pkg/transformers/vat_slip/repository.go +++ b/pkg/transformers/vat_slip/repository.go @@ -2,6 +2,7 @@ package vat_slip import ( "fmt" + log "github.com/sirupsen/logrus" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" @@ -12,32 +13,41 @@ type VatSlipRepository struct { } func (repository VatSlipRepository) Create(headerID int64, models []interface{}) error { - tx, err := repository.db.Begin() - if err != nil { - return err + tx, dBaseErr := repository.db.Begin() + if dBaseErr != nil { + return dBaseErr } for _, model := range models { vatSlip, ok := model.(VatSlipModel) if !ok { - tx.Rollback() + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } return fmt.Errorf("model of type %T, not %T", model, VatSlipModel{}) } - _, err = tx.Exec( + _, execErr := tx.Exec( `INSERT into maker.vat_slip (header_id, ilk, guy, rad, tx_idx, log_idx, raw_log) VALUES($1, $2, $3, $4::NUMERIC, $5, $6, $7)`, headerID, vatSlip.Ilk, vatSlip.Guy, vatSlip.Rad, vatSlip.TransactionIndex, vatSlip.LogIndex, vatSlip.Raw, ) - if err != nil { - tx.Rollback() - return err + if execErr != nil { + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } + return execErr } } - err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatSlipChecked) - if err != nil { - tx.Rollback() - return err + checkHeaderErr := shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatSlipChecked) + if checkHeaderErr != nil { + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } + return checkHeaderErr } return tx.Commit() diff --git a/pkg/transformers/vat_toll/repository.go b/pkg/transformers/vat_toll/repository.go index 2c9be8a4..245e4fa3 100644 --- a/pkg/transformers/vat_toll/repository.go +++ b/pkg/transformers/vat_toll/repository.go @@ -2,6 +2,7 @@ package vat_toll import ( "fmt" + log "github.com/sirupsen/logrus" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" @@ -12,32 +13,41 @@ type VatTollRepository struct { } func (repository VatTollRepository) Create(headerID int64, models []interface{}) error { - tx, err := repository.db.Begin() - if err != nil { - return err + tx, dBaseErr := repository.db.Begin() + if dBaseErr != nil { + return dBaseErr } for _, model := range models { vatToll, ok := model.(VatTollModel) if !ok { - tx.Rollback() + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } return fmt.Errorf("model of type %T, not %T", model, VatTollModel{}) } - _, err = tx.Exec( + _, execErr := tx.Exec( `INSERT into maker.vat_toll (header_id, ilk, urn, take, tx_idx, log_idx, raw_log) VALUES($1, $2, $3, $4::NUMERIC, $5, $6, $7)`, headerID, vatToll.Ilk, vatToll.Urn, vatToll.Take, vatToll.TransactionIndex, vatToll.LogIndex, vatToll.Raw, ) - if err != nil { - tx.Rollback() - return err + if execErr != nil { + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } + return execErr } } - err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatTollChecked) - if err != nil { - tx.Rollback() - return err + checkHeaderErr := shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatTollChecked) + if checkHeaderErr != nil { + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } + return checkHeaderErr } return tx.Commit() } diff --git a/pkg/transformers/vat_tune/repository.go b/pkg/transformers/vat_tune/repository.go index c9951ce6..46ea163e 100644 --- a/pkg/transformers/vat_tune/repository.go +++ b/pkg/transformers/vat_tune/repository.go @@ -2,6 +2,7 @@ package vat_tune import ( "fmt" + log "github.com/sirupsen/logrus" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" @@ -12,32 +13,41 @@ type VatTuneRepository struct { } func (repository VatTuneRepository) Create(headerID int64, models []interface{}) error { - tx, err := repository.db.Begin() - if err != nil { - return err + tx, dBaseErr := repository.db.Begin() + if dBaseErr != nil { + return dBaseErr } for _, model := range models { vatTune, ok := model.(VatTuneModel) if !ok { - tx.Rollback() + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } return fmt.Errorf("model of type %T, not %T", model, VatTuneModel{}) } - _, err = tx.Exec( + _, execErr := tx.Exec( `INSERT into maker.vat_tune (header_id, ilk, urn, v, w, dink, dart, tx_idx, log_idx, raw_log) VALUES($1, $2, $3, $4, $5, $6::NUMERIC, $7::NUMERIC, $8, $9, $10)`, headerID, vatTune.Ilk, vatTune.Urn, vatTune.V, vatTune.W, vatTune.Dink, vatTune.Dart, vatTune.TransactionIndex, vatTune.LogIndex, vatTune.Raw, ) - if err != nil { - tx.Rollback() - return err + if execErr != nil { + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } + return execErr } } - err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatTuneChecked) - if err != nil { - tx.Rollback() - return err + checkHeaderErr := shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatTuneChecked) + if checkHeaderErr != nil { + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } + return checkHeaderErr } return tx.Commit() } diff --git a/pkg/transformers/vow_flog/repository.go b/pkg/transformers/vow_flog/repository.go index 48076802..c83496b4 100644 --- a/pkg/transformers/vow_flog/repository.go +++ b/pkg/transformers/vow_flog/repository.go @@ -16,6 +16,7 @@ package vow_flog import ( "fmt" + log "github.com/sirupsen/logrus" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants" @@ -26,34 +27,43 @@ type VowFlogRepository struct { } func (repository VowFlogRepository) Create(headerID int64, models []interface{}) error { - tx, err := repository.db.Begin() - if err != nil { - return err + tx, dBaseErr := repository.db.Begin() + if dBaseErr != nil { + return dBaseErr } for _, model := range models { flog, ok := model.(VowFlogModel) if !ok { - tx.Rollback() + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } return fmt.Errorf("model of type %T, not %T", model, VowFlogModel{}) } - _, err = tx.Exec( + _, execErr := tx.Exec( `INSERT into maker.vow_flog (header_id, era, log_idx, tx_idx, raw_log) VALUES($1, $2::NUMERIC, $3, $4, $5)`, headerID, flog.Era, flog.LogIndex, flog.TransactionIndex, flog.Raw, ) - if err != nil { - tx.Rollback() - return err + if execErr != nil { + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } + return execErr } } - err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.VowFlogChecked) - if err != nil { - tx.Rollback() - return err + checkHeaderErr := shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.VowFlogChecked) + if checkHeaderErr != nil { + rollbackErr := tx.Rollback() + if rollbackErr != nil { + log.Error("failed to rollback ", rollbackErr) + } + return checkHeaderErr } return tx.Commit()