Add log index to Drip file events

This commit is contained in:
Rob Mulholand 2018-10-19 15:30:07 -05:00
parent de294ad8ea
commit d87fb14c6b
15 changed files with 52 additions and 34 deletions

View File

@ -1,12 +1,13 @@
CREATE TABLE maker.drip_file_ilk (
id SERIAL PRIMARY KEY,
header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE,
ilk TEXT,
vow TEXT,
tax NUMERIC,
tx_idx INTEGER NOT NUll,
raw_log JSONB,
UNIQUE (header_id, tx_idx)
id SERIAL PRIMARY KEY,
header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE,
ilk TEXT,
vow TEXT,
tax NUMERIC,
log_idx INTEGER NOT NUll,
tx_idx INTEGER NOT NUll,
raw_log JSONB,
UNIQUE (header_id, tx_idx, log_idx)
);
CREATE TABLE maker.drip_file_repo (
@ -14,9 +15,10 @@ CREATE TABLE maker.drip_file_repo (
header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE,
what TEXT,
data NUMERIC,
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)
);
CREATE TABLE maker.drip_file_vow (
@ -24,7 +26,8 @@ CREATE TABLE maker.drip_file_vow (
header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE,
what TEXT,
data TEXT,
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)
);

View File

@ -318,6 +318,7 @@ CREATE TABLE maker.drip_file_ilk (
ilk text,
vow text,
tax numeric,
log_idx integer NOT NULL,
tx_idx integer NOT NULL,
raw_log jsonb
);
@ -352,6 +353,7 @@ CREATE TABLE maker.drip_file_repo (
header_id integer NOT NULL,
what text,
data numeric,
log_idx integer NOT NULL,
tx_idx integer NOT NULL,
raw_log jsonb
);
@ -386,6 +388,7 @@ CREATE TABLE maker.drip_file_vow (
header_id integer NOT NULL,
what text,
data text,
log_idx integer NOT NULL,
tx_idx integer NOT NULL,
raw_log jsonb
);
@ -1823,11 +1826,11 @@ ALTER TABLE ONLY maker.drip_drip
--
-- Name: drip_file_ilk drip_file_ilk_header_id_tx_idx_key; Type: CONSTRAINT; Schema: maker; Owner: -
-- Name: drip_file_ilk drip_file_ilk_header_id_tx_idx_log_idx_key; Type: CONSTRAINT; Schema: maker; Owner: -
--
ALTER TABLE ONLY maker.drip_file_ilk
ADD CONSTRAINT drip_file_ilk_header_id_tx_idx_key UNIQUE (header_id, tx_idx);
ADD CONSTRAINT drip_file_ilk_header_id_tx_idx_log_idx_key UNIQUE (header_id, tx_idx, log_idx);
--
@ -1839,11 +1842,11 @@ ALTER TABLE ONLY maker.drip_file_ilk
--
-- Name: drip_file_repo drip_file_repo_header_id_tx_idx_key; Type: CONSTRAINT; Schema: maker; Owner: -
-- Name: drip_file_repo drip_file_repo_header_id_tx_idx_log_idx_key; Type: CONSTRAINT; Schema: maker; Owner: -
--
ALTER TABLE ONLY maker.drip_file_repo
ADD CONSTRAINT drip_file_repo_header_id_tx_idx_key UNIQUE (header_id, tx_idx);
ADD CONSTRAINT drip_file_repo_header_id_tx_idx_log_idx_key UNIQUE (header_id, tx_idx, log_idx);
--
@ -1855,11 +1858,11 @@ ALTER TABLE ONLY maker.drip_file_repo
--
-- Name: drip_file_vow drip_file_vow_header_id_tx_idx_key; Type: CONSTRAINT; Schema: maker; Owner: -
-- Name: drip_file_vow drip_file_vow_header_id_tx_idx_log_idx_key; Type: CONSTRAINT; Schema: maker; Owner: -
--
ALTER TABLE ONLY maker.drip_file_vow
ADD CONSTRAINT drip_file_vow_header_id_tx_idx_key UNIQUE (header_id, tx_idx);
ADD CONSTRAINT drip_file_vow_header_id_tx_idx_log_idx_key UNIQUE (header_id, tx_idx, log_idx);
--

