mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-02-26 02:45:29 +00:00
add raises to public API
This commit is contained in:
parent
1ef3f60b40
commit
6a9555b2b9
@ -1,5 +1,5 @@
|
||||
import
|
||||
randutils, stew/byteutils, random,
|
||||
randutils, random,
|
||||
eth/[common, rlp], eth/trie/[hexary, db, trie_defs],
|
||||
faststreams/input_stream, nimcrypto/sysrand,
|
||||
../stateless/[witness_from_tree, tree_from_witness],
|
||||
|
@ -146,7 +146,8 @@ proc accountStorageLeafNode(t: var TreeBuilder, depth: int): NodeKey
|
||||
proc hashNode(t: var TreeBuilder): NodeKey
|
||||
proc treeNode(t: var TreeBuilder, depth: int = 0, storageMode = false): NodeKey
|
||||
|
||||
proc buildTree*(t: var TreeBuilder): KeccakHash =
|
||||
proc buildTree*(t: var TreeBuilder): KeccakHash
|
||||
{.raises: [ContractCodeError, Defect, IOError, ParsingError, Exception].} =
|
||||
let version = t.safeReadByte().int
|
||||
if version != BlockWitnessVersion.int:
|
||||
raise newException(ParsingError, "Wrong block witness version")
|
||||
@ -164,7 +165,8 @@ proc buildTree*(t: var TreeBuilder): KeccakHash =
|
||||
|
||||
result.data = res.data
|
||||
|
||||
proc buildForest*(t: var TreeBuilder): seq[KeccakHash] =
|
||||
proc buildForest*(t: var TreeBuilder): seq[KeccakHash]
|
||||
{.raises: [ContractCodeError, Defect, IOError, ParsingError, Exception].} =
|
||||
let version = t.safeReadByte().int
|
||||
if version != BlockWitnessVersion.int:
|
||||
raise newException(ParsingError, "Wrong block witness version")
|
||||
|
@ -193,7 +193,8 @@ proc writeShortNode(wb: var WitnessBuilder, node: openArray[byte], depth: int, s
|
||||
# 17th elem should always empty
|
||||
doAssert branchMask.branchMaskBitIsSet(16) == false
|
||||
else:
|
||||
raise newException(CorruptedTrieDatabase, "Bad Short Node")
|
||||
raise newException(CorruptedTrieDatabase,
|
||||
"HexaryTrie short node with an unexpected number of children")
|
||||
|
||||
proc getBranchRecurseAux(wb: var WitnessBuilder, node: openArray[byte], path: NibblesSeq, depth: int, storageMode: bool) =
|
||||
var nodeRlp = rlpFromBytes node
|
||||
@ -244,7 +245,9 @@ proc getBranchRecurseAux(wb: var WitnessBuilder, node: openArray[byte], path: Ni
|
||||
raise newException(CorruptedTrieDatabase,
|
||||
"HexaryTrie node with an unexpected number of children")
|
||||
|
||||
proc buildWitness*(wb: var WitnessBuilder; address: EthAddress, withVersion: bool = true): seq[byte] =
|
||||
proc buildWitness*(wb: var WitnessBuilder; address: EthAddress, withVersion: bool = true): seq[byte]
|
||||
{.raises: [ContractCodeError, IOError, WitnessError, Defect].} =
|
||||
|
||||
# witness version
|
||||
wb.output.append(BlockWitnessVersion.byte)
|
||||
|
||||
@ -253,8 +256,12 @@ proc buildWitness*(wb: var WitnessBuilder; address: EthAddress, withVersion: boo
|
||||
# we only output one tree
|
||||
wb.output.append(MetadataNothing.byte)
|
||||
let key = keccak(address)
|
||||
var node = wb.db.get(wb.root.data)
|
||||
getBranchRecurseAux(wb, node, initNibbleRange(key.data), 0, false)
|
||||
|
||||
try:
|
||||
var node = wb.db.get(wb.root.data)
|
||||
getBranchRecurseAux(wb, node, initNibbleRange(key.data), 0, false)
|
||||
except CorruptedTrieDatabase, RlpTypeMismatch, CatchableError, Exception:
|
||||
raise newException(WitnessError, getCurrentExceptionMsg())
|
||||
|
||||
# result
|
||||
result = wb.output.getOutput(seq[byte])
|
||||
|
@ -23,6 +23,7 @@ type
|
||||
|
||||
ContractCodeError* = object of ValueError
|
||||
ParsingError* = object of ValueError
|
||||
WitnessError* = object of ValueError
|
||||
|
||||
const
|
||||
StorageLeafNodeType* = AccountNodeType
|
||||
|
Loading…
x
Reference in New Issue
Block a user