Add log index to Bite
This commit is contained in:
parent
ea3de51792
commit
495f39abb8
@ -9,6 +9,7 @@ CREATE TABLE maker.bite (
|
|||||||
tab NUMERIC,
|
tab NUMERIC,
|
||||||
nflip NUMERIC,
|
nflip NUMERIC,
|
||||||
tx_idx INTEGER NOT NUll,
|
tx_idx INTEGER NOT NUll,
|
||||||
|
log_idx INTEGER NOT NUll,
|
||||||
raw_log JSONB,
|
raw_log JSONB,
|
||||||
UNIQUE (header_id, tx_idx)
|
UNIQUE (header_id, tx_idx, log_idx)
|
||||||
)
|
)
|
@ -72,6 +72,7 @@ CREATE TABLE maker.bite (
|
|||||||
tab numeric,
|
tab numeric,
|
||||||
nflip numeric,
|
nflip numeric,
|
||||||
tx_idx integer NOT NULL,
|
tx_idx integer NOT NULL,
|
||||||
|
log_idx integer NOT NULL,
|
||||||
raw_log jsonb
|
raw_log jsonb
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -1707,11 +1708,11 @@ ALTER TABLE ONLY public.watched_contracts ALTER COLUMN contract_id SET DEFAULT n
|
|||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Name: bite bite_header_id_tx_idx_key; Type: CONSTRAINT; Schema: maker; Owner: -
|
-- Name: bite bite_header_id_tx_idx_log_idx_key; Type: CONSTRAINT; Schema: maker; Owner: -
|
||||||
--
|
--
|
||||||
|
|
||||||
ALTER TABLE ONLY maker.bite
|
ALTER TABLE ONLY maker.bite
|
||||||
ADD CONSTRAINT bite_header_id_tx_idx_key UNIQUE (header_id, tx_idx);
|
ADD CONSTRAINT bite_header_id_tx_idx_log_idx_key UNIQUE (header_id, tx_idx, log_idx);
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
|
@ -51,6 +51,7 @@ func (BiteConverter) ToEntities(contractAbi string, ethLogs []types.Log) ([]Bite
|
|||||||
}
|
}
|
||||||
|
|
||||||
entity.Raw = ethLog
|
entity.Raw = ethLog
|
||||||
|
entity.LogIndex = ethLog.Index
|
||||||
entity.TransactionIndex = ethLog.TxIndex
|
entity.TransactionIndex = ethLog.TxIndex
|
||||||
|
|
||||||
entities = append(entities, *entity)
|
entities = append(entities, *entity)
|
||||||
@ -69,6 +70,7 @@ func (converter BiteConverter) ToModels(entities []BiteEntity) ([]BiteModel, err
|
|||||||
iArt := entity.IArt
|
iArt := entity.IArt
|
||||||
tab := entity.Tab
|
tab := entity.Tab
|
||||||
flip := entity.Flip
|
flip := entity.Flip
|
||||||
|
logIdx := entity.LogIndex
|
||||||
txIdx := entity.TransactionIndex
|
txIdx := entity.TransactionIndex
|
||||||
rawLogJson, err := json.Marshal(entity.Raw)
|
rawLogJson, err := json.Marshal(entity.Raw)
|
||||||
rawLogString := string(rawLogJson)
|
rawLogString := string(rawLogJson)
|
||||||
@ -84,6 +86,7 @@ func (converter BiteConverter) ToModels(entities []BiteEntity) ([]BiteModel, err
|
|||||||
IArt: shared.BigIntToString(iArt),
|
IArt: shared.BigIntToString(iArt),
|
||||||
Tab: shared.BigIntToString(tab),
|
Tab: shared.BigIntToString(tab),
|
||||||
NFlip: shared.BigIntToString(flip),
|
NFlip: shared.BigIntToString(flip),
|
||||||
|
LogIndex: logIdx,
|
||||||
TransactionIndex: txIdx,
|
TransactionIndex: txIdx,
|
||||||
Raw: rawLogString,
|
Raw: rawLogString,
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,7 @@ type BiteEntity struct {
|
|||||||
Tab *big.Int
|
Tab *big.Int
|
||||||
Flip *big.Int
|
Flip *big.Int
|
||||||
IArt *big.Int
|
IArt *big.Int
|
||||||
|
LogIndex uint
|
||||||
TransactionIndex uint
|
TransactionIndex uint
|
||||||
Raw types.Log
|
Raw types.Log
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@ type BiteModel struct {
|
|||||||
IArt string
|
IArt string
|
||||||
Tab string
|
Tab string
|
||||||
NFlip string
|
NFlip string
|
||||||
|
LogIndex uint `db:"log_idx"`
|
||||||
TransactionIndex uint `db:"tx_idx"`
|
TransactionIndex uint `db:"tx_idx"`
|
||||||
Raw string `db:"raw_log"`
|
Raw string `db:"raw_log"`
|
||||||
}
|
}
|
||||||
|
@ -40,9 +40,9 @@ func (repository BiteRepository) Create(headerID int64, models []BiteModel) erro
|
|||||||
}
|
}
|
||||||
for _, model := range models {
|
for _, model := range models {
|
||||||
_, err := tx.Exec(
|
_, err := tx.Exec(
|
||||||
`INSERT into maker.bite (header_id, ilk, urn, ink, art, iart, tab, nflip, tx_idx, raw_log)
|
`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)`,
|
VALUES($1, $2, $3, $4::NUMERIC, $5::NUMERIC, $6::NUMERIC, $7::NUMERIC, $8::NUMERIC, $9, $10, $11)`,
|
||||||
headerID, model.Ilk, model.Urn, model.Ink, model.Art, model.IArt, model.Tab, model.NFlip, model.TransactionIndex, model.Raw,
|
headerID, model.Ilk, model.Urn, model.Ink, model.Art, model.IArt, model.Tab, model.NFlip, model.LogIndex, model.TransactionIndex, model.Raw,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
|
@ -58,7 +58,7 @@ var _ = Describe("Bite repository", func() {
|
|||||||
|
|
||||||
It("persists a bite record", func() {
|
It("persists a bite record", func() {
|
||||||
var dbBite bite.BiteModel
|
var dbBite bite.BiteModel
|
||||||
err = db.Get(&dbBite, `SELECT ilk, urn, ink, art, tab, nflip, iart, tx_idx, raw_log FROM maker.bite WHERE header_id = $1`, headerID)
|
err = db.Get(&dbBite, `SELECT ilk, urn, ink, art, tab, nflip, iart, log_idx, tx_idx, raw_log FROM maker.bite WHERE header_id = $1`, headerID)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(dbBite.Ilk).To(Equal(test_data.BiteModel.Ilk))
|
Expect(dbBite.Ilk).To(Equal(test_data.BiteModel.Ilk))
|
||||||
Expect(dbBite.Urn).To(Equal(test_data.BiteModel.Urn))
|
Expect(dbBite.Urn).To(Equal(test_data.BiteModel.Urn))
|
||||||
@ -67,6 +67,7 @@ var _ = Describe("Bite repository", func() {
|
|||||||
Expect(dbBite.Tab).To(Equal(test_data.BiteModel.Tab))
|
Expect(dbBite.Tab).To(Equal(test_data.BiteModel.Tab))
|
||||||
Expect(dbBite.NFlip).To(Equal(test_data.BiteModel.NFlip))
|
Expect(dbBite.NFlip).To(Equal(test_data.BiteModel.NFlip))
|
||||||
Expect(dbBite.IArt).To(Equal(test_data.BiteModel.IArt))
|
Expect(dbBite.IArt).To(Equal(test_data.BiteModel.IArt))
|
||||||
|
Expect(dbBite.LogIndex).To(Equal(test_data.BiteModel.LogIndex))
|
||||||
Expect(dbBite.TransactionIndex).To(Equal(test_data.BiteModel.TransactionIndex))
|
Expect(dbBite.TransactionIndex).To(Equal(test_data.BiteModel.TransactionIndex))
|
||||||
Expect(dbBite.Raw).To(MatchJSON(test_data.BiteModel.Raw))
|
Expect(dbBite.Raw).To(MatchJSON(test_data.BiteModel.Raw))
|
||||||
})
|
})
|
||||||
@ -90,7 +91,7 @@ var _ = Describe("Bite repository", func() {
|
|||||||
|
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
var dbBite bite.BiteModel
|
var dbBite bite.BiteModel
|
||||||
err = db.Get(&dbBite, `SELECT ilk, urn, ink, art, tab, nflip, iart, tx_idx, raw_log FROM maker.bite WHERE header_id = $1`, headerID)
|
err = db.Get(&dbBite, `SELECT ilk, urn, ink, art, tab, nflip, iart, log_idx, tx_idx, raw_log FROM maker.bite WHERE header_id = $1`, headerID)
|
||||||
Expect(err).To(HaveOccurred())
|
Expect(err).To(HaveOccurred())
|
||||||
Expect(err).To(MatchError(sql.ErrNoRows))
|
Expect(err).To(MatchError(sql.ErrNoRows))
|
||||||
})
|
})
|
||||||
|
@ -57,7 +57,7 @@ var EthBiteLog = types.Log{
|
|||||||
TxHash: common.HexToHash(TemporaryBiteTransaction),
|
TxHash: common.HexToHash(TemporaryBiteTransaction),
|
||||||
TxIndex: 111,
|
TxIndex: 111,
|
||||||
BlockHash: TemporaryBiteBlockHash,
|
BlockHash: TemporaryBiteBlockHash,
|
||||||
Index: 0,
|
Index: 7,
|
||||||
Removed: false,
|
Removed: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,6 +69,7 @@ var BiteEntity = bite.BiteEntity{
|
|||||||
Tab: biteTab,
|
Tab: biteTab,
|
||||||
Flip: biteFlip,
|
Flip: biteFlip,
|
||||||
IArt: biteIArt,
|
IArt: biteIArt,
|
||||||
|
LogIndex: EthBiteLog.Index,
|
||||||
TransactionIndex: EthBiteLog.TxIndex,
|
TransactionIndex: EthBiteLog.TxIndex,
|
||||||
Raw: EthBiteLog,
|
Raw: EthBiteLog,
|
||||||
}
|
}
|
||||||
@ -78,9 +79,10 @@ var BiteModel = bite.BiteModel{
|
|||||||
Urn: biteLadString,
|
Urn: biteLadString,
|
||||||
Ink: biteInk.String(),
|
Ink: biteInk.String(),
|
||||||
Art: biteArt.String(),
|
Art: biteArt.String(),
|
||||||
|
IArt: biteIArt.String(),
|
||||||
Tab: biteTab.String(),
|
Tab: biteTab.String(),
|
||||||
NFlip: biteFlip.String(),
|
NFlip: biteFlip.String(),
|
||||||
IArt: biteIArt.String(),
|
LogIndex: EthBiteLog.Index,
|
||||||
TransactionIndex: EthBiteLog.TxIndex,
|
TransactionIndex: EthBiteLog.TxIndex,
|
||||||
Raw: biteRawString,
|
Raw: biteRawString,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user