forked from cerc-io/ipld-eth-server
refactor error handling in vat, cat, vow
This commit is contained in:
parent
525fada3d7
commit
bc8b7a101c
@ -19,6 +19,7 @@ import (
|
|||||||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
|
||||||
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
type VatFluxRepository struct {
|
type VatFluxRepository struct {
|
||||||
@ -26,31 +27,40 @@ type VatFluxRepository struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (repository VatFluxRepository) Create(headerID int64, models []interface{}) error {
|
func (repository VatFluxRepository) Create(headerID int64, models []interface{}) error {
|
||||||
tx, err := repository.db.Begin()
|
tx, dBaseErr := repository.db.Begin()
|
||||||
if err != nil {
|
if dBaseErr != nil {
|
||||||
return err
|
return dBaseErr
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, model := range models {
|
for _, model := range models {
|
||||||
vatFlux, ok := model.(VatFluxModel)
|
vatFlux, ok := model.(VatFluxModel)
|
||||||
if !ok {
|
if !ok {
|
||||||
tx.Rollback()
|
rollbackErr := tx.Rollback()
|
||||||
|
if rollbackErr != nil {
|
||||||
|
log.Println("failed to rollback ", rollbackErr)
|
||||||
|
}
|
||||||
return fmt.Errorf("model of type %T, not %T", model, VatFluxModel{})
|
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)`,
|
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)
|
headerID, vatFlux.Ilk, vatFlux.Dst, vatFlux.Src, vatFlux.Rad, vatFlux.TransactionIndex, vatFlux.LogIndex, vatFlux.Raw)
|
||||||
if err != nil {
|
if execErr != nil {
|
||||||
tx.Rollback()
|
rollbackErr := tx.Rollback()
|
||||||
return err
|
if rollbackErr != nil {
|
||||||
|
log.Println("failed to rollback ", rollbackErr)
|
||||||
|
}
|
||||||
|
return execErr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatFluxChecked)
|
checkHeaderErr := shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatFluxChecked)
|
||||||
if err != nil {
|
if checkHeaderErr != nil {
|
||||||
tx.Rollback()
|
rollbackErr := tx.Rollback()
|
||||||
return err
|
if rollbackErr != nil {
|
||||||
|
log.Println("failed to rollback ", rollbackErr)
|
||||||
|
}
|
||||||
|
return checkHeaderErr
|
||||||
}
|
}
|
||||||
|
|
||||||
return tx.Commit()
|
return tx.Commit()
|
||||||
|
@ -16,6 +16,7 @@ package vat_fold
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
|
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
||||||
@ -27,32 +28,41 @@ type VatFoldRepository struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (repository VatFoldRepository) Create(headerID int64, models []interface{}) error {
|
func (repository VatFoldRepository) Create(headerID int64, models []interface{}) error {
|
||||||
tx, err := repository.db.Begin()
|
tx, dBaseErr := repository.db.Begin()
|
||||||
if err != nil {
|
if dBaseErr != nil {
|
||||||
return err
|
return dBaseErr
|
||||||
}
|
}
|
||||||
for _, model := range models {
|
for _, model := range models {
|
||||||
vatFold, ok := model.(VatFoldModel)
|
vatFold, ok := model.(VatFoldModel)
|
||||||
if !ok {
|
if !ok {
|
||||||
tx.Rollback()
|
rollbackErr := tx.Rollback()
|
||||||
|
if rollbackErr != nil {
|
||||||
|
log.Println("failed to rollback ", rollbackErr)
|
||||||
|
}
|
||||||
return fmt.Errorf("model of type %T, not %T", model, VatFoldModel{})
|
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)
|
`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)`,
|
VALUES($1, $2, $3, $4::NUMERIC, $5, $6, $7)`,
|
||||||
headerID, vatFold.Ilk, vatFold.Urn, vatFold.Rate, vatFold.LogIndex, vatFold.TransactionIndex, vatFold.Raw,
|
headerID, vatFold.Ilk, vatFold.Urn, vatFold.Rate, vatFold.LogIndex, vatFold.TransactionIndex, vatFold.Raw,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if execErr != nil {
|
||||||
tx.Rollback()
|
rollbackErr := tx.Rollback()
|
||||||
return err
|
if rollbackErr != nil {
|
||||||
|
log.Println("failed to rollback ", rollbackErr)
|
||||||
|
}
|
||||||
|
return execErr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatFoldChecked)
|
checkHeaderErr := shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatFoldChecked)
|
||||||
if err != nil {
|
if checkHeaderErr != nil {
|
||||||
tx.Rollback()
|
rollbackErr := tx.Rollback()
|
||||||
return err
|
if rollbackErr != nil {
|
||||||
|
log.Println("failed to rollback ", rollbackErr)
|
||||||
|
}
|
||||||
|
return checkHeaderErr
|
||||||
}
|
}
|
||||||
|
|
||||||
return tx.Commit()
|
return tx.Commit()
|
||||||
|
@ -2,6 +2,7 @@ package vat_grab
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
|
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
||||||
@ -13,31 +14,40 @@ type VatGrabRepository struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (repository VatGrabRepository) Create(headerID int64, models []interface{}) error {
|
func (repository VatGrabRepository) Create(headerID int64, models []interface{}) error {
|
||||||
tx, err := repository.db.Begin()
|
tx, dBaseErr := repository.db.Begin()
|
||||||
if err != nil {
|
if dBaseErr != nil {
|
||||||
return err
|
return dBaseErr
|
||||||
}
|
}
|
||||||
for _, model := range models {
|
for _, model := range models {
|
||||||
vatGrab, ok := model.(VatGrabModel)
|
vatGrab, ok := model.(VatGrabModel)
|
||||||
if !ok {
|
if !ok {
|
||||||
tx.Rollback()
|
rollbackErr := tx.Rollback()
|
||||||
|
if rollbackErr != nil {
|
||||||
|
log.Println("failed to rollback ", rollbackErr)
|
||||||
|
}
|
||||||
return fmt.Errorf("model of type %T, not %T", model, VatGrabModel{})
|
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)
|
`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)`,
|
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,
|
headerID, vatGrab.Ilk, vatGrab.Urn, vatGrab.V, vatGrab.W, vatGrab.Dink, vatGrab.Dart, vatGrab.LogIndex, vatGrab.TransactionIndex, vatGrab.Raw,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if execErr != nil {
|
||||||
tx.Rollback()
|
rollbackErr := tx.Rollback()
|
||||||
return err
|
if rollbackErr != nil {
|
||||||
|
log.Println("failed to rollback ", rollbackErr)
|
||||||
|
}
|
||||||
|
return execErr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatGrabChecked)
|
checkHeaderErr := shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatGrabChecked)
|
||||||
if err != nil {
|
if checkHeaderErr != nil {
|
||||||
tx.Rollback()
|
rollbackErr := tx.Rollback()
|
||||||
return err
|
if rollbackErr != nil {
|
||||||
|
log.Println("failed to rollback ", rollbackErr)
|
||||||
|
}
|
||||||
|
return checkHeaderErr
|
||||||
}
|
}
|
||||||
return tx.Commit()
|
return tx.Commit()
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ package vat_heal
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
|
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
||||||
@ -31,31 +32,40 @@ func (repository *VatHealRepository) SetDB(db *postgres.DB) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (repository VatHealRepository) Create(headerID int64, models []interface{}) error {
|
func (repository VatHealRepository) Create(headerID int64, models []interface{}) error {
|
||||||
tx, err := repository.db.Begin()
|
tx, dBaseErr := repository.db.Begin()
|
||||||
if err != nil {
|
if dBaseErr != nil {
|
||||||
return err
|
return dBaseErr
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, model := range models {
|
for _, model := range models {
|
||||||
vatHeal, ok := model.(VatHealModel)
|
vatHeal, ok := model.(VatHealModel)
|
||||||
if !ok {
|
if !ok {
|
||||||
tx.Rollback()
|
rollbackErr := tx.Rollback()
|
||||||
|
if rollbackErr != nil {
|
||||||
|
log.Println("failed to rollback ", rollbackErr)
|
||||||
|
}
|
||||||
return fmt.Errorf("model of type %T, not %T", model, VatHealModel{})
|
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)`,
|
VALUES($1, $2, $3, $4::NUMERIC, $5, $6, $7)`,
|
||||||
headerID, vatHeal.Urn, vatHeal.V, vatHeal.Rad, vatHeal.LogIndex, vatHeal.TransactionIndex, vatHeal.Raw)
|
headerID, vatHeal.Urn, vatHeal.V, vatHeal.Rad, vatHeal.LogIndex, vatHeal.TransactionIndex, vatHeal.Raw)
|
||||||
if err != nil {
|
if execErr != nil {
|
||||||
tx.Rollback()
|
rollbackErr := tx.Rollback()
|
||||||
return err
|
if rollbackErr != nil {
|
||||||
|
log.Println("failed to rollback ", rollbackErr)
|
||||||
|
}
|
||||||
|
return execErr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatHealChecked)
|
checkHeaderErr := shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatHealChecked)
|
||||||
if err != nil {
|
if checkHeaderErr != nil {
|
||||||
tx.Rollback()
|
rollbackErr := tx.Rollback()
|
||||||
return err
|
if rollbackErr != nil {
|
||||||
|
log.Println("failed to rollback ", rollbackErr)
|
||||||
|
}
|
||||||
|
return checkHeaderErr
|
||||||
}
|
}
|
||||||
return tx.Commit()
|
return tx.Commit()
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ import (
|
|||||||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
|
||||||
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
type VatInitRepository struct {
|
type VatInitRepository struct {
|
||||||
@ -26,33 +27,42 @@ type VatInitRepository struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (repository VatInitRepository) Create(headerID int64, models []interface{}) error {
|
func (repository VatInitRepository) Create(headerID int64, models []interface{}) error {
|
||||||
tx, err := repository.db.Begin()
|
tx, dBaseErr := repository.db.Begin()
|
||||||
if err != nil {
|
if dBaseErr != nil {
|
||||||
return err
|
return dBaseErr
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, model := range models {
|
for _, model := range models {
|
||||||
vatInit, ok := model.(VatInitModel)
|
vatInit, ok := model.(VatInitModel)
|
||||||
if !ok {
|
if !ok {
|
||||||
tx.Rollback()
|
rollbackErr := tx.Rollback()
|
||||||
|
if rollbackErr != nil {
|
||||||
|
log.Println("failed to rollback ", rollbackErr)
|
||||||
|
}
|
||||||
return fmt.Errorf("model of type %T, not %T", model, VatInitModel{})
|
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)
|
`INSERT INTO maker.vat_init (header_id, ilk, log_idx, tx_idx, raw_log)
|
||||||
VALUES($1, $2, $3, $4, $5)`,
|
VALUES($1, $2, $3, $4, $5)`,
|
||||||
headerID, vatInit.Ilk, vatInit.LogIndex, vatInit.TransactionIndex, vatInit.Raw,
|
headerID, vatInit.Ilk, vatInit.LogIndex, vatInit.TransactionIndex, vatInit.Raw,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if execErr != nil {
|
||||||
tx.Rollback()
|
rollbackErr := tx.Rollback()
|
||||||
return err
|
if rollbackErr != nil {
|
||||||
|
log.Println("failed to rollback ", rollbackErr)
|
||||||
|
}
|
||||||
|
return execErr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatInitChecked)
|
checkHeaderErr := shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatInitChecked)
|
||||||
if err != nil {
|
if checkHeaderErr != nil {
|
||||||
tx.Rollback()
|
rollbackErr := tx.Rollback()
|
||||||
return err
|
if rollbackErr != nil {
|
||||||
|
log.Println("failed to rollback ", rollbackErr)
|
||||||
|
}
|
||||||
|
return checkHeaderErr
|
||||||
}
|
}
|
||||||
|
|
||||||
return tx.Commit()
|
return tx.Commit()
|
||||||
|
@ -19,6 +19,7 @@ import (
|
|||||||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
|
||||||
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
type VatMoveRepository struct {
|
type VatMoveRepository struct {
|
||||||
@ -26,34 +27,43 @@ type VatMoveRepository struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (repository VatMoveRepository) Create(headerID int64, models []interface{}) error {
|
func (repository VatMoveRepository) Create(headerID int64, models []interface{}) error {
|
||||||
tx, err := repository.db.Begin()
|
tx, dBaseErr := repository.db.Begin()
|
||||||
if err != nil {
|
if dBaseErr != nil {
|
||||||
return err
|
return dBaseErr
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, model := range models {
|
for _, model := range models {
|
||||||
vatMove, ok := model.(VatMoveModel)
|
vatMove, ok := model.(VatMoveModel)
|
||||||
if !ok {
|
if !ok {
|
||||||
tx.Rollback()
|
rollbackErr := tx.Rollback()
|
||||||
|
if rollbackErr != nil {
|
||||||
|
log.Println("failed to rollback ", rollbackErr)
|
||||||
|
}
|
||||||
return fmt.Errorf("model of type %T, not %T", model, VatMoveModel{})
|
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)
|
`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)`,
|
VALUES ($1, $2, $3, $4::NUMERIC, $5, $6, $7)`,
|
||||||
headerID, vatMove.Src, vatMove.Dst, vatMove.Rad, vatMove.LogIndex, vatMove.TransactionIndex, vatMove.Raw,
|
headerID, vatMove.Src, vatMove.Dst, vatMove.Rad, vatMove.LogIndex, vatMove.TransactionIndex, vatMove.Raw,
|
||||||
)
|
)
|
||||||
|
|
||||||
if err != nil {
|
if execErr != nil {
|
||||||
tx.Rollback()
|
rollbackErr := tx.Rollback()
|
||||||
return err
|
if rollbackErr != nil {
|
||||||
|
log.Println("failed to rollback ", rollbackErr)
|
||||||
|
}
|
||||||
|
return execErr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatMoveChecked)
|
checkHeaderErr := shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatMoveChecked)
|
||||||
if err != nil {
|
if checkHeaderErr != nil {
|
||||||
tx.Rollback()
|
rollbackErr := tx.Rollback()
|
||||||
return err
|
if rollbackErr != nil {
|
||||||
|
log.Println("failed to rollback ", rollbackErr)
|
||||||
|
}
|
||||||
|
return checkHeaderErr
|
||||||
}
|
}
|
||||||
|
|
||||||
return tx.Commit()
|
return tx.Commit()
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
|
||||||
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
type VatSlipRepository struct {
|
type VatSlipRepository struct {
|
||||||
@ -12,32 +13,41 @@ type VatSlipRepository struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (repository VatSlipRepository) Create(headerID int64, models []interface{}) error {
|
func (repository VatSlipRepository) Create(headerID int64, models []interface{}) error {
|
||||||
tx, err := repository.db.Begin()
|
tx, dBaseErr := repository.db.Begin()
|
||||||
if err != nil {
|
if dBaseErr != nil {
|
||||||
return err
|
return dBaseErr
|
||||||
}
|
}
|
||||||
for _, model := range models {
|
for _, model := range models {
|
||||||
vatSlip, ok := model.(VatSlipModel)
|
vatSlip, ok := model.(VatSlipModel)
|
||||||
if !ok {
|
if !ok {
|
||||||
tx.Rollback()
|
rollbackErr := tx.Rollback()
|
||||||
|
if rollbackErr != nil {
|
||||||
|
log.Println("failed to rollback ", rollbackErr)
|
||||||
|
}
|
||||||
return fmt.Errorf("model of type %T, not %T", model, VatSlipModel{})
|
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)
|
`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)`,
|
VALUES($1, $2, $3, $4::NUMERIC, $5, $6, $7)`,
|
||||||
headerID, vatSlip.Ilk, vatSlip.Guy, vatSlip.Rad, vatSlip.TransactionIndex, vatSlip.LogIndex, vatSlip.Raw,
|
headerID, vatSlip.Ilk, vatSlip.Guy, vatSlip.Rad, vatSlip.TransactionIndex, vatSlip.LogIndex, vatSlip.Raw,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if execErr != nil {
|
||||||
tx.Rollback()
|
rollbackErr := tx.Rollback()
|
||||||
return err
|
if rollbackErr != nil {
|
||||||
|
log.Println("failed to rollback ", rollbackErr)
|
||||||
|
}
|
||||||
|
return execErr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatSlipChecked)
|
checkHeaderErr := shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatSlipChecked)
|
||||||
if err != nil {
|
if checkHeaderErr != nil {
|
||||||
tx.Rollback()
|
rollbackErr := tx.Rollback()
|
||||||
return err
|
if rollbackErr != nil {
|
||||||
|
log.Println("failed to rollback ", rollbackErr)
|
||||||
|
}
|
||||||
|
return checkHeaderErr
|
||||||
}
|
}
|
||||||
|
|
||||||
return tx.Commit()
|
return tx.Commit()
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
|
||||||
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
type VatTollRepository struct {
|
type VatTollRepository struct {
|
||||||
@ -12,32 +13,41 @@ type VatTollRepository struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (repository VatTollRepository) Create(headerID int64, models []interface{}) error {
|
func (repository VatTollRepository) Create(headerID int64, models []interface{}) error {
|
||||||
tx, err := repository.db.Begin()
|
tx, dBaseErr := repository.db.Begin()
|
||||||
if err != nil {
|
if dBaseErr != nil {
|
||||||
return err
|
return dBaseErr
|
||||||
}
|
}
|
||||||
for _, model := range models {
|
for _, model := range models {
|
||||||
vatToll, ok := model.(VatTollModel)
|
vatToll, ok := model.(VatTollModel)
|
||||||
if !ok {
|
if !ok {
|
||||||
tx.Rollback()
|
rollbackErr := tx.Rollback()
|
||||||
|
if rollbackErr != nil {
|
||||||
|
log.Println("failed to rollback ", rollbackErr)
|
||||||
|
}
|
||||||
return fmt.Errorf("model of type %T, not %T", model, VatTollModel{})
|
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)
|
`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)`,
|
VALUES($1, $2, $3, $4::NUMERIC, $5, $6, $7)`,
|
||||||
headerID, vatToll.Ilk, vatToll.Urn, vatToll.Take, vatToll.TransactionIndex, vatToll.LogIndex, vatToll.Raw,
|
headerID, vatToll.Ilk, vatToll.Urn, vatToll.Take, vatToll.TransactionIndex, vatToll.LogIndex, vatToll.Raw,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if execErr != nil {
|
||||||
tx.Rollback()
|
rollbackErr := tx.Rollback()
|
||||||
return err
|
if rollbackErr != nil {
|
||||||
|
log.Println("failed to rollback ", rollbackErr)
|
||||||
|
}
|
||||||
|
return execErr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatTollChecked)
|
checkHeaderErr := shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatTollChecked)
|
||||||
if err != nil {
|
if checkHeaderErr != nil {
|
||||||
tx.Rollback()
|
rollbackErr := tx.Rollback()
|
||||||
return err
|
if rollbackErr != nil {
|
||||||
|
log.Println("failed to rollback ", rollbackErr)
|
||||||
|
}
|
||||||
|
return checkHeaderErr
|
||||||
}
|
}
|
||||||
return tx.Commit()
|
return tx.Commit()
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
|
||||||
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
type VatTuneRepository struct {
|
type VatTuneRepository struct {
|
||||||
@ -12,32 +13,41 @@ type VatTuneRepository struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (repository VatTuneRepository) Create(headerID int64, models []interface{}) error {
|
func (repository VatTuneRepository) Create(headerID int64, models []interface{}) error {
|
||||||
tx, err := repository.db.Begin()
|
tx, dBaseErr := repository.db.Begin()
|
||||||
if err != nil {
|
if dBaseErr != nil {
|
||||||
return err
|
return dBaseErr
|
||||||
}
|
}
|
||||||
for _, model := range models {
|
for _, model := range models {
|
||||||
vatTune, ok := model.(VatTuneModel)
|
vatTune, ok := model.(VatTuneModel)
|
||||||
if !ok {
|
if !ok {
|
||||||
tx.Rollback()
|
rollbackErr := tx.Rollback()
|
||||||
|
if rollbackErr != nil {
|
||||||
|
log.Println("failed to rollback ", rollbackErr)
|
||||||
|
}
|
||||||
return fmt.Errorf("model of type %T, not %T", model, VatTuneModel{})
|
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)
|
`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)`,
|
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,
|
headerID, vatTune.Ilk, vatTune.Urn, vatTune.V, vatTune.W, vatTune.Dink, vatTune.Dart, vatTune.TransactionIndex, vatTune.LogIndex, vatTune.Raw,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if execErr != nil {
|
||||||
tx.Rollback()
|
rollbackErr := tx.Rollback()
|
||||||
return err
|
if rollbackErr != nil {
|
||||||
|
log.Println("failed to rollback ", rollbackErr)
|
||||||
|
}
|
||||||
|
return execErr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatTuneChecked)
|
checkHeaderErr := shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatTuneChecked)
|
||||||
if err != nil {
|
if checkHeaderErr != nil {
|
||||||
tx.Rollback()
|
rollbackErr := tx.Rollback()
|
||||||
return err
|
if rollbackErr != nil {
|
||||||
|
log.Println("failed to rollback ", rollbackErr)
|
||||||
|
}
|
||||||
|
return checkHeaderErr
|
||||||
}
|
}
|
||||||
return tx.Commit()
|
return tx.Commit()
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ import (
|
|||||||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
|
||||||
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
type VowFlogRepository struct {
|
type VowFlogRepository struct {
|
||||||
@ -26,34 +27,43 @@ type VowFlogRepository struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (repository VowFlogRepository) Create(headerID int64, models []interface{}) error {
|
func (repository VowFlogRepository) Create(headerID int64, models []interface{}) error {
|
||||||
tx, err := repository.db.Begin()
|
tx, dBaseErr := repository.db.Begin()
|
||||||
if err != nil {
|
if dBaseErr != nil {
|
||||||
return err
|
return dBaseErr
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, model := range models {
|
for _, model := range models {
|
||||||
flog, ok := model.(VowFlogModel)
|
flog, ok := model.(VowFlogModel)
|
||||||
if !ok {
|
if !ok {
|
||||||
tx.Rollback()
|
rollbackErr := tx.Rollback()
|
||||||
|
if rollbackErr != nil {
|
||||||
|
log.Println("failed to rollback ", rollbackErr)
|
||||||
|
}
|
||||||
return fmt.Errorf("model of type %T, not %T", model, VowFlogModel{})
|
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)
|
`INSERT into maker.vow_flog (header_id, era, log_idx, tx_idx, raw_log)
|
||||||
VALUES($1, $2::NUMERIC, $3, $4, $5)`,
|
VALUES($1, $2::NUMERIC, $3, $4, $5)`,
|
||||||
headerID, flog.Era, flog.LogIndex, flog.TransactionIndex, flog.Raw,
|
headerID, flog.Era, flog.LogIndex, flog.TransactionIndex, flog.Raw,
|
||||||
)
|
)
|
||||||
|
|
||||||
if err != nil {
|
if execErr != nil {
|
||||||
tx.Rollback()
|
rollbackErr := tx.Rollback()
|
||||||
return err
|
if rollbackErr != nil {
|
||||||
|
log.Println("failed to rollback ", rollbackErr)
|
||||||
|
}
|
||||||
|
return execErr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.VowFlogChecked)
|
checkHeaderErr := shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.VowFlogChecked)
|
||||||
if err != nil {
|
if checkHeaderErr != nil {
|
||||||
tx.Rollback()
|
rollbackErr := tx.Rollback()
|
||||||
return err
|
if rollbackErr != nil {
|
||||||
|
log.Println("failed to rollback ", rollbackErr)
|
||||||
|
}
|
||||||
|
return checkHeaderErr
|
||||||
}
|
}
|
||||||
|
|
||||||
return tx.Commit()
|
return tx.Commit()
|
||||||
|
Loading…
Reference in New Issue
Block a user