Remove log_uc
* Logs now are attached to receipt, so removing block + index unique constraint
This commit is contained in:
parent
08993cc6a4
commit
6583ce72b8
@ -6,4 +6,7 @@ ALTER TABLE logs
|
|||||||
ALTER TABLE logs
|
ALTER TABLE logs
|
||||||
DROP COLUMN receipt_id;
|
DROP COLUMN receipt_id;
|
||||||
|
|
||||||
|
ALTER TABLE logs
|
||||||
|
ADD CONSTRAINT log_uc UNIQUE (block_number, index);
|
||||||
|
|
||||||
COMMIT;
|
COMMIT;
|
@ -1,4 +1,6 @@
|
|||||||
BEGIN;
|
BEGIN;
|
||||||
|
ALTER TABLE logs
|
||||||
|
DROP CONSTRAINT log_uc;
|
||||||
|
|
||||||
ALTER TABLE logs
|
ALTER TABLE logs
|
||||||
ADD COLUMN receipt_id INT;
|
ADD COLUMN receipt_id INT;
|
||||||
|
@ -324,14 +324,6 @@ ALTER TABLE ONLY watched_contracts
|
|||||||
ADD CONSTRAINT contract_hash_uc UNIQUE (contract_hash);
|
ADD CONSTRAINT contract_hash_uc UNIQUE (contract_hash);
|
||||||
|
|
||||||
|
|
||||||
--
|
|
||||||
-- Name: logs log_uc; Type: CONSTRAINT; Schema: public; Owner: -
|
|
||||||
--
|
|
||||||
|
|
||||||
ALTER TABLE ONLY logs
|
|
||||||
ADD CONSTRAINT log_uc UNIQUE (block_number, index);
|
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Name: logs logs_pkey; Type: CONSTRAINT; Schema: public; Owner: -
|
-- Name: logs logs_pkey; Type: CONSTRAINT; Schema: public; Owner: -
|
||||||
--
|
--
|
||||||
|
@ -351,21 +351,10 @@ func (repository Postgres) createReceipt(tx *sql.Tx, transactionId int, receipt
|
|||||||
func (repository Postgres) createLogs(tx *sql.Tx, logs []core.Log, receiptId int) error {
|
func (repository Postgres) createLogs(tx *sql.Tx, logs []core.Log, receiptId int) error {
|
||||||
for _, tlog := range logs {
|
for _, tlog := range logs {
|
||||||
_, err := tx.Exec(
|
_, err := tx.Exec(
|
||||||
`INSERT INTO logs (block_number, address, tx_hash, index, topic0, topic1, topic2, topic3, data)
|
`INSERT INTO logs (block_number, address, tx_hash, index, topic0, topic1, topic2, topic3, data, receipt_id)
|
||||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
|
||||||
ON CONFLICT (index, block_number)
|
|
||||||
DO UPDATE
|
|
||||||
SET block_number = $1,
|
|
||||||
address = $2,
|
|
||||||
tx_hash = $3,
|
|
||||||
index = $4,
|
|
||||||
topic0 = $5,
|
|
||||||
topic1 = $6,
|
|
||||||
topic2 = $7,
|
|
||||||
topic3 = $8,
|
|
||||||
data = $9
|
|
||||||
`,
|
`,
|
||||||
tlog.BlockNumber, tlog.Address, tlog.TxHash, tlog.Index, tlog.Topics[0], tlog.Topics[1], tlog.Topics[2], tlog.Topics[3], tlog.Data,
|
tlog.BlockNumber, tlog.Address, tlog.TxHash, tlog.Index, tlog.Topics[0], tlog.Topics[1], tlog.Topics[2], tlog.Topics[3], tlog.Data, receiptId,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ErrDBInsertFailed
|
return ErrDBInsertFailed
|
||||||
@ -380,17 +369,6 @@ func (repository Postgres) CreateLogs(logs []core.Log) error {
|
|||||||
_, err := tx.Exec(
|
_, err := tx.Exec(
|
||||||
`INSERT INTO logs (block_number, address, tx_hash, index, topic0, topic1, topic2, topic3, data)
|
`INSERT INTO logs (block_number, address, tx_hash, index, topic0, topic1, topic2, topic3, data)
|
||||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
|
||||||
ON CONFLICT (index, block_number)
|
|
||||||
DO UPDATE
|
|
||||||
SET block_number = $1,
|
|
||||||
address = $2,
|
|
||||||
tx_hash = $3,
|
|
||||||
index = $4,
|
|
||||||
topic0 = $5,
|
|
||||||
topic1 = $6,
|
|
||||||
topic2 = $7,
|
|
||||||
topic3 = $8,
|
|
||||||
data = $9
|
|
||||||
`,
|
`,
|
||||||
tlog.BlockNumber, tlog.Address, tlog.TxHash, tlog.Index, tlog.Topics[0], tlog.Topics[1], tlog.Topics[2], tlog.Topics[3], tlog.Data,
|
tlog.BlockNumber, tlog.Address, tlog.TxHash, tlog.Index, tlog.Topics[0], tlog.Topics[1], tlog.Topics[2], tlog.Topics[3], tlog.Data,
|
||||||
)
|
)
|
||||||
|
@ -422,30 +422,6 @@ func AssertRepositoryBehavior(buildRepository func(node core.Node) repositories.
|
|||||||
Expect(log).To(BeNil())
|
Expect(log).To(BeNil())
|
||||||
})
|
})
|
||||||
|
|
||||||
It("updates the log when log with when log with same block number and index is already present", func() {
|
|
||||||
repository.CreateLogs([]core.Log{{
|
|
||||||
BlockNumber: 1,
|
|
||||||
Index: 0,
|
|
||||||
Address: "x123",
|
|
||||||
TxHash: "x456",
|
|
||||||
Topics: core.Topics{0: "x777", 1: "x888", 2: "x999"},
|
|
||||||
Data: "xABC",
|
|
||||||
},
|
|
||||||
})
|
|
||||||
repository.CreateLogs([]core.Log{{
|
|
||||||
BlockNumber: 1,
|
|
||||||
Index: 0,
|
|
||||||
Address: "x123",
|
|
||||||
TxHash: "x456",
|
|
||||||
Topics: core.Topics{0: "x777", 1: "x888", 2: "x999"},
|
|
||||||
Data: "xXYZ",
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
log := repository.FindLogs("x123", 1)
|
|
||||||
Expect(log[0].Data).To(Equal("xXYZ"))
|
|
||||||
})
|
|
||||||
|
|
||||||
It("filters to the correct block number and address", func() {
|
It("filters to the correct block number and address", func() {
|
||||||
repository.CreateLogs([]core.Log{{
|
repository.CreateLogs([]core.Log{{
|
||||||
BlockNumber: 1,
|
BlockNumber: 1,
|
||||||
|
Loading…
Reference in New Issue
Block a user