2019-02-05 10:10:36 +00:00
|
|
|
import
|
2021-04-06 11:33:24 +00:00
|
|
|
../trie/[trie_defs, db, hexary], ../rlp,
|
|
|
|
./eth_types
|
2019-02-05 10:10:36 +00:00
|
|
|
|
|
|
|
proc getAccount*(db: TrieDatabaseRef,
|
|
|
|
rootHash: KeccakHash,
|
|
|
|
account: EthAddress): Account =
|
|
|
|
let trie = initSecureHexaryTrie(db, rootHash)
|
2020-04-20 18:14:39 +00:00
|
|
|
let data = trie.get(account)
|
2019-02-05 10:10:36 +00:00
|
|
|
if data.len > 0:
|
|
|
|
result = rlp.decode(data, Account)
|
|
|
|
else:
|
|
|
|
result = newAccount()
|
|
|
|
|
2019-03-13 01:37:04 +00:00
|
|
|
proc getContractCode*(chain: AbstractChainDB, req: ContractCodeRequest): Blob {.gcsafe.} =
|
2019-02-05 10:10:36 +00:00
|
|
|
let b = chain.getBlockHeader(req.blockHash)
|
|
|
|
if b.hasData:
|
2019-03-13 20:35:22 +00:00
|
|
|
let acc = getAccount(chain.getTrieDB, b.stateRoot, req.key)
|
2019-02-05 10:10:36 +00:00
|
|
|
result = chain.getCodeByHash(acc.codeHash)
|
|
|
|
|
2021-05-06 15:20:54 +00:00
|
|
|
proc getStorageNode*(chain: AbstractChainDB, hash: KeccakHash): Blob
|
|
|
|
{.raises: [CatchableError, Defect].} =
|
2019-03-13 20:35:22 +00:00
|
|
|
let db = chain.getTrieDB
|
2019-02-05 10:10:36 +00:00
|
|
|
return db.get(hash.data)
|