2019-02-05 10:10:36 +00:00
|
|
|
import
|
2019-02-05 16:54:58 +00:00
|
|
|
eth/trie/[trie_defs, db, hexary], eth/rlp,
|
2019-02-05 10:10:36 +00:00
|
|
|
eth_types
|
|
|
|
|
|
|
|
proc getAccount*(db: TrieDatabaseRef,
|
|
|
|
rootHash: KeccakHash,
|
|
|
|
account: EthAddress): Account =
|
|
|
|
let trie = initSecureHexaryTrie(db, rootHash)
|
|
|
|
let data = trie.get(unnecessary_OpenArrayToRange account)
|
|
|
|
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)
|
|
|
|
|
2019-03-13 01:37:04 +00:00
|
|
|
proc getStorageNode*(chain: AbstractChainDB, hash: KeccakHash): Blob =
|
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)
|
|
|
|
# let trie = initSecureHexaryTrie(db, emptyRlpHash) # TODO emptyRlpHash is not correct here
|
|
|
|
# return trie.get(unnecessary_OpenArrayToRange hash.data)
|
|
|
|
|