View File

@ -49,6 +49,7 @@ func (DripFileIlkConverter) ToModels(ethLogs []types.Log) ([]DripFileIlkModel, e
Ilk: ilk,
Vow: vow,
Tax: tax,
LogIndex: ethLog.Index,
TransactionIndex: ethLog.TxIndex,
Raw: raw,
}

View File

@ -18,6 +18,7 @@ type DripFileIlkModel struct {
Ilk string
Vow string
Tax string
LogIndex uint `db:"log_idx"`
TransactionIndex uint `db:"tx_idx"`
Raw []byte `db:"raw_log"`
}

View File

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

View File

@ -58,11 +58,12 @@ var _ = Describe("Drip file ilk repository", func() {
It("adds a drip file ilk event", func() {
var dbDripFileIlk ilk.DripFileIlkModel
err = db.Get(&dbDripFileIlk, `SELECT ilk, vow, tax, tx_idx, raw_log FROM maker.drip_file_ilk WHERE header_id = $1`, headerID)
err = db.Get(&dbDripFileIlk, `SELECT ilk, vow, tax, log_idx, tx_idx, raw_log FROM maker.drip_file_ilk WHERE header_id = $1`, headerID)
Expect(err).NotTo(HaveOccurred())
Expect(dbDripFileIlk.Ilk).To(Equal(test_data.DripFileIlkModel.Ilk))
Expect(dbDripFileIlk.Vow).To(Equal(test_data.DripFileIlkModel.Vow))
Expect(dbDripFileIlk.Tax).To(Equal(test_data.DripFileIlkModel.Tax))
Expect(dbDripFileIlk.LogIndex).To(Equal(test_data.DripFileIlkModel.LogIndex))
Expect(dbDripFileIlk.TransactionIndex).To(Equal(test_data.DripFileIlkModel.TransactionIndex))
Expect(dbDripFileIlk.Raw).To(MatchJSON(test_data.DripFileIlkModel.Raw))
})
@ -87,7 +88,7 @@ var _ = Describe("Drip file ilk repository", func() {
Expect(err).NotTo(HaveOccurred())
var dbDripFileIlk ilk.DripFileIlkModel
err = db.Get(&dbDripFileIlk, `SELECT ilk, vow, tax, tx_idx, raw_log FROM maker.drip_file_ilk WHERE header_id = $1`, headerID)
err = db.Get(&dbDripFileIlk, `SELECT ilk, vow, tax, log_idx, tx_idx, raw_log FROM maker.drip_file_ilk WHERE header_id = $1`, headerID)
Expect(err).To(HaveOccurred())
Expect(err).To(MatchError(sql.ErrNoRows))
})

View File

@ -44,6 +44,7 @@ func (DripFileRepoConverter) ToModels(ethLogs []types.Log) ([]DripFileRepoModel,
model := DripFileRepoModel{
What: what,
Data: data,
LogIndex: ethLog.Index,
TransactionIndex: ethLog.TxIndex,
Raw: raw,
}

View File

@ -17,6 +17,7 @@ package repo
type DripFileRepoModel struct {
What string
Data string
LogIndex uint `db:"log_idx"`
TransactionIndex uint `db:"tx_idx"`
Raw []byte `db:"raw_log"`
}

View File

@ -40,9 +40,9 @@ func (repository DripFileRepoRepository) Create(headerID int64, models []DripFil
}
for _, model := range models {
_, err = tx.Exec(
`INSERT into maker.drip_file_repo (header_id, what, data, tx_idx, raw_log)
VALUES($1, $2, $3::NUMERIC, $4, $5)`,
headerID, model.What, model.Data, model.TransactionIndex, model.Raw,
`INSERT into maker.drip_file_repo (header_id, what, data, log_idx, tx_idx, raw_log)
VALUES($1, $2, $3::NUMERIC, $4, $5, $6)`,
headerID, model.What, model.Data, model.LogIndex, model.TransactionIndex, model.Raw,
)
if err != nil {
tx.Rollback()

View File

@ -58,10 +58,11 @@ var _ = Describe("Drip file repo repository", func() {
It("adds a drip file repo event", func() {
var dbDripFileRepo repo.DripFileRepoModel
err = db.Get(&dbDripFileRepo, `SELECT what, data, tx_idx, raw_log FROM maker.drip_file_repo WHERE header_id = $1`, headerID)
err = db.Get(&dbDripFileRepo, `SELECT what, data, log_idx, tx_idx, raw_log FROM maker.drip_file_repo WHERE header_id = $1`, headerID)
Expect(err).NotTo(HaveOccurred())
Expect(dbDripFileRepo.What).To(Equal(test_data.DripFileRepoModel.What))
Expect(dbDripFileRepo.Data).To(Equal(test_data.DripFileRepoModel.Data))
Expect(dbDripFileRepo.LogIndex).To(Equal(test_data.DripFileRepoModel.LogIndex))
Expect(dbDripFileRepo.TransactionIndex).To(Equal(test_data.DripFileRepoModel.TransactionIndex))
Expect(dbDripFileRepo.Raw).To(MatchJSON(test_data.DripFileRepoModel.Raw))
})
@ -85,7 +86,7 @@ var _ = Describe("Drip file repo repository", func() {
Expect(err).NotTo(HaveOccurred())
var dbDripFileRepo repo.DripFileRepoModel
err = db.Get(&dbDripFileRepo, `SELECT what, data, tx_idx, raw_log FROM maker.drip_file_repo WHERE header_id = $1`, headerID)
err = db.Get(&dbDripFileRepo, `SELECT what, data, log_idx, tx_idx, raw_log FROM maker.drip_file_repo WHERE header_id = $1`, headerID)
Expect(err).To(HaveOccurred())
Expect(err).To(MatchError(sql.ErrNoRows))
})

View File

@ -44,6 +44,7 @@ func (DripFileVowConverter) ToModels(ethLogs []types.Log) ([]DripFileVowModel, e
model := DripFileVowModel{
What: what,
Data: data,
LogIndex: ethLog.Index,
TransactionIndex: ethLog.TxIndex,
Raw: raw,
}

View File

@ -17,6 +17,7 @@ package vow
type DripFileVowModel struct {
What string
Data string
LogIndex uint `db:"log_idx"`
TransactionIndex uint `db:"tx_idx"`
Raw []byte `db:"raw_log"`
}

View File

@ -40,9 +40,9 @@ func (repository DripFileVowRepository) Create(headerID int64, models []DripFile
}
for _, model := range models {
_, err = tx.Exec(
`INSERT into maker.drip_file_vow (header_id, what, data, tx_idx, raw_log)
VALUES($1, $2, $3, $4, $5)`,
headerID, model.What, model.Data, model.TransactionIndex, model.Raw,
`INSERT into maker.drip_file_vow (header_id, what, data, log_idx, tx_idx, raw_log)
VALUES($1, $2, $3, $4, $5, $6)`,
headerID, model.What, model.Data, model.LogIndex, model.TransactionIndex, model.Raw,
)
if err != nil {
tx.Rollback()

View File

@ -58,10 +58,11 @@ var _ = Describe("Drip file vow repository", func() {
It("adds a drip file vow event", func() {
var dbDripFileVow vow.DripFileVowModel
err = db.Get(&dbDripFileVow, `SELECT what, data, tx_idx, raw_log FROM maker.drip_file_vow WHERE header_id = $1`, headerID)
err = db.Get(&dbDripFileVow, `SELECT what, data, log_idx, tx_idx, raw_log FROM maker.drip_file_vow WHERE header_id = $1`, headerID)
Expect(err).NotTo(HaveOccurred())
Expect(dbDripFileVow.What).To(Equal(test_data.DripFileVowModel.What))
Expect(dbDripFileVow.Data).To(Equal(test_data.DripFileVowModel.Data))
Expect(dbDripFileVow.LogIndex).To(Equal(test_data.DripFileVowModel.LogIndex))
Expect(dbDripFileVow.TransactionIndex).To(Equal(test_data.DripFileVowModel.TransactionIndex))
Expect(dbDripFileVow.Raw).To(MatchJSON(test_data.DripFileVowModel.Raw))
})
@ -85,7 +86,7 @@ var _ = Describe("Drip file vow repository", func() {
Expect(err).NotTo(HaveOccurred())
var dbDripFileVow vow.DripFileVowModel
err = db.Get(&dbDripFileVow, `SELECT what, data, tx_idx, raw_log FROM maker.drip_file_vow WHERE header_id = $1`, headerID)
err = db.Get(&dbDripFileVow, `SELECT what, data, log_idx, tx_idx, raw_log FROM maker.drip_file_vow WHERE header_id = $1`, headerID)
Expect(err).To(HaveOccurred())
Expect(err).To(MatchError(sql.ErrNoRows))
})

View File

@ -39,7 +39,7 @@ var EthDripFileIlkLog = types.Log{
TxHash: common.HexToHash("0xa1c31b7e6389470902237161263558615e60b40f2e63060b2f4aeafe92d57e5f"),
TxIndex: 12,
BlockHash: common.HexToHash("0x0188f3ee3cc05aa72457fa328e6a461de31e4cbd429fc37f9a52da4e9773c0b4"),
Index: 0,
Index: 15,
Removed: false,
}
@ -48,6 +48,7 @@ var DripFileIlkModel = ilk2.DripFileIlkModel{
Ilk: "fake ilk",
Vow: "fake vow",
Tax: big.NewInt(123).String(),
LogIndex: EthDripFileIlkLog.Index,
TransactionIndex: EthDripFileIlkLog.TxIndex,
Raw: rawDripFileIlkLog,
}
@ -65,7 +66,7 @@ var EthDripFileRepoLog = types.Log{
TxHash: common.HexToHash("0xeeaa16de1d91c239b66773e8c2116a26cfeaaf5d962b31466c9bf047a5caa20f"),
TxIndex: 13,
BlockHash: common.HexToHash("0x89de4145ea8e34dfd9db9a7ea34f5be6f1f402e812fd389acca342513b353288"),
Index: 0,
Index: 16,
Removed: false,
}
@ -73,6 +74,7 @@ var rawDripFileRepoLog, _ = json.Marshal(EthDripFileRepoLog)
var DripFileRepoModel = repo.DripFileRepoModel{
What: "fake what",
Data: big.NewInt(123).String(),
LogIndex: EthDripFileRepoLog.Index,
TransactionIndex: EthDripFileRepoLog.TxIndex,
Raw: rawDripFileRepoLog,
}
@ -90,7 +92,7 @@ var EthDripFileVowLog = types.Log{
TxHash: common.HexToHash("0x586e26b71b41fcd6905044dbe8f0cca300517542278f74a9b925c4f800fed85c"),
TxIndex: 14,
BlockHash: common.HexToHash("0xbec69b1e93503679c9c006819477b86fe16aaff3a418da1e916c431b68be5522"),
Index: 0,
Index: 17,
Removed: false,
}
@ -98,6 +100,7 @@ var rawDripFileVowLog, _ = json.Marshal(EthDripFileVowLog)
var DripFileVowModel = vow.DripFileVowModel{
What: "vow",
Data: "0x3728e9777B2a0a611ee0F89e00E01044ce4736d1",
LogIndex: EthDripFileVowLog.Index,
TransactionIndex: EthDripFileVowLog.TxIndex,
Raw: rawDripFileVowLog,
}