forked from cerc-io/ipld-eth-server
Merge pull request #131 from 8thlight/VDB-31-improve-error-handling-in-transformers
VDB 31 improve error handling in transformers
This commit is contained in:
commit
5efd683c54
@ -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()
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user