Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make ProofOfInclusion and ProofOfInclusionLayer py streamable #940

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading