2023-02-27 22:16:52 +00:00
|
|
|
package ipld_eth_statedb
|
|
|
|
|
|
|
|
const (
|
2023-03-05 07:45:53 +00:00
|
|
|
GetContractCodePgStr = `SELECT data FROM ipld.blocks WHERE key = $1`
|
2023-02-28 17:34:45 +00:00
|
|
|
GetStateAccount = `SELECT balance, nonce, code_hash, storage_root, removed FROM eth.state_cids
|
2023-02-27 22:16:52 +00:00
|
|
|
INNER JOIN eth.header_cids ON (
|
|
|
|
state_cids.header_id = header_cids.block_hash
|
|
|
|
AND state_cids.block_number = header_cids.block_number
|
|
|
|
)
|
|
|
|
WHERE state_leaf_key = $1
|
|
|
|
AND header_cids.block_number <= (SELECT block_number
|
|
|
|
FROM eth.header_cids
|
|
|
|
WHERE block_hash = $2)
|
|
|
|
AND header_cids.block_hash = (SELECT canonical_header_hash(header_cids.block_number))
|
|
|
|
ORDER BY header_cids.block_number DESC
|
|
|
|
LIMIT 1`
|
2023-02-28 17:43:07 +00:00
|
|
|
GetStorageSlot = `SELECT val, removed FROM eth.storage_cids
|
2023-02-28 17:34:45 +00:00
|
|
|
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
|
2023-02-28 18:07:03 +00:00
|
|
|
AND header_cids.block_number <= (SELECT block_number
|
|
|
|
FROM eth.header_cids
|
|
|
|
WHERE block_hash = $3)
|
2023-02-28 17:34:45 +00:00
|
|
|
AND header_cids.block_hash = (SELECT canonical_header_hash(header_cids.block_number))
|
|
|
|
ORDER BY header_cids.block_number DESC
|
|
|
|
LIMIT 1`
|
2023-02-27 22:16:52 +00:00
|
|
|
)
|
2023-02-28 17:43:07 +00:00
|
|
|
|
|
|
|
// StorageSlotResult struct for unpacking GetStorageSlot result
|
|
|
|
type StorageSlotResult struct {
|
2023-02-28 17:45:11 +00:00
|
|
|
Value []byte `db:"val"`
|
|
|
|
Removed bool `db:"removed"`
|
2023-02-28 17:43:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// StateAccountResult struct for unpacking GetStateAccount result
|
|
|
|
type StateAccountResult struct {
|
|
|
|
Balance string `db:"balance"`
|
|
|
|
Nonce uint64 `db:"nonce"`
|
2023-03-05 07:45:53 +00:00
|
|
|
CodeHash string `db:"code_hash"`
|
2023-02-28 17:43:07 +00:00
|
|
|
StorageRoot string `db:"storage_root"`
|
|
|
|
Removed bool `db:"removed"`
|
|
|
|
}
|