fix buildWitness API
This commit is contained in:
parent
4e12ba825c
commit
4974ca49db
|
@ -30,7 +30,7 @@ proc testGetBranch(tester: Tester, rootHash: KeccakHash, testStatusIMPL: var Tes
|
|||
#try:
|
||||
for address in tester.address:
|
||||
var wb = initWitnessBuilder(tester.memdb, rootHash)
|
||||
var witness = wb.getBranchRecurse(address)
|
||||
var witness = wb.buildWitness(address)
|
||||
|
||||
var db = newMemoryDB()
|
||||
when defined(useInputStream):
|
||||
|
|
|
@ -43,20 +43,23 @@ proc randAccount(db: DB): Account =
|
|||
result.codeHash = randCode(db)
|
||||
result.storageRoot = randStorage(db)
|
||||
|
||||
proc randAddress(): EthAddress =
|
||||
discard randomBytes(result.addr, sizeof(result))
|
||||
|
||||
proc runTest(numPairs: int) =
|
||||
var memDB = newMemoryDB()
|
||||
var trie = initSecureHexaryTrie(memDB)
|
||||
var addrs = newSeq[Bytes](numPairs)
|
||||
var addrs = newSeq[EthAddress](numPairs)
|
||||
|
||||
for i in 0..<numPairs:
|
||||
addrs[i] = randList(byte, rng(0, 255), 20, unique = false)
|
||||
addrs[i] = randAddress()
|
||||
let acc = randAccount(memDB)
|
||||
trie.put(addrs[i], rlp.encode(acc))
|
||||
|
||||
let rootHash = trie.rootHash
|
||||
|
||||
var wb = initWitnessBuilder(memDB, rootHash)
|
||||
var witness = wb.getBranchRecurse(hexary.keccak(addrs[0]).data)
|
||||
var witness = wb.buildWitness(addrs[0])
|
||||
var db = newMemoryDB()
|
||||
when defined(useInputStream):
|
||||
var input = memoryInput(witness)
|
||||
|
|
|
@ -241,7 +241,8 @@ proc getBranchRecurseAux(wb: var WitnessBuilder, node: openArray[byte], path: Ni
|
|||
raise newException(CorruptedTrieDatabase,
|
||||
"HexaryTrie node with an unexpected number of children")
|
||||
|
||||
proc getBranchRecurse*(wb: var WitnessBuilder; key: openArray[byte]): seq[byte] =
|
||||
proc buildWitness*(wb: var WitnessBuilder; address: EthAddress): seq[byte] =
|
||||
let key = keccak(address)
|
||||
var node = wb.db.get(wb.root.data)
|
||||
getBranchRecurseAux(wb, node, initNibbleRange(key), 0, false)
|
||||
getBranchRecurseAux(wb, node, initNibbleRange(key.data), 0, false)
|
||||
result = wb.output.getOutput(seq[byte])
|
||||
|
|
|
@ -13,7 +13,8 @@ type
|
|||
|
||||
const
|
||||
StorageLeafNodeType* = AccountNodeType
|
||||
|
||||
BlockWitnessVersion* = 0x01
|
||||
|
||||
proc setBranchMaskBit*(x: var uint, i: int) {.inline.} =
|
||||
assert(i >= 0 and i < 17)
|
||||
x = x or (1 shl i).uint
|
||||
|
|
Loading…
Reference in New Issue