diff --git a/Cargo.lock b/Cargo.lock index 2b5f798ce..a36be4add 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -523,6 +523,7 @@ dependencies = [ "chia-consensus", "chia-protocol", "chia-ssl", + "chia-traits 0.15.0", "clvm-utils", "clvmr", "hex", diff --git a/crates/chia-bls/benches/cache.rs b/crates/chia-bls/benches/cache.rs index cca3464a5..5265f270d 100644 --- a/crates/chia-bls/benches/cache.rs +++ b/crates/chia-bls/benches/cache.rs @@ -91,7 +91,7 @@ fn cache_benchmark(c: &mut Criterion) { ); c.bench_function("bls_cache.evict 5% of the items", |b| { - let mut cache = bls_cache.clone(); + let cache = bls_cache.clone(); let mut pks_shuffled = pks.clone(); pks_shuffled.shuffle(&mut rng); b.iter(|| { @@ -103,7 +103,7 @@ fn cache_benchmark(c: &mut Criterion) { }); c.bench_function("bls_cache.evict 100% of the items", |b| { - let mut cache = bls_cache.clone(); + let cache = bls_cache.clone(); let mut pks_shuffled = pks.clone(); pks_shuffled.shuffle(&mut rng); b.iter(|| { diff --git a/crates/chia-bls/src/bls_cache.rs b/crates/chia-bls/src/bls_cache.rs index 6fa46b780..188acc183 100644 --- a/crates/chia-bls/src/bls_cache.rs +++ b/crates/chia-bls/src/bls_cache.rs @@ -344,7 +344,7 @@ pub mod tests { #[test] fn test_evict() { - let mut bls_cache = BlsCache::new(NonZeroUsize::new(5).unwrap()); + let bls_cache = BlsCache::new(NonZeroUsize::new(5).unwrap()); // Create 5 pk msg pairs and add them to the cache. let mut pks_msgs = Vec::new(); for i in 1..=5 { diff --git a/crates/chia-protocol/src/bytes.rs b/crates/chia-protocol/src/bytes.rs index ac3e929fc..74f5c7962 100644 --- a/crates/chia-protocol/src/bytes.rs +++ b/crates/chia-protocol/src/bytes.rs @@ -392,14 +392,14 @@ impl From for Bytes32 { #[cfg(feature = "py-bindings")] impl ToPyObject for BytesImpl { fn to_object(&self, py: Python<'_>) -> PyObject { - PyBytes::new_bound(py, &self.0).into() + ChiaToPython::to_python(self, py).unwrap().into() } } #[cfg(feature = "py-bindings")] impl IntoPy for BytesImpl { fn into_py(self, py: Python<'_>) -> PyObject { - PyBytes::new_bound(py, &self.0).into() + ChiaToPython::to_python(&self, py).unwrap().into() } } diff --git a/crates/chia-protocol/src/coin.rs b/crates/chia-protocol/src/coin.rs index 4fbb74775..0a634285c 100644 --- a/crates/chia-protocol/src/coin.rs +++ b/crates/chia-protocol/src/coin.rs @@ -54,8 +54,8 @@ impl Coin { #[cfg(feature = "py-bindings")] #[pymethods] impl Coin { - fn name<'p>(&self, py: Python<'p>) -> Bound<'p, pyo3::types::PyBytes> { - pyo3::types::PyBytes::new_bound(py, &self.coin_id()) + fn name(&self) -> Bytes32 { + self.coin_id() } } diff --git a/tests/test_coin.py b/tests/test_coin.py index 9c4f3325d..b5935e445 100644 --- a/tests/test_coin.py +++ b/tests/test_coin.py @@ -3,6 +3,7 @@ import copy import pytest from chia_rs.sized_ints import uint64 +from chia_rs.sized_bytes import bytes32 parent_coin = b"---foo--- " puzzle_hash = b"---bar--- " @@ -385,3 +386,8 @@ def test_coin_fields() -> None: assert c1.parent_coin_info == parent_coin assert c1.puzzle_hash == puzzle_hash assert c1.amount == 1000000 + +def test_coin_print() -> None: + c1 = Coin(parent_coin, puzzle_hash, uint64(1000000)) + assert type(c1.name()) is bytes32 + assert f"{c1.name()}" == "e1838c5c7ebb472e310600ce9c03c09b5e4bb77dde53f3427f6e8cc67dede32d" diff --git a/tests/test_program.py b/tests/test_program.py index c0e5429e3..41992f15e 100644 --- a/tests/test_program.py +++ b/tests/test_program.py @@ -1,4 +1,5 @@ from chia_rs import run_chia_program, Program +from chia_rs.sized_bytes import bytes32 def test_raise() -> None: @@ -34,3 +35,8 @@ def test_repr() -> None: assert False except ValueError as e: assert f"{e}" == "('clvm raise', '83666f6f')" + +def test_print() -> None: + temp = Program.to([8, (1, "foo")]) + assert type(temp.get_tree_hash()) is bytes32 + assert f"{temp.get_tree_hash()}" == "a200d6417c8fdc7c7937382c1b61e219854e1efd8f2e15d6c88e6571bc29ed1a" diff --git a/wheel/Cargo.toml b/wheel/Cargo.toml index 3010aa1eb..f8d97b529 100644 --- a/wheel/Cargo.toml +++ b/wheel/Cargo.toml @@ -35,3 +35,4 @@ chia-protocol = { workspace = true, features = ["py-bindings"] } clvm-utils = { workspace = true } chia-ssl = { workspace = true } chia-client = { workspace = true } +chia-traits = { workspace = true } diff --git a/wheel/src/api.rs b/wheel/src/api.rs index 581e1e73d..bc7d6e08f 100644 --- a/wheel/src/api.rs +++ b/wheel/src/api.rs @@ -43,6 +43,7 @@ use chia_protocol::{ SubSlotProofs, TimestampedPeerInfo, TransactionAck, TransactionsInfo, UnfinishedBlock, UnfinishedHeaderBlock, VDFInfo, VDFProof, WeightProof, }; +use chia_traits::ChiaToPython; use clvm_utils::tree_hash_from_bytes; use clvmr::{LIMIT_HEAP, NO_UNKNOWN_OPS}; use pyo3::buffer::PyBuffer; @@ -113,9 +114,9 @@ pub fn confirm_not_included_already_hashed( } #[pyfunction] -pub fn tree_hash<'a>(py: Python<'a>, blob: PyBuffer) -> PyResult> { +pub fn tree_hash<'a>(py: Python<'a>, blob: PyBuffer) -> PyResult> { let slice = py_to_slice::<'a>(blob); - Ok(PyBytes::new_bound(py, &tree_hash_from_bytes(slice)?)) + ChiaToPython::to_python(&Bytes32::from(&tree_hash_from_bytes(slice)?.into()), py) } // there is an updated version of this function that doesn't require serializing