Skip to content

Commit

Permalink
Merge pull request #883 from Chia-Network/more_datalayer_types_python…
Browse files Browse the repository at this point in the history
…_constructable

make more datalayer types python constructable
  • Loading branch information
altendky authored Jan 22, 2025
2 parents 963d137 + 67d8550 commit a748a83
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
33 changes: 33 additions & 0 deletions crates/chia-datalayer/src/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,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 @@ -345,6 +364,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 @@ -33,6 +33,8 @@ class BlockIndexOutOfBoundsError(Exception): ...

@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 @@ -46,6 +48,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

0 comments on commit a748a83

Please sign in to comment.