Add log index to Deal
This commit is contained in:
parent
495f39abb8
commit
1aafb7201e
@ -1,8 +1,10 @@
|
||||
CREATE TABLE maker.deal (
|
||||
id SERIAL PRIMARY KEY,
|
||||
header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE,
|
||||
bid_id NUMERIC NOT NULL,
|
||||
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,
|
||||
bid_id NUMERIC NOT NULL,
|
||||
contract_address VARCHAR,
|
||||
log_idx INTEGER NOT NUll,
|
||||
tx_idx INTEGER NOT NUll,
|
||||
raw_log JSONB,
|
||||
UNIQUE (header_id, tx_idx, log_idx)
|
||||
);
|
@ -1,2 +0,0 @@
|
||||
ALTER TABLE maker.deal
|
||||
DROP COLUMN contract_address;
|
@ -1,2 +0,0 @@
|
||||
ALTER TABLE maker.deal
|
||||
ADD COLUMN contract_address VARCHAR;
|
@ -209,9 +209,10 @@ CREATE TABLE maker.deal (
|
||||
id integer NOT NULL,
|
||||
header_id integer NOT NULL,
|
||||
bid_id numeric NOT NULL,
|
||||
contract_address character varying,
|
||||
log_idx integer NOT NULL,
|
||||
tx_idx integer NOT NULL,
|
||||
raw_log jsonb,
|
||||
contract_address character varying
|
||||
raw_log jsonb
|
||||
);
|
||||
|
||||
|
||||
@ -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
|
||||
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);
|
||||
|
||||
|
||||
--
|
||||
|
@ -47,6 +47,7 @@ func (DealConverter) ToModels(ethLogs []types.Log) (result []DealModel, err erro
|
||||
model := DealModel{
|
||||
BidId: bidId.String(),
|
||||
ContractAddress: log.Address.Hex(),
|
||||
LogIndex: log.Index,
|
||||
TransactionIndex: log.TxIndex,
|
||||
Raw: raw,
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ package deal
|
||||
type DealModel struct {
|
||||
BidId string `db:"bid_id"`
|
||||
ContractAddress string `db:"contract_address"`
|
||||
LogIndex uint `db:"log_idx"`
|
||||
TransactionIndex uint `db:"tx_idx"`
|
||||
Raw []byte `db:"raw_log"`
|
||||
}
|
||||
|
@ -38,9 +38,9 @@ func (r DealRepository) Create(headerId int64, models []DealModel) error {
|
||||
}
|
||||
for _, model := range models {
|
||||
_, err = tx.Exec(
|
||||
`INSERT into maker.deal (header_id, bid_id, contract_address, tx_idx, raw_log)
|
||||
VALUES($1, $2, $3, $4, $5)`,
|
||||
headerId, model.BidId, model.ContractAddress, model.TransactionIndex, model.Raw,
|
||||
`INSERT into maker.deal (header_id, bid_id, contract_address, log_idx, tx_idx, raw_log)
|
||||
VALUES($1, $2, $3, $4, $5, $6)`,
|
||||
headerId, model.BidId, model.ContractAddress, model.LogIndex, model.TransactionIndex, model.Raw,
|
||||
)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
|
@ -57,10 +57,11 @@ var _ = Describe("Deal Repository", func() {
|
||||
db.QueryRow(`SELECT count(*) FROM maker.deal`).Scan(&count)
|
||||
Expect(count).To(Equal(1))
|
||||
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(dbResult.BidId).To(Equal(test_data.DealModel.BidId))
|
||||
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.Raw).To(MatchJSON(test_data.DealModel.Raw))
|
||||
})
|
||||
|
@ -36,7 +36,7 @@ var DealLogNote = types.Log{
|
||||
TxHash: common.HexToHash("0xc6ff19de9299e5b290ba2d52fdb4662360ca86376613d78ee546244866a0be2d"),
|
||||
TxIndex: 74,
|
||||
BlockHash: common.HexToHash("0x6454844075164a1d264c86d2a2c31ac1b64eb2f4ebdbbaeb4d44388fdf74470b"),
|
||||
Index: 0,
|
||||
Index: 75,
|
||||
Removed: false,
|
||||
}
|
||||
var dealRawJson, _ = json.Marshal(DealLogNote)
|
||||
@ -44,6 +44,7 @@ var dealRawJson, _ = json.Marshal(DealLogNote)
|
||||
var DealModel = deal.DealModel{
|
||||
BidId: "123",
|
||||
ContractAddress: shared.FlipperContractAddress,
|
||||
TransactionIndex: 74,
|
||||
LogIndex: DealLogNote.Index,
|
||||
TransactionIndex: DealLogNote.TxIndex,
|
||||
Raw: dealRawJson,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user