Example #1
0
 def set_root_hash(self, root_hash):
     assert is_string(root_hash)
     assert len(root_hash) in [0, 32]
     if root_hash == BLANK_ROOT:
         self.root_node = BLANK_NODE
         self._root_hash = BLANK_ROOT
         return
     self.root_node = self._decode_to_node(root_hash)
     self._root_hash = root_hash
Example #2
0
 def set_root_hash(self, root_hash):
     assert is_string(root_hash)
     assert len(root_hash) in [0, 32]
     if self.transient:
         self.transient_root_hash = root_hash
         return
     if root_hash == BLANK_ROOT:
         self.root_node = BLANK_NODE
         return
     self.root_node = self._decode_to_node(root_hash)
Example #3
0
    def update(self, key, value):
        '''
        :param key: a string
        :value: a string
        '''
        if not is_string(key):
            raise Exception("Key must be string")

        # if len(key) > 32:
        #     raise Exception("Max key length is 32")

        if not is_string(value):
            raise Exception("Value must be string")

        # if value == '':
        #     return self.delete(key)
        self.root_node = self._update_and_delete_storage(
            self.root_node, bin_to_nibbles(to_string(key)), to_string(value))
        self.get_root_hash()
Example #4
0
    def update(self, key, value):
        '''
        :param key: a string
        :value: a string
        '''
        if not is_string(key):
            raise Exception("Key must be string")

        # if len(key) > 32:
        #     raise Exception("Max key length is 32")

        if not is_string(value):
            raise Exception("Value must be string")

        # if value == '':
        #     return self.delete(key)
        self.root_node = self._update_and_delete_storage(
            self.root_node,
            bin_to_nibbles(to_string(key)),
            value)
        self.get_root_hash()
Example #5
0
    def delete(self, key):
        '''
        :param key: a string with length of [0, 32]
        '''
        if not is_string(key):
            raise Exception("Key must be string")

        if len(key) > 32:
            raise Exception("Max key length is 32")

        self.root_node = self._delete_and_delete_storage(
            self.root_node, bin_to_nibbles(to_string(key)))
        self.get_root_hash()
Example #6
0
    def delete(self, key):
        '''
        :param key: a string with length of [0, 32]
        '''
        if not is_string(key):
            raise Exception("Key must be string")

        if len(key) > 32:
            raise Exception("Max key length is 32")

        self.root_node = self._delete_and_delete_storage(
            self.root_node,
            bin_to_nibbles(to_string(key)))
        self.get_root_hash()
Example #7
0
 def _dec(x):
     if is_string(x) and x.startswith(b'0x'):
         return decode_hex(x[2:])
     return x
Example #8
0
 def _dec(x):
     if is_string(x) and x.startswith(b'0x'):
         return decode_hex(x[2:])
     return x
Example #9
0
 def encode_node(nd):
     if is_string(nd):
         return encode_hex(nd)
     else:
         return encode_hex(rlp.encode(nd))
Example #10
0
 def encode_node(nd):
     if is_string(nd):
         return encode_hex(nd)
     else:
         return encode_hex(rlp_encode(nd))