Add log index to Vat grab
This commit is contained in:
parent
1e74c73591
commit
650bbf5874
@ -7,9 +7,10 @@ CREATE TABLE maker.vat_grab (
|
|||||||
w TEXT,
|
w TEXT,
|
||||||
dink NUMERIC,
|
dink NUMERIC,
|
||||||
dart NUMERIC,
|
dart NUMERIC,
|
||||||
|
log_idx INTEGER NOT NULL,
|
||||||
tx_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)
|
||||||
);
|
);
|
||||||
|
|
||||||
ALTER TABLE public.checked_headers
|
ALTER TABLE public.checked_headers
|
||||||
|
@ -798,6 +798,7 @@ CREATE TABLE maker.vat_grab (
|
|||||||
w text,
|
w text,
|
||||||
dink numeric,
|
dink numeric,
|
||||||
dart numeric,
|
dart numeric,
|
||||||
|
log_idx integer NOT NULL,
|
||||||
tx_idx integer NOT NULL,
|
tx_idx integer NOT NULL,
|
||||||
raw_log jsonb
|
raw_log jsonb
|
||||||
);
|
);
|
||||||
@ -2044,11 +2045,11 @@ ALTER TABLE ONLY maker.vat_fold
|
|||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Name: vat_grab vat_grab_header_id_tx_idx_key; Type: CONSTRAINT; Schema: maker; Owner: -
|
-- Name: vat_grab vat_grab_header_id_tx_idx_log_idx_key; Type: CONSTRAINT; Schema: maker; Owner: -
|
||||||
--
|
--
|
||||||
|
|
||||||
ALTER TABLE ONLY maker.vat_grab
|
ALTER TABLE ONLY maker.vat_grab
|
||||||
ADD CONSTRAINT vat_grab_header_id_tx_idx_key UNIQUE (header_id, tx_idx);
|
ADD CONSTRAINT vat_grab_header_id_tx_idx_log_idx_key UNIQUE (header_id, tx_idx, log_idx);
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
|
@ -22,7 +22,7 @@ var EthVatGrabLog = types.Log{
|
|||||||
TxHash: common.HexToHash("0x7cb84c750ce4985f7811abf641d52ffcb35306d943081475226484cf1470c6fa"),
|
TxHash: common.HexToHash("0x7cb84c750ce4985f7811abf641d52ffcb35306d943081475226484cf1470c6fa"),
|
||||||
TxIndex: 4,
|
TxIndex: 4,
|
||||||
BlockHash: common.HexToHash("0xf5a367d560e14c4658ef85e4877e08b5560a4773b69b39f6b8025910b666fade"),
|
BlockHash: common.HexToHash("0xf5a367d560e14c4658ef85e4877e08b5560a4773b69b39f6b8025910b666fade"),
|
||||||
Index: 0,
|
Index: 5,
|
||||||
Removed: false,
|
Removed: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,6 +34,7 @@ var VatGrabModel = vat_grab.VatGrabModel{
|
|||||||
W: "0x3728e9777B2a0a611ee0F89e00E01044ce4736d1",
|
W: "0x3728e9777B2a0a611ee0F89e00E01044ce4736d1",
|
||||||
Dink: "115792089237316195423570985008687907853269984665640564039455584007913129639936",
|
Dink: "115792089237316195423570985008687907853269984665640564039455584007913129639936",
|
||||||
Dart: "115792089237316195423570985008687907853269984665640564039441803007913129639936",
|
Dart: "115792089237316195423570985008687907853269984665640564039441803007913129639936",
|
||||||
|
LogIndex: EthVatGrabLog.Index,
|
||||||
TransactionIndex: EthVatGrabLog.TxIndex,
|
TransactionIndex: EthVatGrabLog.TxIndex,
|
||||||
Raw: rawVatGrabLog,
|
Raw: rawVatGrabLog,
|
||||||
}
|
}
|
||||||
|
@ -44,6 +44,7 @@ func (VatGrabConverter) ToModels(ethLogs []types.Log) ([]VatGrabModel, error) {
|
|||||||
W: w.String(),
|
W: w.String(),
|
||||||
Dink: dink,
|
Dink: dink,
|
||||||
Dart: dart,
|
Dart: dart,
|
||||||
|
LogIndex: ethLog.Index,
|
||||||
TransactionIndex: ethLog.TxIndex,
|
TransactionIndex: ethLog.TxIndex,
|
||||||
Raw: raw,
|
Raw: raw,
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ type VatGrabModel struct {
|
|||||||
W string
|
W string
|
||||||
Dink string
|
Dink string
|
||||||
Dart string
|
Dart 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"`
|
||||||
}
|
}
|
||||||
|
@ -28,9 +28,9 @@ func (repository VatGrabRepository) Create(headerID int64, models []VatGrabModel
|
|||||||
}
|
}
|
||||||
for _, model := range models {
|
for _, model := range models {
|
||||||
_, err = tx.Exec(
|
_, err = tx.Exec(
|
||||||
`INSERT into maker.vat_grab (header_id, ilk, urn, v, w, dink, dart, tx_idx, raw_log)
|
`INSERT into maker.vat_grab (header_id, ilk, urn, v, w, dink, dart, log_idx, tx_idx, raw_log)
|
||||||
VALUES($1, $2, $3, $4, $5, $6::NUMERIC, $7::NUMERIC, $8, $9)`,
|
VALUES($1, $2, $3, $4, $5, $6::NUMERIC, $7::NUMERIC, $8, $9, $10)`,
|
||||||
headerID, model.Ilk, model.Urn, model.V, model.W, model.Dink, model.Dart, model.TransactionIndex, model.Raw,
|
headerID, model.Ilk, model.Urn, model.V, model.W, model.Dink, model.Dart, model.LogIndex, model.TransactionIndex, model.Raw,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
|
@ -37,14 +37,14 @@ var _ = Describe("Vat grab repository", func() {
|
|||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
headerID, err = headerRepository.CreateOrUpdateHeader(fakes.FakeHeader)
|
headerID, err = headerRepository.CreateOrUpdateHeader(fakes.FakeHeader)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
err = vatGrabRepository.Create(headerID, []vat_grab.VatGrabModel{test_data.VatGrabModel})
|
|
||||||
Expect(err).NotTo(HaveOccurred())
|
|
||||||
})
|
})
|
||||||
|
|
||||||
It("adds a vat grab event", func() {
|
It("adds a vat grab event", func() {
|
||||||
|
err = vatGrabRepository.Create(headerID, []vat_grab.VatGrabModel{test_data.VatGrabModel})
|
||||||
|
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
var dbVatGrab vat_grab.VatGrabModel
|
var dbVatGrab vat_grab.VatGrabModel
|
||||||
err = db.Get(&dbVatGrab, `SELECT ilk, urn, v, w, dink, dart, tx_idx, raw_log FROM maker.vat_grab WHERE header_id = $1`, headerID)
|
err = db.Get(&dbVatGrab, `SELECT ilk, urn, v, w, dink, dart, log_idx, tx_idx, raw_log FROM maker.vat_grab WHERE header_id = $1`, headerID)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(dbVatGrab.Ilk).To(Equal(test_data.VatGrabModel.Ilk))
|
Expect(dbVatGrab.Ilk).To(Equal(test_data.VatGrabModel.Ilk))
|
||||||
Expect(dbVatGrab.Urn).To(Equal(test_data.VatGrabModel.Urn))
|
Expect(dbVatGrab.Urn).To(Equal(test_data.VatGrabModel.Urn))
|
||||||
@ -52,30 +52,53 @@ var _ = Describe("Vat grab repository", func() {
|
|||||||
Expect(dbVatGrab.W).To(Equal(test_data.VatGrabModel.W))
|
Expect(dbVatGrab.W).To(Equal(test_data.VatGrabModel.W))
|
||||||
Expect(dbVatGrab.Dink).To(Equal(test_data.VatGrabModel.Dink))
|
Expect(dbVatGrab.Dink).To(Equal(test_data.VatGrabModel.Dink))
|
||||||
Expect(dbVatGrab.Dart).To(Equal(test_data.VatGrabModel.Dart))
|
Expect(dbVatGrab.Dart).To(Equal(test_data.VatGrabModel.Dart))
|
||||||
|
Expect(dbVatGrab.LogIndex).To(Equal(test_data.VatGrabModel.LogIndex))
|
||||||
Expect(dbVatGrab.TransactionIndex).To(Equal(test_data.VatGrabModel.TransactionIndex))
|
Expect(dbVatGrab.TransactionIndex).To(Equal(test_data.VatGrabModel.TransactionIndex))
|
||||||
Expect(dbVatGrab.Raw).To(MatchJSON(test_data.VatGrabModel.Raw))
|
Expect(dbVatGrab.Raw).To(MatchJSON(test_data.VatGrabModel.Raw))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("marks header as checked for logs", func() {
|
It("marks header as checked for logs", func() {
|
||||||
|
err = vatGrabRepository.Create(headerID, []vat_grab.VatGrabModel{test_data.VatGrabModel})
|
||||||
|
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
var headerChecked bool
|
var headerChecked bool
|
||||||
err = db.Get(&headerChecked, `SELECT vat_grab_checked FROM public.checked_headers WHERE header_id = $1`, headerID)
|
err = db.Get(&headerChecked, `SELECT vat_grab_checked FROM public.checked_headers WHERE header_id = $1`, headerID)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(headerChecked).To(BeTrue())
|
Expect(headerChecked).To(BeTrue())
|
||||||
})
|
})
|
||||||
|
|
||||||
It("does not duplicate pit file vat_grab events", func() {
|
It("updates the header to checked if checked headers row already exists", func() {
|
||||||
|
_, err = db.Exec(`INSERT INTO public.checked_headers (header_id) VALUES ($1)`, headerID)
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
|
err = vatGrabRepository.Create(headerID, []vat_grab.VatGrabModel{test_data.VatGrabModel})
|
||||||
|
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
var headerChecked bool
|
||||||
|
err = db.Get(&headerChecked, `SELECT vat_grab_checked FROM public.checked_headers WHERE header_id = $1`, headerID)
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
Expect(headerChecked).To(BeTrue())
|
||||||
|
})
|
||||||
|
|
||||||
|
It("does not duplicate vat grab events", func() {
|
||||||
|
err = vatGrabRepository.Create(headerID, []vat_grab.VatGrabModel{test_data.VatGrabModel})
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
err = vatGrabRepository.Create(headerID, []vat_grab.VatGrabModel{test_data.VatGrabModel})
|
err = vatGrabRepository.Create(headerID, []vat_grab.VatGrabModel{test_data.VatGrabModel})
|
||||||
|
|
||||||
Expect(err).To(HaveOccurred())
|
Expect(err).To(HaveOccurred())
|
||||||
Expect(err.Error()).To(ContainSubstring("pq: duplicate key value violates unique constraint"))
|
Expect(err.Error()).To(ContainSubstring("pq: duplicate key value violates unique constraint"))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("removes pit file vat_grab if corresponding header is deleted", func() {
|
It("removes vat grab if corresponding header is deleted", func() {
|
||||||
|
err = vatGrabRepository.Create(headerID, []vat_grab.VatGrabModel{test_data.VatGrabModel})
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
_, err = db.Exec(`DELETE FROM headers WHERE id = $1`, headerID)
|
_, err = db.Exec(`DELETE FROM headers WHERE id = $1`, headerID)
|
||||||
|
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
var dbVatGrab vat_grab.VatGrabModel
|
var dbVatGrab vat_grab.VatGrabModel
|
||||||
err = db.Get(&dbVatGrab, `SELECT ilk, urn, v, w, dink, dart, tx_idx, raw_log FROM maker.vat_grab WHERE header_id = $1`, headerID)
|
err = db.Get(&dbVatGrab, `SELECT ilk, urn, v, w, dink, dart, log_idx, tx_idx, raw_log FROM maker.vat_grab 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))
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user