diff --git a/db/migrations/1536710319_create_drip_drip_table.up.sql b/db/migrations/1536710319_create_drip_drip_table.up.sql index 58c26273..4e325f3e 100644 --- a/db/migrations/1536710319_create_drip_drip_table.up.sql +++ b/db/migrations/1536710319_create_drip_drip_table.up.sql @@ -2,7 +2,8 @@ CREATE TABLE maker.drip_drip ( id SERIAL PRIMARY KEY, header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE, ilk TEXT, - 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) ); \ No newline at end of file diff --git a/db/schema.sql b/db/schema.sql index ae6f7182..c075cc33 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -282,6 +282,7 @@ CREATE TABLE maker.drip_drip ( id integer NOT NULL, header_id integer NOT NULL, ilk text, + log_idx integer NOT NULL, tx_idx integer NOT NULL, raw_log jsonb ); @@ -1806,11 +1807,11 @@ ALTER TABLE ONLY maker.dent -- --- Name: drip_drip drip_drip_header_id_tx_idx_key; Type: CONSTRAINT; Schema: maker; Owner: - +-- Name: drip_drip drip_drip_header_id_tx_idx_log_idx_key; Type: CONSTRAINT; Schema: maker; Owner: - -- ALTER TABLE ONLY maker.drip_drip - ADD CONSTRAINT drip_drip_header_id_tx_idx_key UNIQUE (header_id, tx_idx); + ADD CONSTRAINT drip_drip_header_id_tx_idx_log_idx_key UNIQUE (header_id, tx_idx, log_idx); -- diff --git a/pkg/transformers/drip_drip/converter.go b/pkg/transformers/drip_drip/converter.go index 0a7473a1..1dbb3306 100644 --- a/pkg/transformers/drip_drip/converter.go +++ b/pkg/transformers/drip_drip/converter.go @@ -41,6 +41,7 @@ func (DripDripConverter) ToModels(ethLogs []types.Log) ([]DripDripModel, error) } model := DripDripModel{ Ilk: ilk, + LogIndex: ethLog.Index, TransactionIndex: ethLog.TxIndex, Raw: raw, } diff --git a/pkg/transformers/drip_drip/model.go b/pkg/transformers/drip_drip/model.go index 6461a036..f6cc1522 100644 --- a/pkg/transformers/drip_drip/model.go +++ b/pkg/transformers/drip_drip/model.go @@ -16,6 +16,7 @@ package drip_drip type DripDripModel struct { Ilk string + LogIndex uint `db:"log_idx"` TransactionIndex uint `db:"tx_idx"` Raw []byte `db:"raw_log"` } diff --git a/pkg/transformers/drip_drip/repository.go b/pkg/transformers/drip_drip/repository.go index 23881f34..864aea45 100644 --- a/pkg/transformers/drip_drip/repository.go +++ b/pkg/transformers/drip_drip/repository.go @@ -40,9 +40,9 @@ func (repository DripDripRepository) Create(headerID int64, models []DripDripMod } for _, model := range models { _, err = tx.Exec( - `INSERT into maker.drip_drip (header_id, ilk, tx_idx, raw_log) - VALUES($1, $2, $3, $4)`, - headerID, model.Ilk, model.TransactionIndex, model.Raw, + `INSERT into maker.drip_drip (header_id, ilk, log_idx, tx_idx, raw_log) + VALUES($1, $2, $3, $4, $5)`, + headerID, model.Ilk, model.LogIndex, model.TransactionIndex, model.Raw, ) if err != nil { tx.Rollback() diff --git a/pkg/transformers/drip_drip/repository_test.go b/pkg/transformers/drip_drip/repository_test.go index 4be60cec..78a2552b 100644 --- a/pkg/transformers/drip_drip/repository_test.go +++ b/pkg/transformers/drip_drip/repository_test.go @@ -58,9 +58,10 @@ var _ = Describe("Drip drip repository", func() { It("adds a drip drip event", func() { var dbDripDrip drip_drip.DripDripModel - err = db.Get(&dbDripDrip, `SELECT ilk, tx_idx, raw_log FROM maker.drip_drip WHERE header_id = $1`, headerID) + err = db.Get(&dbDripDrip, `SELECT ilk, log_idx, tx_idx, raw_log FROM maker.drip_drip WHERE header_id = $1`, headerID) Expect(err).NotTo(HaveOccurred()) Expect(dbDripDrip.Ilk).To(Equal(test_data.DripDripModel.Ilk)) + Expect(dbDripDrip.LogIndex).To(Equal(test_data.DripDripModel.LogIndex)) Expect(dbDripDrip.TransactionIndex).To(Equal(test_data.DripDripModel.TransactionIndex)) Expect(dbDripDrip.Raw).To(MatchJSON(test_data.DripDripModel.Raw)) }) @@ -84,7 +85,7 @@ var _ = Describe("Drip drip repository", func() { Expect(err).NotTo(HaveOccurred()) var dbDripDrip drip_drip.DripDripModel - err = db.Get(&dbDripDrip, `SELECT ilk, tx_idx, raw_log FROM maker.drip_drip WHERE header_id = $1`, headerID) + err = db.Get(&dbDripDrip, `SELECT ilk, log_idx, tx_idx, raw_log FROM maker.drip_drip WHERE header_id = $1`, headerID) Expect(err).To(HaveOccurred()) Expect(err).To(MatchError(sql.ErrNoRows)) }) diff --git a/pkg/transformers/test_data/drip_drip.go b/pkg/transformers/test_data/drip_drip.go index 20b45739..3166b47a 100644 --- a/pkg/transformers/test_data/drip_drip.go +++ b/pkg/transformers/test_data/drip_drip.go @@ -36,13 +36,14 @@ var EthDripDripLog = types.Log{ TxHash: common.HexToHash("0xa34fd5cfcb125ebfc81d33633495701b531753669712092bdb8aa6159a240040"), TxIndex: 10, BlockHash: common.HexToHash("0x7a2aa72468986774d90dc8c80d436956a5b6a7e5acea430fb8a79f9217ef00a3"), - Index: 0, + Index: 11, Removed: false, } var rawDripDripLog, _ = json.Marshal(EthDripDripLog) var DripDripModel = drip_drip.DripDripModel{ Ilk: "fake ilk", + LogIndex: EthDripDripLog.Index, TransactionIndex: EthDripDripLog.TxIndex, Raw: rawDripDripLog, }