import "."/[trie_bitseq, trie_defs, trie_utils, db, sparse_proofs] export trie_utils, trie_bitseq, sparse_proofs.verifyProof type DB = TrieDatabaseRef SparseBinaryTrie* = object db: DB rootHash: seq[byte] type # 256 * 2 div 8 DoubleHash = array[64, byte] proc initDoubleHash(a, b: openArray[byte]): DoubleHash = doAssert(a.len == 32, $a.len) doAssert(b.len == 32, $b.len) result[0..31] = a result[32..^1] = b proc initDoubleHash(x: openArray[byte]): DoubleHash = initDoubleHash(x, x) proc init*(x: typedesc[SparseBinaryTrie], db: DB): SparseBinaryTrie = result.db = db # Initialize an empty tree with one branch var value = initDoubleHash(emptyNodeHashes[0].data) result.rootHash = @(keccakHash(value).data) result.db.put(result.rootHash, value) for i in 0..