Add log index to Drip drip

This commit is contained in:
Rob Mulholand 2018-10-19 11:55:53 -05:00
parent e5ba0496a6
commit de294ad8ea
7 changed files with 16 additions and 10 deletions

View File

@ -2,7 +2,8 @@ CREATE TABLE maker.drip_drip (
id SERIAL PRIMARY KEY, id SERIAL PRIMARY KEY,
header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE, header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE,
ilk TEXT, ilk TEXT,
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)
); );

View File

@ -282,6 +282,7 @@ CREATE TABLE maker.drip_drip (
id integer NOT NULL, id integer NOT NULL,
header_id integer NOT NULL, header_id integer NOT NULL,
ilk text, ilk text,
log_idx integer NOT NULL,
tx_idx integer NOT NULL, tx_idx integer NOT NULL,
raw_log jsonb 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 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);
-- --

View File

@ -41,6 +41,7 @@ func (DripDripConverter) ToModels(ethLogs []types.Log) ([]DripDripModel, error)
} }
model := DripDripModel{ model := DripDripModel{
Ilk: ilk, Ilk: ilk,
LogIndex: ethLog.Index,
TransactionIndex: ethLog.TxIndex, TransactionIndex: ethLog.TxIndex,
Raw: raw, Raw: raw,
} }

View File

@ -16,6 +16,7 @@ package drip_drip
type DripDripModel struct { type DripDripModel struct {
Ilk string Ilk 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"`
} }

View File

@ -40,9 +40,9 @@ func (repository DripDripRepository) Create(headerID int64, models []DripDripMod
} }
for _, model := range models { for _, model := range models {
_, err = tx.Exec( _, err = tx.Exec(
`INSERT into maker.drip_drip (header_id, ilk, tx_idx, raw_log) `INSERT into maker.drip_drip (header_id, ilk, log_idx, tx_idx, raw_log)
VALUES($1, $2, $3, $4)`, VALUES($1, $2, $3, $4, $5)`,
headerID, model.Ilk, model.TransactionIndex, model.Raw, headerID, model.Ilk, model.LogIndex, model.TransactionIndex, model.Raw,
) )
if err != nil { if err != nil {
tx.Rollback() tx.Rollback()

View File

@ -58,9 +58,10 @@ var _ = Describe("Drip drip repository", func() {
It("adds a drip drip event", func() { It("adds a drip drip event", func() {
var dbDripDrip drip_drip.DripDripModel 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(err).NotTo(HaveOccurred())
Expect(dbDripDrip.Ilk).To(Equal(test_data.DripDripModel.Ilk)) 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.TransactionIndex).To(Equal(test_data.DripDripModel.TransactionIndex))
Expect(dbDripDrip.Raw).To(MatchJSON(test_data.DripDripModel.Raw)) Expect(dbDripDrip.Raw).To(MatchJSON(test_data.DripDripModel.Raw))
}) })
@ -84,7 +85,7 @@ var _ = Describe("Drip drip repository", func() {
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
var dbDripDrip drip_drip.DripDripModel 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(HaveOccurred())
Expect(err).To(MatchError(sql.ErrNoRows)) Expect(err).To(MatchError(sql.ErrNoRows))
}) })

View File

@ -36,13 +36,14 @@ var EthDripDripLog = types.Log{
TxHash: common.HexToHash("0xa34fd5cfcb125ebfc81d33633495701b531753669712092bdb8aa6159a240040"), TxHash: common.HexToHash("0xa34fd5cfcb125ebfc81d33633495701b531753669712092bdb8aa6159a240040"),
TxIndex: 10, TxIndex: 10,
BlockHash: common.HexToHash("0x7a2aa72468986774d90dc8c80d436956a5b6a7e5acea430fb8a79f9217ef00a3"), BlockHash: common.HexToHash("0x7a2aa72468986774d90dc8c80d436956a5b6a7e5acea430fb8a79f9217ef00a3"),
Index: 0, Index: 11,
Removed: false, Removed: false,
} }
var rawDripDripLog, _ = json.Marshal(EthDripDripLog) var rawDripDripLog, _ = json.Marshal(EthDripDripLog)
var DripDripModel = drip_drip.DripDripModel{ var DripDripModel = drip_drip.DripDripModel{
Ilk: "fake ilk", Ilk: "fake ilk",
LogIndex: EthDripDripLog.Index,
TransactionIndex: EthDripDripLog.TxIndex, TransactionIndex: EthDripDripLog.TxIndex,
Raw: rawDripDripLog, Raw: rawDripDripLog,
} }