Add log index to Dent
This commit is contained in:
parent
1aafb7201e
commit
e5ba0496a6
@ -6,7 +6,8 @@ CREATE TABLE maker.dent (
|
||||
bid NUMERIC,
|
||||
guy BYTEA,
|
||||
tic NUMERIC,
|
||||
tx_idx INTEGER NOT NUll,
|
||||
log_idx INTEGER NOT NUll,
|
||||
tx_idx INTEGER NOT NUll,
|
||||
raw_log JSONB,
|
||||
UNIQUE (header_id, tx_idx)
|
||||
UNIQUE (header_id, tx_idx, log_idx)
|
||||
);
|
||||
|
@ -248,6 +248,7 @@ CREATE TABLE maker.dent (
|
||||
bid numeric,
|
||||
guy bytea,
|
||||
tic numeric,
|
||||
log_idx integer NOT NULL,
|
||||
tx_idx integer NOT NULL,
|
||||
raw_log jsonb
|
||||
);
|
||||
@ -1789,11 +1790,11 @@ ALTER TABLE ONLY maker.deal
|
||||
|
||||
|
||||
--
|
||||
-- Name: dent dent_header_id_tx_idx_key; Type: CONSTRAINT; Schema: maker; Owner: -
|
||||
-- Name: dent dent_header_id_tx_idx_log_idx_key; Type: CONSTRAINT; Schema: maker; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY maker.dent
|
||||
ADD CONSTRAINT dent_header_id_tx_idx_key UNIQUE (header_id, tx_idx);
|
||||
ADD CONSTRAINT dent_header_id_tx_idx_log_idx_key UNIQUE (header_id, tx_idx, log_idx);
|
||||
|
||||
|
||||
--
|
||||
|
@ -48,6 +48,7 @@ func (c DentConverter) ToModels(ethLogs []types.Log) (result []DentModel, err er
|
||||
//TODO: it is likely that the tic value will need to be added to an emitted event,
|
||||
//so this will need to be updated at that point
|
||||
|
||||
logIndex := log.Index
|
||||
transactionIndex := log.TxIndex
|
||||
|
||||
raw, err := json.Marshal(log)
|
||||
@ -61,6 +62,7 @@ func (c DentConverter) ToModels(ethLogs []types.Log) (result []DentModel, err er
|
||||
Bid: bidValue,
|
||||
Guy: guy,
|
||||
Tic: tic,
|
||||
LogIndex: logIndex,
|
||||
TransactionIndex: transactionIndex,
|
||||
Raw: raw,
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ type DentModel struct {
|
||||
Bid string
|
||||
Guy string
|
||||
Tic string
|
||||
LogIndex uint `db:"log_idx"`
|
||||
TransactionIndex uint `db:"tx_idx"`
|
||||
Raw []byte `db:"raw_log"`
|
||||
}
|
||||
|
@ -40,9 +40,9 @@ func (r DentRepository) Create(headerId int64, models []DentModel) error {
|
||||
}
|
||||
for _, model := range models {
|
||||
_, err = tx.Exec(
|
||||
`INSERT into maker.dent (header_id, bid_id, lot, bid, guy, tic, tx_idx, raw_log)
|
||||
VALUES($1, $2, $3, $4, $5, $6, $7, $8)`,
|
||||
headerId, model.BidId, model.Lot, model.Bid, model.Guy, model.Tic, model.TransactionIndex, model.Raw,
|
||||
`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, model.BidId, model.Lot, model.Bid, model.Guy, model.Tic, model.LogIndex, model.TransactionIndex, model.Raw,
|
||||
)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
|
@ -59,13 +59,14 @@ var _ = Describe("Dent Repository", func() {
|
||||
Expect(count).To(Equal(1))
|
||||
|
||||
var dbResult dent.DentModel
|
||||
err = db.Get(&dbResult, `SELECT bid_id, lot, bid, guy, tic, tx_idx, raw_log FROM maker.dent WHERE header_id = $1`, headerId)
|
||||
err = db.Get(&dbResult, `SELECT bid_id, lot, bid, guy, tic, log_idx, tx_idx, raw_log FROM maker.dent WHERE header_id = $1`, headerId)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(dbResult.BidId).To(Equal(test_data.DentModel.BidId))
|
||||
Expect(dbResult.Lot).To(Equal(test_data.DentModel.Lot))
|
||||
Expect(dbResult.Bid).To(Equal(test_data.DentModel.Bid))
|
||||
Expect(dbResult.Guy).To(Equal(test_data.DentModel.Guy))
|
||||
Expect(dbResult.Tic).To(Equal(test_data.DentModel.Tic))
|
||||
Expect(dbResult.LogIndex).To(Equal(test_data.DentModel.LogIndex))
|
||||
Expect(dbResult.TransactionIndex).To(Equal(test_data.DentModel.TransactionIndex))
|
||||
Expect(dbResult.Raw).To(MatchJSON(test_data.DentModel.Raw))
|
||||
})
|
||||
|
@ -59,6 +59,7 @@ var DentModel = dent.DentModel{
|
||||
Bid: dentBid,
|
||||
Guy: dentGuy,
|
||||
Tic: DentTic,
|
||||
LogIndex: DentLog.Index,
|
||||
TransactionIndex: DentLog.TxIndex,
|
||||
Raw: dentRawJson,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user