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
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)
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()
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()
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()
def _dec(x): if is_string(x) and x.startswith(b'0x'): return decode_hex(x[2:]) return x
def encode_node(nd): if is_string(nd): return encode_hex(nd) else: return encode_hex(rlp.encode(nd))
def encode_node(nd): if is_string(nd): return encode_hex(nd) else: return encode_hex(rlp_encode(nd))