Refactoring.
This commit is contained in:
parent
b3e4fbfa39
commit
c0a4600ce7
@ -4,7 +4,7 @@ CREATE TABLE eth.log_cids (
|
||||
receipt_id INTEGER NOT NULL REFERENCES eth.receipt_cids (id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
|
||||
address VARCHAR(66),
|
||||
cid TEXT NOT NULL,
|
||||
data BYTEA,
|
||||
log_data BYTEA,
|
||||
mh_key TEXT NOT NULL REFERENCES public.blocks (key) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
|
||||
index INTEGER NOT NULL,
|
||||
topic0 VARCHAR(66),
|
||||
|
@ -626,6 +626,7 @@ func (pea *PublicEthAPI) localGetLogs(crit filters.FilterCriteria) ([]*types.Log
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// TODO: write query for Retrieving block Number by hash
|
||||
header, err := pea.B.Retriever.RetrieveHeaderCIDByHash(tx, *crit.BlockHash)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -635,6 +636,7 @@ func (pea *PublicEthAPI) localGetLogs(crit filters.FilterCriteria) ([]*types.Log
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// TODO: should we convert string to uint ?
|
||||
blockNumber, err := strconv.ParseUint(header.BlockNumber, 10, 64)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -700,12 +702,12 @@ func (pea *PublicEthAPI) localGetLogs(crit filters.FilterCriteria) ([]*types.Log
|
||||
return nil, err
|
||||
}
|
||||
|
||||
header, err := pea.B.Retriever.RetrieveHeaderCIDByNumber(tx, i)
|
||||
canonicalHash, err := pea.B.GetCanonicalHash(uint64(i))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return extractLogsOfInterest(pea.B.Config.ChainConfig, common.HexToHash(header.BlockHash), uint64(i), rctCIDs, txnIPLDs, rctIPLDs, logIPLDs, txnCIDs)
|
||||
return extractLogsOfInterest(pea.B.Config.ChainConfig, canonicalHash, uint64(i), rctCIDs, txnIPLDs, rctIPLDs, logIPLDs, txnCIDs)
|
||||
}
|
||||
|
||||
if err := tx.Commit(); err != nil {
|
||||
|
@ -243,6 +243,7 @@ var _ = Describe("API", func() {
|
||||
}
|
||||
expectedBlock["uncles"] = uncleHashes
|
||||
|
||||
// setting chain config to for london block
|
||||
chainConfig.LondonBlock = big.NewInt(2)
|
||||
indexAndPublisher = indexer.NewStateDiffIndexer(chainConfig, db)
|
||||
tx, err = indexAndPublisher.PushBlock(test_helpers.MockLondonBlock, test_helpers.MockLondonReceipts, test_helpers.MockLondonBlock.Difficulty())
|
||||
|
@ -285,7 +285,7 @@ func extractLogsOfInterest(config *params.ChainConfig, blockHash common.Hash, bl
|
||||
}
|
||||
|
||||
if logModels, ok := logIPLDs[rctCIDs[k].ID]; ok {
|
||||
idx := 0
|
||||
idx := 0 // TODO: check if this is good way use index for log
|
||||
for logIdx, v := range logModels {
|
||||
l := &types.Log{}
|
||||
err := rlp.DecodeBytes(v.Data, l)
|
||||
@ -349,9 +349,7 @@ func deriveFields(rs types.Receipts, config *params.ChainConfig, hash common.Has
|
||||
} else {
|
||||
rs[i].GasUsed = rs[i].CumulativeGasUsed - rs[i-1].CumulativeGasUsed
|
||||
}
|
||||
for j := 0; j < len(rs[i].Logs); j++ {
|
||||
|
||||
}
|
||||
for j := 0; j < len(rs[i].Logs); j++ {
|
||||
rs[i].Logs[j].BlockNumber = number
|
||||
rs[i].Logs[j].BlockHash = hash
|
||||
|
@ -209,7 +209,7 @@ func (ecr *CIDRetriever) RetrieveTxCIDs(tx *sqlx.Tx, txFilter TxFilter, headerID
|
||||
return results, tx.Select(&results, pgStr, args...)
|
||||
}
|
||||
|
||||
func topicsQuery(id int, topics [][]string, args []interface{}, pgStr string, first bool) (string, []interface{}, int) {
|
||||
func topicFilterCondition(id int, topics [][]string, args []interface{}, pgStr string, first bool) (string, []interface{}, int) {
|
||||
for i, topicSet := range topics {
|
||||
if len(topicSet) == 0 {
|
||||
continue
|
||||
@ -227,7 +227,7 @@ func topicsQuery(id int, topics [][]string, args []interface{}, pgStr string, fi
|
||||
return pgStr, args, id
|
||||
}
|
||||
|
||||
func retrieveFilteredRctQuery(id int, pgStr string, args []interface{}, rctFilter ReceiptFilter, trxIds []int64) (string, []interface{}, int) {
|
||||
func receiptFilterConditions(id int, pgStr string, args []interface{}, rctFilter ReceiptFilter, trxIds []int64) (string, []interface{}, int) {
|
||||
rctCond := " AND (receipt_cids.id = ANY ( "
|
||||
logQuery := "SELECT receipt_id FROM eth.log_cids WHERE"
|
||||
if len(rctFilter.LogAddresses) > 0 {
|
||||
@ -238,7 +238,7 @@ func retrieveFilteredRctQuery(id int, pgStr string, args []interface{}, rctFilte
|
||||
|
||||
// Filter on topics if there are any
|
||||
if hasTopics(rctFilter.Topics) {
|
||||
pgStr, args, id = topicsQuery(id, rctFilter.Topics, args, pgStr, false)
|
||||
pgStr, args, id = topicFilterCondition(id, rctFilter.Topics, args, pgStr, false)
|
||||
}
|
||||
|
||||
pgStr += ")"
|
||||
@ -253,7 +253,7 @@ func retrieveFilteredRctQuery(id int, pgStr string, args []interface{}, rctFilte
|
||||
// Filter on topics if there are any
|
||||
if hasTopics(rctFilter.Topics) {
|
||||
pgStr += rctCond + logQuery
|
||||
pgStr, args, id = topicsQuery(id, rctFilter.Topics, args, pgStr, true)
|
||||
pgStr, args, id = topicFilterCondition(id, rctFilter.Topics, args, pgStr, true)
|
||||
pgStr += ")"
|
||||
// Filter on txIDs if there are any and we are matching txs
|
||||
if rctFilter.MatchTxs && len(trxIds) > 0 {
|
||||
@ -303,7 +303,7 @@ func (ecr *CIDRetriever) RetrieveRctCIDsByHeaderID(tx *sqlx.Tx, rctFilter Receip
|
||||
AND header_cids.id = $1`
|
||||
id := 2
|
||||
args = append(args, headerID)
|
||||
pgStr, args, id = retrieveFilteredRctQuery(id, pgStr, args, rctFilter, trxIds)
|
||||
pgStr, args, id = receiptFilterConditions(id, pgStr, args, rctFilter, trxIds)
|
||||
|
||||
pgStr += ` ORDER BY transaction_cids.index`
|
||||
receiptCids := make([]models.ReceiptModel, 0)
|
||||
@ -332,7 +332,7 @@ func (ecr *CIDRetriever) RetrieveRctCIDs(tx *sqlx.Tx, rctFilter ReceiptFilter, b
|
||||
id++
|
||||
}
|
||||
|
||||
pgStr, args, id = retrieveFilteredRctQuery(id, pgStr, args, rctFilter, trxIds)
|
||||
pgStr, args, id = receiptFilterConditions(id, pgStr, args, rctFilter, trxIds)
|
||||
|
||||
pgStr += ` ORDER BY transaction_cids.index`
|
||||
receiptCids := make([]models.ReceiptModel, 0)
|
||||
@ -518,15 +518,6 @@ func (ecr *CIDRetriever) RetrieveHeaderCIDByHash(tx *sqlx.Tx, blockHash common.H
|
||||
return headerCID, tx.Get(&headerCID, pgStr, blockHash.String())
|
||||
}
|
||||
|
||||
// RetrieveHeaderCIDByNumber returns the header for the given block number
|
||||
func (ecr *CIDRetriever) RetrieveHeaderCIDByNumber(tx *sqlx.Tx, blockNumber int64) (models.HeaderModel, error) {
|
||||
log.Debug("retrieving header cids for block hash ", blockNumber)
|
||||
pgStr := `SELECT * FROM eth.header_cids
|
||||
WHERE block_number = $1`
|
||||
var headerCID models.HeaderModel
|
||||
return headerCID, tx.Get(&headerCID, pgStr, blockNumber)
|
||||
}
|
||||
|
||||
// RetrieveTxCIDsByHeaderID retrieves all tx CIDs for the given header id
|
||||
func (ecr *CIDRetriever) RetrieveTxCIDsByHeaderID(tx *sqlx.Tx, headerID int64) ([]models.TxModel, error) {
|
||||
log.Debug("retrieving tx cids for block id ", headerID)
|
||||
|
Loading…
Reference in New Issue
Block a user