Skip to content

Commit

Permalink
Merge pull request #940 from Chia-Network/datalayer_pystreamable_for_…
Browse files Browse the repository at this point in the history
…ProofOfInclusion

make `ProofOfInclusion` and `ProofOfInclusionLayer` py streamable
  • Loading branch information
altendky authored Feb 20, 2025
2 parents 326e673 + 2a0ccdb commit 534439d
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 18 deletions.
29 changes: 12 additions & 17 deletions crates/chia-datalayer/src/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,29 +340,24 @@ pub enum NodeType {
Leaf = 1,
}

#[cfg_attr(feature = "py-bindings", pyclass(get_all))]
#[derive(Clone, Debug, Hash, Eq, PartialEq)]
#[cfg_attr(
feature = "py-bindings",
pyclass(get_all),
derive(PyJsonDict, PyStreamable)
)]
#[derive(Clone, Debug, Hash, Eq, PartialEq, Streamable)]
pub struct ProofOfInclusionLayer {
pub other_hash_side: Side,
pub other_hash: Hash,
pub combined_hash: Hash,
}

#[cfg(feature = "py-bindings")]
#[pymethods]
impl ProofOfInclusionLayer {
#[new]
pub fn py_init(other_hash_side: Side, other_hash: Hash, combined_hash: Hash) -> PyResult<Self> {
Ok(Self {
other_hash_side,
other_hash,
combined_hash,
})
}
}

#[cfg_attr(feature = "py-bindings", pyclass(get_all))]
#[derive(Clone, Debug, Hash, Eq, PartialEq)]
#[cfg_attr(
feature = "py-bindings",
pyclass(get_all),
derive(PyJsonDict, PyStreamable)
)]
#[derive(Clone, Debug, Hash, Eq, PartialEq, Streamable)]
pub struct ProofOfInclusion {
pub node_hash: Hash,
pub layers: Vec<ProofOfInclusionLayer>,
Expand Down
45 changes: 44 additions & 1 deletion wheel/python/chia_rs/datalayer.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,32 @@ class LeafNode:

@final
class ProofOfInclusionLayer:
def __init__(self, parent: Optional[uint32], hash: bytes32, left: uint32, right: uint32) -> None: ...
other_hash_side: uint8
other_hash: bytes32
combined_hash: bytes32

def __init__(self, other_hash_side: uint8, other_hash: bytes32, combined_hash: bytes32) -> None: ...

# TODO: generate
def __hash__(self) -> int: ...
def __repr__(self) -> str: ...
def __deepcopy__(self, memo: object) -> Self: ...
def __copy__(self) -> Self: ...
@classmethod
def from_bytes(cls, blob: bytes) -> Self: ...
@classmethod
def from_bytes_unchecked(cls, blob: bytes) -> Self: ...
@classmethod
def parse_rust(cls, blob: ReadableBuffer, trusted: bool = False) -> tuple[Self, int]: ...
def to_bytes(self) -> bytes: ...
def __bytes__(self) -> bytes: ...
def stream_to_bytes(self) -> bytes: ...
def get_hash(self) -> bytes32: ...
def to_json_dict(self) -> dict[str, Any]: ...
@classmethod
def from_json_dict(cls, json_dict: dict[str, Any]) -> Self: ...
def replace(self, *, other_hash_side: uint8 = ..., other_hash: bytes32 = ..., combined_hash: bytes32 = ...) -> Self: ...

@final
class ProofOfInclusion:
node_hash: bytes32
Expand All @@ -194,6 +215,28 @@ class ProofOfInclusion:
def root_hash(self) -> bytes32: ...
def valid(self) -> bool: ...

def __init__(self, node_hash: bytes32, layers: list[ProofOfInclusionLayer]) -> None: ...

# TODO: generate
def __hash__(self) -> int: ...
def __repr__(self) -> str: ...
def __deepcopy__(self, memo: object) -> Self: ...
def __copy__(self) -> Self: ...
@classmethod
def from_bytes(cls, blob: bytes) -> Self: ...
@classmethod
def from_bytes_unchecked(cls, blob: bytes) -> Self: ...
@classmethod
def parse_rust(cls, blob: ReadableBuffer, trusted: bool = False) -> tuple[Self, int]: ...
def to_bytes(self) -> bytes: ...
def __bytes__(self) -> bytes: ...
def stream_to_bytes(self) -> bytes: ...
def get_hash(self) -> bytes32: ...
def to_json_dict(self) -> dict[str, Any]: ...
@classmethod
def from_json_dict(cls, json_dict: dict[str, Any]) -> Self: ...
def replace(self, *, node_hash: bytes32 = ..., layers: list[ProofOfInclusionLayer] = ...) -> Self: ...

@final
class MerkleBlob:
@property
Expand Down

0 comments on commit 534439d

Please sign in to comment.