Skip to content

Commit

Permalink
try more derive etc
Browse files Browse the repository at this point in the history
  • Loading branch information
altendky committed Jan 8, 2025
1 parent bcbb571 commit ed70cf7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ unused_import_braces = "deny"
unreachable_code = "deny"
unreachable_patterns = "deny"
dead_code = "deny"
deprecated = "allow"
deprecated = "deny"
deprecated_in_future = "deny"
trivial_casts = "deny"
trivial_numeric_casts = "deny"
Expand Down
26 changes: 14 additions & 12 deletions crates/chia-datalayer/src/merkle.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[cfg(feature = "py-bindings")]
use pyo3::{
buffer::PyBuffer, exceptions::PyValueError, pyclass, pymethods, FromPyObject, IntoPy,
IntoPyObject, PyObject, PyResult, Python,
buffer::PyBuffer, exceptions::PyValueError, pyclass, pymethods, Bound, FromPyObject,
IntoPyObject, PyAny, PyErr, PyResult, Python,
};

use chia_protocol::Bytes32;
Expand Down Expand Up @@ -301,11 +301,15 @@ impl Node {
}

#[cfg(feature = "py-bindings")]
impl IntoPy<PyObject> for Node {
fn into_py(self, py: Python<'_>) -> PyObject {
impl<'py> IntoPyObject<'py> for Node {
type Target = PyAny;
type Output = Bound<'py, Self::Target>;
type Error = PyErr;

fn into_pyobject(self, py: Python<'py>) -> Result<Self::Output, Self::Error> {
match self {
Node::Internal(node) => node.into_py(py),
Node::Leaf(node) => node.into_py(py),
Node::Internal(node) => Ok(node.into_pyobject(py)?.into_any()),
Node::Leaf(node) => Ok(node.into_pyobject(py)?.into_any()),
}
}
}
Expand Down Expand Up @@ -1266,29 +1270,27 @@ impl MerkleBlob {
index: TreeIndex,
py: Python<'_>,
) -> PyResult<pyo3::PyObject> {
let list = pyo3::types::PyList::empty_bound(py);
let list = pyo3::types::PyList::empty(py);

for (index, node) in self
.get_lineage_with_indexes(index)
.map_err(|e| PyValueError::new_err(e.to_string()))?
{
use pyo3::conversion::IntoPy;
use pyo3::types::PyListMethods;
list.append((index.into_pyobject(py)?, node.into_py(py)))?;
list.append((index.into_pyobject(py)?, node.into_pyobject(py)?))?;
}

Ok(list.into())
}

#[pyo3(name = "get_nodes_with_indexes")]
pub fn py_get_nodes_with_indexes(&self, py: Python<'_>) -> PyResult<pyo3::PyObject> {
let list = pyo3::types::PyList::empty_bound(py);
let list = pyo3::types::PyList::empty(py);

for item in MerkleBlobParentFirstIterator::new(&self.blob) {
use pyo3::conversion::IntoPy;
use pyo3::types::PyListMethods;
let (index, block) = item.map_err(|e| PyValueError::new_err(e.to_string()))?;
list.append((index.into_pyobject(py)?, block.node.into_py(py)))?;
list.append((index.into_pyobject(py)?, block.node.into_pyobject(py)?))?;
}

Ok(list.into())
Expand Down

0 comments on commit ed70cf7

Please sign in to comment.