forked from cerc-io/ipld-eth-server
(VDB-380) Create separate table for ilks
- reference ilk by foreign key every place it's used
This commit is contained in:
@@ -37,7 +37,7 @@ func (PitFileIlkConverter) ToModels(ethLogs []types.Log) ([]interface{}, error)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ilk := ethLog.Topics[2].Hex()
|
||||
ilk := shared.GetHexWithoutPrefix(ethLog.Topics[2].Bytes())
|
||||
what := string(bytes.Trim(ethLog.Topics[3].Bytes(), "\x00"))
|
||||
dataBytes := ethLog.Data[len(ethLog.Data)-constants.DataItemLength:]
|
||||
data, err := getData(dataBytes, what)
|
||||
|
||||
@@ -47,11 +47,20 @@ func (repository PitFileIlkRepository) Create(headerID int64, models []interface
|
||||
return fmt.Errorf("model of type %T, not %T", model, PitFileIlkModel{})
|
||||
}
|
||||
|
||||
ilkID, ilkErr := shared.GetOrCreateIlkInTransaction(pitFileIlk.Ilk, tx)
|
||||
if ilkErr != nil {
|
||||
rollbackErr := tx.Rollback()
|
||||
if rollbackErr != nil {
|
||||
log.Error("failed to rollback ", rollbackErr)
|
||||
}
|
||||
return ilkErr
|
||||
}
|
||||
|
||||
_, 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)
|
||||
ON CONFLICT (header_id, tx_idx, log_idx) DO UPDATE SET ilk = $2, what = $3, data = $4, raw_log = $7;`,
|
||||
headerID, pitFileIlk.Ilk, pitFileIlk.What, pitFileIlk.Data, pitFileIlk.LogIndex, pitFileIlk.TransactionIndex, pitFileIlk.Raw,
|
||||
headerID, ilkID, pitFileIlk.What, pitFileIlk.Data, pitFileIlk.LogIndex, pitFileIlk.TransactionIndex, pitFileIlk.Raw,
|
||||
)
|
||||
if execErr != nil {
|
||||
rollbackErr := tx.Rollback()
|
||||
|
||||
@@ -19,6 +19,8 @@ package ilk_test
|
||||
import (
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
||||
"strconv"
|
||||
|
||||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres/repositories"
|
||||
@@ -67,7 +69,9 @@ var _ = Describe("Pit file ilk repository", func() {
|
||||
var dbPitFile ilk.PitFileIlkModel
|
||||
err = db.Get(&dbPitFile, `SELECT ilk, what, data, log_idx, tx_idx, raw_log FROM maker.pit_file_ilk WHERE header_id = $1`, headerID)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(dbPitFile.Ilk).To(Equal(test_data.PitFileIlkSpotModel.Ilk))
|
||||
ilkID, err := shared.GetOrCreateIlk(test_data.PitFileIlkSpotModel.Ilk, db)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(dbPitFile.Ilk).To(Equal(strconv.Itoa(ilkID)))
|
||||
Expect(dbPitFile.What).To(Equal(test_data.PitFileIlkSpotModel.What))
|
||||
Expect(dbPitFile.Data).To(Equal(test_data.PitFileIlkSpotModel.Data))
|
||||
Expect(dbPitFile.LogIndex).To(Equal(test_data.PitFileIlkSpotModel.LogIndex))
|
||||
|
||||
Reference in New Issue
Block a user