nim-eth/eth/common/state_accessors.nim

24 lines
753 B
Nim
Raw Normal View History

2019-02-05 10:10:36 +00:00
import
../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)
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()
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:
let acc = getAccount(chain.getTrieDB, b.stateRoot, req.key)
2019-02-05 10:10:36 +00:00
result = chain.getCodeByHash(acc.codeHash)
proc getStorageNode*(chain: AbstractChainDB, hash: KeccakHash): Blob =
let db = chain.getTrieDB
2019-02-05 10:10:36 +00:00
return db.get(hash.data)