mirror of
https://github.com/status-im/nim-eth.git
synced 2025-02-07 20:04:48 +00:00
`eth_types` is being imported from many projects and ends up causing long build times due to its extensive import lists - this PR starts cleaning some of that up by moving the chain DB and RLP to their own modules. this PR also moves `keccakHash` to its own module and uses it in many places.
28 lines
810 B
Nim
28 lines
810 B
Nim
import
|
|
../trie/[trie_defs, db, hexary],
|
|
../rlp,
|
|
./chaindb
|
|
|
|
export chaindb
|
|
|
|
proc getAccount*(db: TrieDatabaseRef,
|
|
rootHash: KeccakHash,
|
|
account: EthAddress): Account =
|
|
let trie = initSecureHexaryTrie(db, rootHash)
|
|
let data = trie.get(account)
|
|
if data.len > 0:
|
|
result = rlp.decode(data, Account)
|
|
else:
|
|
result = newAccount()
|
|
|
|
proc getContractCode*(chain: AbstractChainDB, req: ContractCodeRequest): Blob {.gcsafe.} =
|
|
let b = chain.getBlockHeader(req.blockHash)
|
|
if b.hasData:
|
|
let acc = getAccount(chain.getTrieDB, b.stateRoot, req.key)
|
|
result = chain.getCodeByHash(acc.codeHash)
|
|
|
|
proc getStorageNode*(chain: AbstractChainDB, hash: KeccakHash): Blob
|
|
{.raises: [CatchableError, Defect].} =
|
|
let db = chain.getTrieDB
|
|
return db.get(hash.data)
|