diff --git a/db/migrations/00032_update_receipt_cids.sql b/db/migrations/00032_update_receipt_cids.sql index 250fb474..15ec931e 100644 --- a/db/migrations/00032_update_receipt_cids.sql +++ b/db/migrations/00032_update_receipt_cids.sql @@ -3,7 +3,7 @@ ALTER TABLE eth.receipt_cids ADD COLUMN log_contracts VARCHAR(66)[]; ALTER TABLE eth.receipt_cids -RENAME COLUMN contract TO contract_hash; +ADD COLUMN contract_hash VARCHAR(66); WITH uniques AS (SELECT DISTINCT ON (tx_id) * FROM eth.receipt_cids) DELETE FROM eth.receipt_cids WHERE receipt_cids.id NOT IN (SELECT id FROM uniques); @@ -16,7 +16,7 @@ ALTER TABLE eth.receipt_cids DROP CONSTRAINT receipt_cids_tx_id_key; ALTER TABLE eth.receipt_cids -RENAME COLUMN contract_hash TO contract; +DROP COLUMN contract_hash; ALTER TABLE eth.receipt_cids DROP COLUMN log_contracts; \ No newline at end of file diff --git a/db/schema.sql b/db/schema.sql index d00e8e07..36b5ffb1 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -353,12 +353,13 @@ CREATE TABLE eth.receipt_cids ( id integer NOT NULL, tx_id integer NOT NULL, cid text NOT NULL, - contract_hash character varying(66), + contract character varying(66), topic0s character varying(66)[], topic1s character varying(66)[], topic2s character varying(66)[], topic3s character varying(66)[], - log_contracts character varying(66)[] + log_contracts character varying(66)[], + contract_hash character varying(66) ); diff --git a/pkg/super_node/eth/converter.go b/pkg/super_node/eth/converter.go index 537bc9a2..d6287293 100644 --- a/pkg/super_node/eth/converter.go +++ b/pkg/super_node/eth/converter.go @@ -114,6 +114,7 @@ func (pc *PayloadConverter) Convert(payload shared.RawChainData) (shared.Convert Topic1s: topicSets[1], Topic2s: topicSets[2], Topic3s: topicSets[3], + Contract: contract, ContractHash: contractHash, LogContracts: logContracts, } diff --git a/pkg/super_node/eth/indexer.go b/pkg/super_node/eth/indexer.go index f19efa9e..f9723fe7 100644 --- a/pkg/super_node/eth/indexer.go +++ b/pkg/super_node/eth/indexer.go @@ -127,9 +127,9 @@ func (in *CIDIndexer) indexTransactionAndReceiptCIDs(tx *sqlx.Tx, payload *CIDPa } func (in *CIDIndexer) indexReceiptCID(tx *sqlx.Tx, cidMeta ReceiptModel, txID int64) error { - _, err := tx.Exec(`INSERT INTO eth.receipt_cids (tx_id, cid, contract_hash, topic0s, topic1s, topic2s, topic3s, log_contracts) VALUES ($1, $2, $3, $4, $5, $6, $7, $8) - ON CONFLICT (tx_id) DO UPDATE SET (cid, contract_hash, topic0s, topic1s, topic2s, topic3s, log_contracts) = ($2, $3, $4, $5, $6, $7, $8)`, - txID, cidMeta.CID, cidMeta.ContractHash, cidMeta.Topic0s, cidMeta.Topic1s, cidMeta.Topic2s, cidMeta.Topic3s, cidMeta.LogContracts) + _, err := tx.Exec(`INSERT INTO eth.receipt_cids (tx_id, cid, contract, contract_hash, topic0s, topic1s, topic2s, topic3s, log_contracts) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9) + ON CONFLICT (tx_id) DO UPDATE SET (cid, contract, contract_hash, topic0s, topic1s, topic2s, topic3s, log_contracts) = ($2, $3, $4, $5, $6, $7, $8, $9)`, + txID, cidMeta.CID, cidMeta.Contract, cidMeta.ContractHash, cidMeta.Topic0s, cidMeta.Topic1s, cidMeta.Topic2s, cidMeta.Topic3s, cidMeta.LogContracts) return err } diff --git a/pkg/super_node/eth/mocks/test_data.go b/pkg/super_node/eth/mocks/test_data.go index c0439435..aca169fc 100644 --- a/pkg/super_node/eth/mocks/test_data.go +++ b/pkg/super_node/eth/mocks/test_data.go @@ -141,6 +141,7 @@ var ( Topic1s: []string{ mockTopic12.String(), }, + Contract: "", ContractHash: "", LogContracts: []string{ Address.String(), @@ -154,6 +155,7 @@ var ( Topic1s: []string{ mockTopic22.String(), }, + Contract: "", ContractHash: "", LogContracts: []string{ AnotherAddress.String(), @@ -161,6 +163,7 @@ var ( }, { CID: "", + Contract: ContractAddress.String(), ContractHash: ContractHash, LogContracts: []string{}, }, @@ -174,6 +177,7 @@ var ( Topic1s: []string{ mockTopic12.String(), }, + Contract: "", ContractHash: "", LogContracts: []string{ Address.String(), @@ -187,6 +191,7 @@ var ( Topic1s: []string{ mockTopic22.String(), }, + Contract: "", ContractHash: "", LogContracts: []string{ AnotherAddress.String(), @@ -194,6 +199,7 @@ var ( }, { CID: Rct3CID.String(), + Contract: ContractAddress.String(), ContractHash: ContractHash, LogContracts: []string{}, }, diff --git a/pkg/super_node/eth/models.go b/pkg/super_node/eth/models.go index c960b91b..5f73bfe1 100644 --- a/pkg/super_node/eth/models.go +++ b/pkg/super_node/eth/models.go @@ -63,6 +63,7 @@ type ReceiptModel struct { ID int64 `db:"id"` TxID int64 `db:"tx_id"` CID string `db:"cid"` + Contract string `db:"contract"` ContractHash string `db:"contract_hash"` LogContracts pq.StringArray `db:"log_contracts"` Topic0s pq.StringArray `db:"topic0s"` diff --git a/pkg/super_node/eth/publisher.go b/pkg/super_node/eth/publisher.go index 67211cc3..375b449c 100644 --- a/pkg/super_node/eth/publisher.go +++ b/pkg/super_node/eth/publisher.go @@ -189,6 +189,7 @@ func (pub *IPLDPublisher) publishReceipts(receipts []*ipld.EthReceipt, receiptTr } rctCids[rct.TxHash] = ReceiptModel{ CID: cid, + Contract: receiptMeta[i].Contract, ContractHash: receiptMeta[i].ContractHash, Topic0s: receiptMeta[i].Topic0s, Topic1s: receiptMeta[i].Topic1s, diff --git a/pkg/super_node/eth/retriever.go b/pkg/super_node/eth/retriever.go index 0251888d..5baa2c72 100644 --- a/pkg/super_node/eth/retriever.go +++ b/pkg/super_node/eth/retriever.go @@ -214,7 +214,7 @@ func (ecr *CIDRetriever) RetrieveTxCIDs(tx *sqlx.Tx, txFilter TxFilter, headerID func (ecr *CIDRetriever) RetrieveRctCIDsByHeaderID(tx *sqlx.Tx, rctFilter ReceiptFilter, headerID int64, trxIds []int64) ([]ReceiptModel, error) { log.Debug("retrieving receipt cids for header id ", headerID) args := make([]interface{}, 0, 4) - pgStr := `SELECT receipt_cids.id, receipt_cids.tx_id, receipt_cids.cid, + pgStr := `SELECT receipt_cids.id, receipt_cids.tx_id, receipt_cids.cid, receipt_cids.contract, receipt_cids.contract_hash, receipt_cids.topic0s, receipt_cids.topic1s, receipt_cids.topic2s, receipt_cids.topic3s, receipt_cids.log_contracts FROM eth.receipt_cids, eth.transaction_cids, eth.header_cids @@ -294,7 +294,7 @@ func (ecr *CIDRetriever) RetrieveRctCIDsByHeaderID(tx *sqlx.Tx, rctFilter Receip func (ecr *CIDRetriever) RetrieveRctCIDs(tx *sqlx.Tx, rctFilter ReceiptFilter, blockNumber int64, blockHash *common.Hash, trxIds []int64) ([]ReceiptModel, error) { log.Debug("retrieving receipt cids for block ", blockNumber) args := make([]interface{}, 0, 5) - pgStr := `SELECT receipt_cids.id, receipt_cids.tx_id, receipt_cids.cid, + pgStr := `SELECT receipt_cids.id, receipt_cids.tx_id, receipt_cids.cid, receipt_cids.contract, receipt_cids.contract_hash, receipt_cids.topic0s, receipt_cids.topic1s, receipt_cids.topic2s, receipt_cids.topic3s, receipt_cids.log_contracts FROM eth.receipt_cids, eth.transaction_cids, eth.header_cids @@ -614,7 +614,7 @@ func (ecr *CIDRetriever) RetrieveTxCIDsByHeaderID(tx *sqlx.Tx, headerID int64) ( // RetrieveReceiptCIDsByTxIDs retrieves receipt CIDs by their associated tx IDs func (ecr *CIDRetriever) RetrieveReceiptCIDsByTxIDs(tx *sqlx.Tx, txIDs []int64) ([]ReceiptModel, error) { log.Debugf("retrieving receipt cids for tx ids %v", txIDs) - pgStr := `SELECT receipt_cids.id, receipt_cids.tx_id, receipt_cids.cid, + pgStr := `SELECT receipt_cids.id, receipt_cids.tx_id, receipt_cids.cid, receipt_cids.contract, receipt_cids.contract_hash, receipt_cids.topic0s, receipt_cids.topic1s, receipt_cids.topic2s, receipt_cids.topic3s, receipt_cids.log_contracts FROM eth.receipt_cids, eth.transaction_cids