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