mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-13 13:55:45 +00:00
InputStream still unstable, use seq[byte] again
This commit is contained in:
parent
692bed176e
commit
a540b8cbeb
@ -33,8 +33,12 @@ proc testGetBranch(tester: Tester, rootHash: KeccakHash, testStatusIMPL: var Tes
|
||||
var witness = wb.getBranchRecurse(address)
|
||||
|
||||
var db = newMemoryDB()
|
||||
when defined(useInputStream):
|
||||
var input = memoryInput(witness)
|
||||
var tb = initTreeBuilder(input, db)
|
||||
else:
|
||||
var tb = initTreeBuilder(witness, db)
|
||||
|
||||
var root = tb.treeNode()
|
||||
check root.data == rootHash.data
|
||||
|
||||
|
@ -11,10 +11,19 @@ type
|
||||
data*: array[32, byte]
|
||||
|
||||
TreeBuilder = object
|
||||
when defined(useInputStream):
|
||||
input: InputStream
|
||||
else:
|
||||
input: seq[byte]
|
||||
pos: int
|
||||
db: DB
|
||||
root: KeccakHash
|
||||
|
||||
# the InputStream still unstable
|
||||
# when using large dataset for testing
|
||||
# or run longer
|
||||
|
||||
when defined(useInputStream):
|
||||
proc initTreeBuilder*(input: InputStream, db: DB): TreeBuilder =
|
||||
result.input = input
|
||||
result.db = db
|
||||
@ -24,6 +33,11 @@ proc initTreeBuilder*(input: openArray[byte], db: DB): TreeBuilder =
|
||||
result.input = memoryInput(input)
|
||||
result.db = db
|
||||
result.root = emptyRlpHash
|
||||
else:
|
||||
proc initTreeBuilder*(input: openArray[byte], db: DB): TreeBuilder =
|
||||
result.input = @input
|
||||
result.db = db
|
||||
result.root = emptyRlpHash
|
||||
|
||||
func rootHash*(t: TreeBuilder): KeccakHash {.inline.} =
|
||||
t.root
|
||||
@ -32,18 +46,34 @@ proc writeNode(t: var TreeBuilder, n: openArray[byte]): KeccakHash =
|
||||
result = keccak(n)
|
||||
t.db.put(result.data, n)
|
||||
|
||||
when defined(useInputStream):
|
||||
template readByte(t: var TreeBuilder): byte =
|
||||
t.input.read
|
||||
|
||||
template len(t: TreeBuilder): int =
|
||||
t.input.len
|
||||
|
||||
template peek(t: TreeBuilder): byte =
|
||||
t.input.peek
|
||||
|
||||
template read(t: var TreeBuilder, len: int): auto =
|
||||
t.input.read(len)
|
||||
|
||||
else:
|
||||
template readByte(t: var TreeBuilder): byte =
|
||||
let pos = t.pos
|
||||
inc t.pos
|
||||
t.input[pos]
|
||||
|
||||
template len(t: TreeBuilder): int =
|
||||
t.input.len
|
||||
|
||||
template peek(t: TreeBuilder): byte =
|
||||
t.input.peek
|
||||
t.input[t.pos]
|
||||
|
||||
template read(t: var TreeBuilder, len: int): auto =
|
||||
let pos = t.pos
|
||||
inc(t.pos, len)
|
||||
toOpenArray(t.input, pos, pos+len-1)
|
||||
|
||||
proc readU32(t: var TreeBuilder): uint32 =
|
||||
result = fromBytesBE(uint32, t.read(4))
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user