Add log index to Deal

This commit is contained in:
Rob Mulholand 2018-10-19 11:24:46 -05:00
parent 495f39abb8
commit 1aafb7201e
9 changed files with 23 additions and 20 deletions

View File

@ -1,8 +1,10 @@
CREATE TABLE maker.deal ( CREATE TABLE maker.deal (
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,
bid_id NUMERIC NOT NULL, bid_id NUMERIC NOT NULL,
tx_idx INTEGER NOT NUll, contract_address VARCHAR,
raw_log JSONB, log_idx INTEGER NOT NUll,
UNIQUE (header_id, tx_idx) tx_idx INTEGER NOT NUll,
raw_log JSONB,
UNIQUE (header_id, tx_idx, log_idx)
); );

View File

@ -1,2 +0,0 @@
ALTER TABLE maker.deal
DROP COLUMN contract_address;

View File

@ -1,2 +0,0 @@
ALTER TABLE maker.deal
ADD COLUMN contract_address VARCHAR;

View File

@ -209,9 +209,10 @@ CREATE TABLE maker.deal (
id integer NOT NULL, id integer NOT NULL,
header_id integer NOT NULL, header_id integer NOT NULL,
bid_id numeric NOT NULL, bid_id numeric NOT NULL,
contract_address character varying,
log_idx integer NOT NULL,
tx_idx integer NOT NULL, tx_idx integer NOT NULL,
raw_log jsonb, raw_log jsonb
contract_address character varying
); );
@ -1772,11 +1773,11 @@ ALTER TABLE ONLY maker.cat_file_pit_vow
-- --
-- Name: deal deal_header_id_tx_idx_key; Type: CONSTRAINT; Schema: maker; Owner: - -- Name: deal deal_header_id_tx_idx_log_idx_key; Type: CONSTRAINT; Schema: maker; Owner: -
-- --
ALTER TABLE ONLY maker.deal ALTER TABLE ONLY maker.deal
ADD CONSTRAINT deal_header_id_tx_idx_key UNIQUE (header_id, tx_idx); ADD CONSTRAINT deal_header_id_tx_idx_log_idx_key UNIQUE (header_id, tx_idx, log_idx);
-- --

View File

@ -47,6 +47,7 @@ func (DealConverter) ToModels(ethLogs []types.Log) (result []DealModel, err erro
model := DealModel{ model := DealModel{
BidId: bidId.String(), BidId: bidId.String(),
ContractAddress: log.Address.Hex(), ContractAddress: log.Address.Hex(),
LogIndex: log.Index,
TransactionIndex: log.TxIndex, TransactionIndex: log.TxIndex,
Raw: raw, Raw: raw,
} }

View File

@ -17,6 +17,7 @@ package deal
type DealModel struct { type DealModel struct {
BidId string `db:"bid_id"` BidId string `db:"bid_id"`
ContractAddress string `db:"contract_address"` ContractAddress string `db:"contract_address"`
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

@ -38,9 +38,9 @@ func (r DealRepository) Create(headerId int64, models []DealModel) error {
} }
for _, model := range models { for _, model := range models {
_, err = tx.Exec( _, err = tx.Exec(
`INSERT into maker.deal (header_id, bid_id, contract_address, tx_idx, raw_log) `INSERT into maker.deal (header_id, bid_id, contract_address, log_idx, tx_idx, raw_log)
VALUES($1, $2, $3, $4, $5)`, VALUES($1, $2, $3, $4, $5, $6)`,
headerId, model.BidId, model.ContractAddress, model.TransactionIndex, model.Raw, headerId, model.BidId, model.ContractAddress, model.LogIndex, model.TransactionIndex, model.Raw,
) )
if err != nil { if err != nil {
tx.Rollback() tx.Rollback()

View File

@ -57,10 +57,11 @@ var _ = Describe("Deal Repository", func() {
db.QueryRow(`SELECT count(*) FROM maker.deal`).Scan(&count) db.QueryRow(`SELECT count(*) FROM maker.deal`).Scan(&count)
Expect(count).To(Equal(1)) Expect(count).To(Equal(1))
var dbResult deal.DealModel var dbResult deal.DealModel
err = db.Get(&dbResult, `SELECT bid_id, contract_address, tx_idx, raw_log FROM maker.deal WHERE header_id = $1`, headerId) err = db.Get(&dbResult, `SELECT bid_id, contract_address, log_idx, tx_idx, raw_log FROM maker.deal WHERE header_id = $1`, headerId)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(dbResult.BidId).To(Equal(test_data.DealModel.BidId)) Expect(dbResult.BidId).To(Equal(test_data.DealModel.BidId))
Expect(dbResult.ContractAddress).To(Equal(test_data.DealModel.ContractAddress)) Expect(dbResult.ContractAddress).To(Equal(test_data.DealModel.ContractAddress))
Expect(dbResult.LogIndex).To(Equal(test_data.DealModel.LogIndex))
Expect(dbResult.TransactionIndex).To(Equal(test_data.DealModel.TransactionIndex)) Expect(dbResult.TransactionIndex).To(Equal(test_data.DealModel.TransactionIndex))
Expect(dbResult.Raw).To(MatchJSON(test_data.DealModel.Raw)) Expect(dbResult.Raw).To(MatchJSON(test_data.DealModel.Raw))
}) })

View File

@ -36,7 +36,7 @@ var DealLogNote = types.Log{
TxHash: common.HexToHash("0xc6ff19de9299e5b290ba2d52fdb4662360ca86376613d78ee546244866a0be2d"), TxHash: common.HexToHash("0xc6ff19de9299e5b290ba2d52fdb4662360ca86376613d78ee546244866a0be2d"),
TxIndex: 74, TxIndex: 74,
BlockHash: common.HexToHash("0x6454844075164a1d264c86d2a2c31ac1b64eb2f4ebdbbaeb4d44388fdf74470b"), BlockHash: common.HexToHash("0x6454844075164a1d264c86d2a2c31ac1b64eb2f4ebdbbaeb4d44388fdf74470b"),
Index: 0, Index: 75,
Removed: false, Removed: false,
} }
var dealRawJson, _ = json.Marshal(DealLogNote) var dealRawJson, _ = json.Marshal(DealLogNote)
@ -44,6 +44,7 @@ var dealRawJson, _ = json.Marshal(DealLogNote)
var DealModel = deal.DealModel{ var DealModel = deal.DealModel{
BidId: "123", BidId: "123",
ContractAddress: shared.FlipperContractAddress, ContractAddress: shared.FlipperContractAddress,
TransactionIndex: 74, LogIndex: DealLogNote.Index,
TransactionIndex: DealLogNote.TxIndex,
Raw: dealRawJson, Raw: dealRawJson,
} }