diff --git a/sql.go b/sql.go index f130d91..9d62626 100644 --- a/sql.go +++ b/sql.go @@ -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` )