merkle-tree-stream/merkle_tree_stream/node.py

32 lines
712 B
Python
Raw Permalink Normal View History

2019-08-07 05:58:26 +00:00
"""A merkle tree node."""
from typing import Any, Optional
import attr
from flat_tree import FlatTreeAccessor
2020-05-16 16:37:43 +00:00
__all__ = ["MerkleTreeNode"]
2019-08-07 05:58:26 +00:00
@attr.s(auto_attribs=True)
class MerkleTreeNode:
"""A node in a merkle tree.
:param index: The index of node
:param parent: The parent of the node
:param size: The size of the data
:param data: The data of the node
:param hash: The hash of the data
"""
index: int
parent: int
size: int
data: bytes
hash: Optional[bytes] = attr.Factory(bytes)
2019-08-07 05:58:26 +00:00
def __attrs_post_init__(self) -> Any:
"""Initialise the parent index."""
flat_tree = FlatTreeAccessor()
self.parent = flat_tree.parent(self.index)