Skip to content

Commit

Permalink
Merge branch 'main' into merkle_blob
Browse files Browse the repository at this point in the history
  • Loading branch information
altendky committed Oct 18, 2024
2 parents ae77486 + 519a82e commit f22ac25
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 78 deletions.
84 changes: 15 additions & 69 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ sha2 = "0.10.8"
hkdf = "0.12.0"
hex = "0.4.3"
thiserror = "1.0.63"
pyo3 = "0.21.2"
pyo3 = "0.22.5"
arbitrary = "1.3.2"
lru = "0.12.4"
rand = "0.8.5"
Expand Down
1 change: 1 addition & 0 deletions crates/chia-bls/src/secret_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ impl SecretKey {
#[classattr]
pub const PRIVATE_KEY_SIZE: usize = 32;

#[pyo3(signature = (msg, final_pk=None))]
pub fn sign(&self, msg: &[u8], final_pk: Option<PublicKey>) -> crate::Signature {
match final_pk {
Some(prefix) => {
Expand Down
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
14 changes: 9 additions & 5 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 @@ -306,7 +309,7 @@ pub fn py_streamable_macro(input: proc_macro::TokenStream) -> proc_macro::TokenS
self.py_to_bytes(py)
}

pub fn __deepcopy__<'p>(&self, memo: &pyo3::PyAny) -> pyo3::PyResult<Self> {
pub fn __deepcopy__<'p>(&self, memo: &pyo3::Bound<pyo3::PyAny>) -> pyo3::PyResult<Self> {
Ok(self.clone())
}

Expand All @@ -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 @@ -80,10 +80,11 @@ use chia_datalayer::MerkleBlob;
#[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 f22ac25

Please sign in to comment.