Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to #[classmethod] for SpendBundle::py_aggregate #678

Merged
merged 33 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
a4740e8
switch to classmethod for py_aggregate
matt-o-how Aug 26, 2024
d1f02d3
import under cfg feature
matt-o-how Aug 26, 2024
6a7ee09
update stubs
matt-o-how Aug 26, 2024
5985332
add test for derived class returning correctly
matt-o-how Aug 26, 2024
8644b38
change pystreamable macro to use classmethods instead of staticmethods
matt-o-how Aug 27, 2024
7c85ba1
fmt and clippy
matt-o-how Aug 27, 2024
1ab56bf
fix line ending format
matt-o-how Aug 27, 2024
c602f5c
black test
matt-o-how Aug 27, 2024
6c2a324
add tests for the streamable macro functions
matt-o-how Aug 29, 2024
7185a6b
fix tests to actually test what we're expecting
matt-o-how Aug 29, 2024
cfe8665
fix aggregate
matt-o-how Aug 30, 2024
eaa227b
nonworking commit for arvid
matt-o-how Sep 3, 2024
91205ae
fixup
arvidn Sep 3, 2024
5f0bab7
add downcasting step to streamable classmethods that support it
matt-o-how Sep 5, 2024
c256de6
fix tests and remove duplicate imports
matt-o-how Sep 5, 2024
b058c2d
add from_parent for OwnedSpendConditions and OwnedSpendBundleConditions
matt-o-how Sep 6, 2024
2723e1f
fmt
matt-o-how Sep 6, 2024
34ab0f9
fix stubs and use ?
matt-o-how Sep 9, 2024
58bf3ed
pushing broken optional skip to work from laptop
matt-o-how Sep 10, 2024
26bed89
fix
matt-o-how Sep 10, 2024
773be19
update all remaining streamable macros to use check and skip
matt-o-how Sep 10, 2024
6ba0981
update stubs to reflect new Streamable
matt-o-how Sep 10, 2024
dbef1e9
use py as paramter instead of calling with_gil()
matt-o-how Sep 10, 2024
71933f9
Add NotImplemented error for unsupported from_parent() calls
matt-o-how Sep 10, 2024
7f82ad3
re-enable from_parent in SpendBundle
matt-o-how Sep 11, 2024
89888cf
make error messages struct specific
matt-o-how Sep 12, 2024
763c1a7
fmt
matt-o-how Sep 13, 2024
423d41d
fix if statement for from_parent skip
matt-o-how Sep 13, 2024
b62d9d4
clippy fixes
matt-o-how Sep 13, 2024
ef7ecbe
add from_parent skip to aggregate()
matt-o-how Sep 13, 2024
f316c7e
clippy fix
matt-o-how Sep 13, 2024
2448708
Remove final with_gil()
matt-o-how Sep 16, 2024
2ebcd94
fmt
matt-o-how Sep 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions crates/chia-bls/src/gtelement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use clvmr::sha2::Sha256;
use pyo3::prelude::*;
#[cfg(feature = "py-bindings")]
use pyo3::types::PyType;
#[cfg(feature = "py-bindings")]
use pyo3::exceptions::PyNotImplementedError;
use std::fmt;
use std::hash::{Hash, Hasher};
use std::io::Cursor;
Expand Down Expand Up @@ -118,11 +120,8 @@ impl GTElement {

#[classmethod]
#[pyo3(name = "from_parent")]
pub fn from_parent(_cls: &Bound<'_, PyType>, instance: Self) -> PyResult<PyObject> {
Python::with_gil(|py| {
// ignore child case
Ok(instance.into_py(py))
})
pub fn from_parent(_cls: &Bound<'_, PyType>, _instance: Self) -> PyResult<PyObject> {
Err(PyNotImplementedError::new_err("This class does not support from_parent()."))
}

#[must_use]
Expand Down
9 changes: 4 additions & 5 deletions crates/chia-bls/src/public_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use clvmr::sha2::Sha256;
use pyo3::prelude::*;
#[cfg(feature = "py-bindings")]
use pyo3::types::PyType;
#[cfg(feature = "py-bindings")]
use pyo3::exceptions::PyNotImplementedError;
use std::fmt;
use std::hash::{Hash, Hasher};
use std::io::Cursor;
Expand Down Expand Up @@ -327,11 +329,8 @@ impl PublicKey {

#[classmethod]
#[pyo3(name = "from_parent")]
pub fn from_parent(_cls: &Bound<'_, PyType>, instance: Self) -> PyResult<PyObject> {
Python::with_gil(|py| {
// ignore child case
Ok(instance.into_py(py))
})
pub fn from_parent(_cls: &Bound<'_, PyType>, _instance: Self) -> PyResult<PyObject> {
Err(PyNotImplementedError::new_err("This class does not support from_parent()."))
}

#[pyo3(name = "get_fingerprint")]
Expand Down
9 changes: 4 additions & 5 deletions crates/chia-bls/src/secret_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use hkdf::HkdfExtract;
use pyo3::prelude::*;
#[cfg(feature = "py-bindings")]
use pyo3::types::PyType;
#[cfg(feature = "py-bindings")]
use pyo3::exceptions::PyNotImplementedError;
use std::fmt;
use std::hash::{Hash, Hasher};
use std::io::Cursor;
Expand Down Expand Up @@ -272,11 +274,8 @@ impl SecretKey {

#[classmethod]
#[pyo3(name = "from_parent")]
pub fn from_parent(_cls: &Bound<'_, PyType>, instance: Self) -> PyResult<PyObject> {
Python::with_gil(|py| {
// ignore child case
Ok(instance.into_py(py))
})
pub fn from_parent(_cls: &Bound<'_, PyType>, _instance: Self) -> PyResult<PyObject> {
Err(PyNotImplementedError::new_err("This class does not support from_parent()."))
}

#[pyo3(name = "derive_hardened")]
Expand Down
8 changes: 5 additions & 3 deletions crates/chia-bls/src/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use clvmr::sha2::Sha256;
use pyo3::prelude::*;
#[cfg(feature = "py-bindings")]
use pyo3::types::PyType;
#[cfg(feature = "py-bindings")]
use pyo3::exceptions::PyNotImplementedError;
use std::borrow::Borrow;
use std::fmt;
use std::hash::{Hash, Hasher};
Expand Down Expand Up @@ -494,10 +496,10 @@ impl Signature {
#[pyo3(name = "from_parent")]
pub fn from_parent(
_cls: &Bound<'_, PyType>,
py: Python<'_>,
instance: Self,
_py: Python<'_>,
arvidn marked this conversation as resolved.
Show resolved Hide resolved
_instance: Self,
) -> PyResult<PyObject> {
Ok(instance.into_py(py))
Err(PyNotImplementedError::new_err("This class does not support from_parent()."))
}

#[pyo3(name = "pair")]
Expand Down
17 changes: 7 additions & 10 deletions crates/chia-consensus/src/gen/owned_conditions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ use chia_py_streamable_macro::{PyJsonDict, PyStreamable};
use pyo3::prelude::*;
#[cfg(feature = "py-bindings")]
use pyo3::types::PyType;
#[cfg(feature = "py-bindings")]
use pyo3::exceptions::PyNotImplementedError;

#[derive(Streamable, Hash, Debug, Clone, Eq, PartialEq)]
#[cfg_attr(
Expand Down Expand Up @@ -155,11 +157,8 @@ fn convert_agg_sigs(a: &Allocator, agg_sigs: &[(PublicKey, NodePtr)]) -> Vec<(Pu
impl OwnedSpendConditions {
#[classmethod]
#[pyo3(name = "from_parent")]
pub fn from_parent(_cls: &Bound<'_, PyType>, instance: Self) -> PyResult<PyObject> {
Python::with_gil(|py| {
// ignore child case - though this could be extended in the future to support child class
Ok(instance.into_py(py))
})
pub fn from_parent(_cls: &Bound<'_, PyType>, _instance: Self) -> PyResult<PyObject> {
Err(PyNotImplementedError::new_err("This class does not support from_parent()."))
}
}

Expand All @@ -168,10 +167,8 @@ impl OwnedSpendConditions {
impl OwnedSpendBundleConditions {
#[classmethod]
#[pyo3(name = "from_parent")]
pub fn from_parent(_cls: &Bound<'_, PyType>, instance: Self) -> PyResult<PyObject> {
Python::with_gil(|py| {
// ignore child case - though this could be extended in the future to support child class
Ok(instance.into_py(py))
})
pub fn from_parent(_cls: &Bound<'_, PyType>, _instance: Self) -> PyResult<PyObject> {
Err(PyNotImplementedError::new_err("This class does not support from_parent()."))
}
}

11 changes: 4 additions & 7 deletions crates/chia-protocol/src/coin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use clvmr::sha2::Sha256;
use pyo3::prelude::*;
#[cfg(feature = "py-bindings")]
use pyo3::types::PyType;
#[cfg(feature = "py-bindings")]
use pyo3::exceptions::PyNotImplementedError;

#[streamable]
#[derive(Copy)]
Expand Down Expand Up @@ -62,13 +64,8 @@ impl Coin {
impl Coin {
#[classmethod]
#[pyo3(name = "from_parent")]
pub fn from_parent(cls: &Bound<'_, PyType>, coin: Self) -> PyResult<PyObject> {
Python::with_gil(|py| {
// Convert result into potential child class
let instance = cls.call1((coin.parent_coin_info, coin.puzzle_hash, coin.amount))?;

Ok(instance.into_py(py))
})
pub fn from_parent(_cls: &Bound<'_, PyType>, _coin: Self) -> PyResult<PyObject> {
Err(PyNotImplementedError::new_err("This class does not support from_parent()."))
}
}

Expand Down
7 changes: 2 additions & 5 deletions crates/chia-protocol/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,11 +492,8 @@ impl ToJsonDict for Program {
impl Program {
#[classmethod]
#[pyo3(name = "from_parent")]
pub fn from_parent(_cls: &Bound<'_, PyType>, instance: Self) -> PyResult<PyObject> {
Python::with_gil(|py| {
// ignore child case
Ok(instance.into_py(py))
})
pub fn from_parent(_cls: &Bound<'_, PyType>, _instance: Self) -> PyResult<PyObject> {
Err(PyNotImplementedError::new_err("This class does not support from_parent()."))
}
}

Expand Down
14 changes: 4 additions & 10 deletions crates/chia-protocol/src/spend_bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ use clvmr::ENABLE_FIXED_DIV;
use pyo3::prelude::*;
#[cfg(feature = "py-bindings")]
use pyo3::types::PyType;
#[cfg(feature = "py-bindings")]
use pyo3::exceptions::PyNotImplementedError;

#[streamable(subclass)]
pub struct SpendBundle {
Expand Down Expand Up @@ -113,16 +115,8 @@ impl SpendBundle {

#[classmethod]
#[pyo3(name = "from_parent")]
pub fn from_parent(cls: &Bound<'_, PyType>, spend_bundle: Self) -> PyResult<PyObject> {
Python::with_gil(|py| {
// Convert result into potential child class
let instance = cls.call(
(spend_bundle.coin_spends, spend_bundle.aggregated_signature),
None,
)?;

Ok(instance.into_py(py))
})
pub fn from_parent(_cls: &Bound<'_, PyType>, _spend_bundle: Self) -> PyResult<PyObject> {
Err(PyNotImplementedError::new_err("This class does not support from_parent()."))
}

#[pyo3(name = "name")]
Expand Down
Loading