Add rollback if GetTicInTx fails and move GetTicInTx to shared/repository.go
This commit is contained in:
parent
c8aa3dc275
commit
e2b864baa8
@ -34,6 +34,10 @@ func (repository DentRepository) Create(headerID int64, models []interface{}) er
|
||||
|
||||
tic, getTicErr := shared.GetTicInTx(headerID, tx)
|
||||
if getTicErr != nil {
|
||||
rollbackErr := tx.Rollback()
|
||||
if rollbackErr != nil {
|
||||
log.Error("failed to rollback ", rollbackErr)
|
||||
}
|
||||
return getTicErr
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -34,6 +34,10 @@ func (repository TendRepository) Create(headerID int64, models []interface{}) er
|
||||
|
||||
tic, getTicErr := shared.GetTicInTx(headerID, tx)
|
||||
if getTicErr != nil {
|
||||
rollbackErr := tx.Rollback()
|
||||
if rollbackErr != nil {
|
||||
log.Error("failed to rollback ", rollbackErr)
|
||||
}
|
||||
return getTicErr
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user