Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
  • Loading branch information
altendky committed Oct 18, 2024
1 parent 64f5db6 commit 4bb157d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
4 changes: 2 additions & 2 deletions crates/chia-protocol/src/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ impl<const N: usize> ChiaToPython for BytesImpl<N> {

#[cfg(feature = "py-bindings")]
impl<'py, const N: usize> FromPyObject<'py> for BytesImpl<N> {
fn extract(obj: &'py PyAny) -> PyResult<Self> {
fn extract_bound(obj: &Bound<'py, PyAny>) -> PyResult<Self> {
let b = obj.downcast::<PyBytes>()?;
let slice: &[u8] = b.as_bytes();
let buf: [u8; N] = slice.try_into()?;
Expand Down Expand Up @@ -453,7 +453,7 @@ impl ChiaToPython for Bytes {

#[cfg(feature = "py-bindings")]
impl<'py> FromPyObject<'py> for Bytes {
fn extract(obj: &'py PyAny) -> PyResult<Self> {
fn extract_bound(obj: &Bound<'py, PyAny>) -> PyResult<Self> {
let b = obj.downcast::<PyBytes>()?;
Ok(Bytes(b.as_bytes().to_vec()))
}
Expand Down
12 changes: 8 additions & 4 deletions crates/chia_py_streamable_macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ pub fn py_streamable_macro(input: proc_macro::TokenStream) -> proc_macro::TokenS
syn::Data::Enum(_) => {
return quote! {
impl<'a> pyo3::conversion::FromPyObject<'a> for #ident {
fn extract(ob: &'a pyo3::PyAny) -> pyo3::PyResult<Self> {
fn extract_bound(ob: &pyo3::Bound<'a, pyo3::PyAny>) -> pyo3::PyResult<Self> {
use pyo3::types::PyAnyMethods;
let v: u8 = ob.extract()?;
<Self as #crate_name::Streamable>::parse::<false>(&mut std::io::Cursor::<&[u8]>::new(&[v])).map_err(|e| e.into())
}
Expand Down Expand Up @@ -132,11 +133,13 @@ pub fn py_streamable_macro(input: proc_macro::TokenStream) -> proc_macro::TokenS
#[pyo3::pymethods]
impl #ident {
#[pyo3(signature = (**kwargs))]
fn replace(&self, kwargs: Option<&pyo3::types::PyDict>) -> pyo3::PyResult<Self> {
fn replace(&self, kwargs: Option<&pyo3::Bound<pyo3::types::PyDict>>) -> pyo3::PyResult<Self> {
let mut ret = self.clone();
if let Some(kwargs) = kwargs {
let iter: pyo3::types::iter::PyDictIterator = kwargs.iter();
use pyo3::prelude::PyDictMethods;
let iter = kwargs.iter();
for (field, value) in iter {
use pyo3::prelude::PyAnyMethods;
let field = field.extract::<String>()?;
match field.as_str() {
#(stringify!(#fnames_maybe_upper) => {
Expand Down Expand Up @@ -323,9 +326,10 @@ pub fn py_streamable_macro(input: proc_macro::TokenStream) -> proc_macro::TokenS
impl #ident {
pub fn __setstate__(
&mut self,
state: &pyo3::types::PyBytes,
state: &pyo3::Bound<pyo3::types::PyBytes>,
) -> pyo3::PyResult<()> {
use chia_traits::Streamable;
use pyo3::types::PyBytesMethods;

*self = Self::parse::<true>(&mut std::io::Cursor::new(state.as_bytes()))?;

Expand Down
3 changes: 2 additions & 1 deletion wheel/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,11 @@ use chia_bls::{
#[pyfunction]
pub fn compute_merkle_set_root<'p>(
py: Python<'p>,
values: Vec<&'p PyBytes>,
values: Vec<Bound<'p, PyBytes>>,
) -> PyResult<Bound<'p, PyBytes>> {
let mut buffer = Vec::<[u8; 32]>::with_capacity(values.len());
for b in values {
use pyo3::types::PyBytesMethods;
buffer.push(b.as_bytes().try_into()?);
}
Ok(PyBytes::new_bound(
Expand Down

0 comments on commit 4bb157d

Please sign in to comment.