def get_new_trie_with_proof_nodes(proof_nodes):
        new_trie = Trie(KeyValueStorageInMemory())

        for node in proof_nodes:
            R = rlp_encode(node)
            H = sha3(R)
            new_trie._db.put(H, R)

        return new_trie
    def get_new_trie_with_proof_nodes(proof_nodes):
        new_trie = Trie(KeyValueStorageInMemory())

        for node in proof_nodes:
            R = rlp_encode(node)
            H = sha3(R)
            new_trie._db.put(H, R)

        return new_trie
Beispiel #3
0
 def get_root_hash(self):
     if self.transient:
         return self.transient_root_hash
     if self.root_node == BLANK_NODE:
         return BLANK_ROOT
     assert isinstance(self.root_node, list)
     val = rlp_encode(self.root_node)
     key = sha3(val)
     self.spv_grabbing(self.root_node)
     return key
 def get_root_hash(self):
     if self.transient:
         return self.transient_root_hash
     if self.root_node == BLANK_NODE:
         return BLANK_ROOT
     assert isinstance(self.root_node, list)
     val = rlp_encode(self.root_node)
     key = sha3(val)
     self.spv_grabbing(self.root_node)
     return key
Beispiel #5
0
    def _encode_node(self, node, is_root=False):
        if node == BLANK_NODE:
            return BLANK_NODE
        # assert isinstance(node, list)
        rlpnode = rlp_encode(node)
        if len(rlpnode) < 32 and not is_root:
            return node

        hashkey = sha3(rlpnode)
        self._db.inc_refcount(hashkey, rlpnode)
        return hashkey
    def _encode_node(self, node, is_root=False):
        if node == BLANK_NODE:
            return BLANK_NODE
        # assert isinstance(node, list)
        rlpnode = rlp_encode(node)
        if len(rlpnode) < 32 and not is_root:
            return node

        hashkey = sha3(rlpnode)
        self._db.inc_refcount(hashkey, rlpnode)
        return hashkey
Beispiel #7
0
    def verify_spv_proof(root, key, proof_nodes):
        proof.push(VERIFYING, proof_nodes)
        t = Trie(KeyValueStorageInMemory())

        for i, node in enumerate(proof_nodes):
            R = rlp_encode(node)
            H = sha3(R)
            t._db.put(H, R)
        try:
            t.root_hash = root
            t.get(key)
            proof.pop()
            return True
        except Exception as e:
            print(e)
            proof.pop()
            return False
Beispiel #8
0
 def _delete_node_storage(self, node, is_root=False):
     '''delete storage
     :param node: node in form of list, or BLANK_NODE
     '''
     if node == BLANK_NODE:
         return
     # assert isinstance(node, list)
     encoded = rlp_encode(node)
     if len(encoded) < 32 and not is_root:
         return
     """
     ===== FIXME ====
     in the current trie implementation two nodes can share identical
     subtrees thus we can not safely delete nodes for now
     """
     hashkey = sha3(encoded)
     self._db.dec_refcount(hashkey)
 def _delete_node_storage(self, node, is_root=False):
     '''delete storage
     :param node: node in form of list, or BLANK_NODE
     '''
     if node == BLANK_NODE:
         return
     # assert isinstance(node, list)
     encoded = rlp_encode(node)
     if len(encoded) < 32 and not is_root:
         return
     """
     ===== FIXME ====
     in the current trie implementation two nodes can share identical
     subtrees thus we can not safely delete nodes for now
     """
     hashkey = sha3(encoded)
     self._db.dec_refcount(hashkey)
    def verify_spv_proof(root, key, value, proof_nodes, serialized=False):
        # NOTE: `root` is a derivative of the last element of `proof_nodes`
        # but it's important to keep `root` as a separate as signed root
        # hashes will be published.
        if serialized:
            proof_nodes = Trie.deserialize_proof(proof_nodes)
        proof.push(VERIFYING, proof_nodes)
        new_trie = Trie(KeyValueStorageInMemory())

        for node in proof_nodes:
            R = rlp_encode(node)
            H = sha3(R)
            new_trie._db.put(H, R)
        try:
            new_trie.root_hash = root
            v = new_trie.get(key)
            proof.pop()
            return v == value
        except Exception as e:
            print(e)
            proof.pop()
            return False