Zeth - Zerocash on Ethereum  0.8
Reference implementation of the Zeth protocol by Clearmatics
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
zeth.core.merkle_tree.PersistentMerkleTree Class Reference
Inheritance diagram for zeth.core.merkle_tree.PersistentMerkleTree:
Inheritance graph
[legend]
Collaboration diagram for zeth.core.merkle_tree.PersistentMerkleTree:
Collaboration graph
[legend]

Public Member Functions

def __init__ (self, str filename, MerkleTreeData tree_data, int depth, ITreeHash tree_hash)
 
None save (self)
 
- Public Member Functions inherited from zeth.core.merkle_tree.MerkleTree
def __init__ (self, MerkleTreeData tree_data, int depth, ITreeHash tree_hash)
 
int get_num_entries (self)
 
bytes get_leaf (self, int index)
 
List[bytes] get_leaves (self)
 
bytes get_node (self, int layer_idx, int node_idx)
 
Iterator[Tuple[bytes, List[bytes]]] get_layers (self)
 
bytes get_root (self)
 
None insert (self, bytes value)
 
bytes recompute_root (self)
 

Static Public Member Functions

PersistentMerkleTree open (str filename, int max_num_leaves, ITreeHash tree_hash)
 
- Static Public Member Functions inherited from zeth.core.merkle_tree.MerkleTree
MerkleTree empty_with_depth (int depth, ITreeHash tree_hash)
 
MerkleTree empty_with_size (int num_leaves, ITreeHash tree_hash)
 

Public Attributes

 filename
 
- Public Attributes inherited from zeth.core.merkle_tree.MerkleTree
 max_num_leaves
 
 depth
 
 tree_data
 
 num_new_leaves
 
 tree_hash
 

Detailed Description

Version of MerkleTree that also supports persistence.

Definition at line 209 of file merkle_tree.py.

Constructor & Destructor Documentation

◆ __init__()

def zeth.core.merkle_tree.PersistentMerkleTree.__init__ (   self,
str  filename,
MerkleTreeData  tree_data,
int  depth,
ITreeHash  tree_hash 
)

Definition at line 213 of file merkle_tree.py.

213  def __init__(
214  self,
215  filename: str,
216  tree_data: MerkleTreeData,
217  depth: int,
218  tree_hash: ITreeHash):
219  MerkleTree.__init__(self, tree_data, depth, tree_hash)
220  self.filename = filename
221 

Member Function Documentation

◆ open()

PersistentMerkleTree zeth.core.merkle_tree.PersistentMerkleTree.open ( str  filename,
int  max_num_leaves,
ITreeHash  tree_hash 
)
static

Definition at line 223 of file merkle_tree.py.

223  def open(
224  filename: str,
225  max_num_leaves: int,
226  tree_hash: ITreeHash) -> PersistentMerkleTree:
227  depth = int(math.log(max_num_leaves, 2))
228  assert max_num_leaves == int(math.pow(2, depth))
229  if exists(filename):
230  with open(filename, "r") as tree_f:
231  json_dict = json.load(tree_f)
232  tree_data = MerkleTreeData.from_json_dict(json_dict)
233  assert depth == tree_data.depth
234  else:
235  tree_data = MerkleTree._empty_data_with_depth(depth, tree_hash)
236 
237  return PersistentMerkleTree(filename, tree_data, depth, tree_hash)
238 
Here is the caller graph for this function:

◆ save()

None zeth.core.merkle_tree.PersistentMerkleTree.save (   self)

Definition at line 239 of file merkle_tree.py.

239  def save(self) -> None:
240  with open(self.filename, "w") as tree_f:
241  json.dump(self.tree_data.to_json_dict(), tree_f)
242 
243 
Here is the call graph for this function:

Member Data Documentation

◆ filename

zeth.core.merkle_tree.PersistentMerkleTree.filename

Definition at line 215 of file merkle_tree.py.


The documentation for this class was generated from the following file:
zeth.cli.zeth_deploy.int
int
Definition: zeth_deploy.py:27