Пример #1
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
     # print(repr(root_hash))
     self.root_node = self._decode_to_node(root_hash)
Пример #2
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)
        old_root = copy.deepcopy(self.root_node)
        self.root_node = self._update_and_delete_storage(
            self.root_node, bin_to_nibbles(to_string(key)), to_string(value))
        self.replace_root_hash(old_root, self.root_node)
Пример #3
0
 def set_root_hash(self, root_hash):
     if not is_string(root_hash):
         raise PlenumTypeError('root_hash', root_hash, bytes)
     if not (len(root_hash) in [0, 32]):
         raise PlenumValueError('root_hash', root_hash, 'length in range [0, 32]')
     if self.transient:
         self.transient_root_hash = root_hash
         return
     if root_hash == BLANK_ROOT:
         self.root_node = BLANK_NODE
         return
     # print(repr(root_hash))
     self.root_node = self._decode_to_node(root_hash)
Пример #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)
        old_root = copy.deepcopy(self.root_node)
        self.root_node = self._update_and_delete_storage(
            self.root_node,
            bin_to_nibbles(to_string(key)),
            to_string(value))
        self.replace_root_hash(old_root, self.root_node)
Пример #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")

        old_root = copy.deepcopy(self.root_node)
        self.root_node = self._delete_and_delete_storage(
            self.root_node, bin_to_nibbles(to_string(key)))
        self.replace_root_hash(old_root, self.root_node)
Пример #6
0
 def set_root_hash(self, root_hash):
     if not is_string(root_hash):
         raise PlenumTypeError('root_hash', root_hash, bytes)
     if not (len(root_hash) in [0, 32]):
         raise PlenumValueError('root_hash', root_hash,
                                'length in range [0, 32]')
     if self.transient:
         self.transient_root_hash = root_hash
         return
     if root_hash == BLANK_ROOT:
         self.root_node = BLANK_NODE
         return
     # print(repr(root_hash))
     self.root_node = self._decode_to_node(root_hash)
Пример #7
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")

        old_root = copy.deepcopy(self.root_node)
        self.root_node = self._delete_and_delete_storage(
            self.root_node,
            bin_to_nibbles(to_string(key)))
        self.replace_root_hash(old_root, self.root_node)
Пример #8
0
 def encode_node(nd):
     if is_string(nd):
         return encode_hex(nd)
     else:
         return encode_hex(rlp_encode(nd))