postgres sql statements for database queries

This commit is contained in:
i-norden 2023-02-28 11:34:45 -06:00
parent 82555a5319
commit 16b0b5b0f2

14
sql.go
View File

@ -1,7 +1,8 @@
package ipld_eth_statedb
const (
GetBalancePgStr = `SELECT balance FROM eth.state_cids
GetContractCodePgStr = `SELECT data FROM public.blocks WHERE key = $1`
GetStateAccount = `SELECT balance, nonce, code_hash, storage_root, removed FROM eth.state_cids
INNER JOIN eth.header_cids ON (
state_cids.header_id = header_cids.block_hash
AND state_cids.block_number = header_cids.block_number
@ -13,5 +14,14 @@ const (
AND header_cids.block_hash = (SELECT canonical_header_hash(header_cids.block_number))
ORDER BY header_cids.block_number DESC
LIMIT 1`
GetContractCodePgStr = `SELECT data FROM public.blocks WHERE key = $1`
GetStorageSlot = `SELECT value, removed FROM eth.storage_cids
INNER JOIN eth.header_cids ON (
storage_cids.header_id = header_cids.block_hash
AND storage_cids.block_number = header_cids.block_number
)
WHERE state_leaf_key = $1
AND storage_leaf_key = $2
AND header_cids.block_hash = (SELECT canonical_header_hash(header_cids.block_number))
ORDER BY header_cids.block_number DESC
LIMIT 1`
)