Skip to content

Commit

Permalink
Remove get_storage_at fn.
Browse files Browse the repository at this point in the history
  • Loading branch information
telackey committed Aug 2, 2023
1 parent 2c87117 commit eb95d5e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
3 changes: 3 additions & 0 deletions pkg/eth/retriever.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,9 @@ func (r *Retriever) retrieveFilteredLogs(db *sqlx.DB, rctFilter ReceiptFilter, s

pgStr, args = logFilterCondition(&id, pgStr, args, rctFilter)
pgStr += ` ORDER BY eth.log_cids.block_number, eth.log_cids.index`
if blockHash != nil {
pgStr += ` LIMIT 1`
}

logs := make([]LogResult, 0)
err := db.Select(&logs, pgStr, args...)
Expand Down
41 changes: 33 additions & 8 deletions pkg/eth/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,40 @@ LIMIT 1
AND eth.receipt_cids.tx_id = eth.transaction_cids.tx_hash
AND ipld.blocks.block_number = eth.log_cids.block_number
AND ipld.blocks.key = eth.log_cids.cid`
RetrieveStorageLeafByAddressHashAndLeafKeyAndBlockHashPgStr = `SELECT cid, val, block_number, removed, state_leaf_removed FROM get_storage_at_by_hash($1, $2, $3)`
RetrieveStorageLeafByAddressHashAndLeafKeyAndBlockHashPgStr = `
SELECT storage_cids.cid,
storage_cids.val,
storage_cids.block_number,
storage_cids.removed,
was_state_leaf_removed_by_number(storage_cids.state_leaf_key, storage_cids.block_number) AS state_leaf_removed
FROM eth.storage_cids, eth.header_cids
WHERE header_cids.block_number <= (SELECT block_number from eth.header_cids where block_hash = $3 LIMIT 1)
AND header_cids.canonical
AND storage_cids.block_number = header_cids.block_number
AND storage_cids.header_id = header_cids.block_hash
AND storage_cids.storage_leaf_key = $2
AND storage_cids.state_leaf_key = $1
ORDER BY storage_cids.block_number DESC LIMIT 1
`
RetrieveStorageAndRLPByAddressHashAndLeafKeyAndBlockHashPgStr = `
SELECT cid, val, storage.block_number, removed, state_leaf_removed, data
FROM get_storage_at_by_hash($1, $2, $3) AS storage
INNER JOIN ipld.blocks ON (
storage.cid = blocks.key
AND storage.block_number = blocks.block_number
)`
RetrieveCanonicalBlockHashByNumber = `SELECT block_hash FROM eth.header_cids WHERE block_number = $1 and canonical`
SELECT storage_cids.cid,
storage_cids.val,
storage_cids.block_number,
storage_cids.removed,
was_state_leaf_removed_by_number(storage_cids.state_leaf_key, storage_cids.block_number) AS state_leaf_removed,
blocks.data
FROM eth.storage_cids, eth.header_cids, ipld.blocks
WHERE header_cids.block_number <= (SELECT block_number from eth.header_cids where block_hash = $3 LIMIT 1)
AND header_cids.canonical
AND storage_cids.block_number = header_cids.block_number
AND storage_cids.header_id = header_cids.block_hash
AND storage_cids.storage_leaf_key = $2
AND storage_cids.state_leaf_key = $1
AND blocks.key = storage_cids.cid
AND blocks.block_number = storage_cids.block_number
ORDER BY storage_cids.block_number DESC LIMIT 1
`
RetrieveCanonicalBlockHashByNumber = `SELECT block_hash FROM eth.header_cids WHERE block_number = $1 AND canonical`
RetrieveCanonicalHeaderByNumber = `
SELECT header_cids.cid,
blocks.data
Expand Down

0 comments on commit eb95d5e

Please sign in to comment.