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 more datalayer types python constructable #883

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
33 changes: 33 additions & 0 deletions crates/chia-datalayer/src/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,25 @@ impl InternalNode {
}
}

#[cfg(feature = "py-bindings")]
#[pymethods]
impl InternalNode {
#[new]
pub fn py_init(
parent: Parent,
hash: Hash,
left: TreeIndex,
right: TreeIndex,
) -> PyResult<Self> {
Ok(Self {
parent,
hash,
left,
right,
})
}
}

#[cfg_attr(feature = "py-bindings", pyclass(get_all))]
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, Streamable)]
pub struct LeafNode {
Expand All @@ -238,6 +257,20 @@ pub struct LeafNode {
pub value: KvId,
}

#[cfg(feature = "py-bindings")]
#[pymethods]
impl LeafNode {
#[new]
pub fn py_init(parent: Parent, hash: Hash, key: KvId, value: KvId) -> PyResult<Self> {
Ok(Self {
parent,
hash,
key,
value,
})
}
}

#[derive(Clone, Debug, PartialEq, Eq)]
pub enum Node {
Internal(InternalNode),
Expand Down
4 changes: 4 additions & 0 deletions wheel/python/chia_rs/datalayer.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ METADATA_SIZE: int

@final
class InternalNode:
def __init__(self, parent: Optional[uint32], hash: bytes32, left: uint32, right: uint32) -> None: ...

@property
def parent(self) -> Optional[uint32]: ...
@property
Expand All @@ -25,6 +27,8 @@ class InternalNode:

@final
class LeafNode:
def __init__(self, parent: Optional[uint32], hash: bytes32, key: int64, value: int64) -> None: ...

@property
def parent(self) -> Optional[uint32]: ...
@property
Expand Down
Loading