Skip to content

Commit

Permalink
SpendBundle only
Browse files Browse the repository at this point in the history
  • Loading branch information
Rigidity committed Aug 7, 2024
1 parent d262408 commit c208121
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion crates/chia-bls/src/secret_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::ops::{Add, AddAssign};

#[cfg_attr(
feature = "py-bindings",
pyo3::pyclass(frozen, subclass, name = "PrivateKey"),
pyo3::pyclass(frozen, name = "PrivateKey"),
derive(chia_py_streamable_macro::PyStreamable)
)]
#[derive(PartialEq, Eq, Clone)]
Expand Down
4 changes: 2 additions & 2 deletions crates/chia-consensus/src/gen/owned_conditions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use chia_py_streamable_macro::{PyJsonDict, PyStreamable};
#[derive(Streamable, Hash, Debug, Clone, Eq, PartialEq)]
#[cfg_attr(
feature = "py-bindings",
pyo3::pyclass(name = "Spend", get_all, frozen, subclass),
pyo3::pyclass(name = "Spend", get_all, frozen),
derive(PyJsonDict, PyStreamable)
)]
pub struct OwnedSpend {
Expand Down Expand Up @@ -39,7 +39,7 @@ pub struct OwnedSpend {
#[derive(Streamable, Hash, Debug, Clone, Eq, PartialEq)]
#[cfg_attr(
feature = "py-bindings",
pyo3::pyclass(name = "SpendBundleConditions", get_all, frozen, subclass),
pyo3::pyclass(name = "SpendBundleConditions", get_all, frozen),
derive(PyJsonDict, PyStreamable)
)]
pub struct OwnedSpendBundleConditions {
Expand Down
2 changes: 1 addition & 1 deletion crates/chia-consensus/src/merkle_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub enum ArrayTypes {

// represents a MerkleSet by putting all the nodes in a vec. Root is the last entry.
#[derive(PartialEq, Debug, Clone, Default)]
#[cfg_attr(feature = "py-bindings", pyclass(frozen, subclass, name = "MerkleSet"))]
#[cfg_attr(feature = "py-bindings", pyclass(frozen, name = "MerkleSet"))]
pub struct MerkleSet {
nodes_vec: Vec<(ArrayTypes, [u8; 32])>,
// This is true if the tree was built from a proof. This means the tree may
Expand Down
2 changes: 1 addition & 1 deletion crates/chia-protocol/src/spend_bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use clvmr::ENABLE_FIXED_DIV;
#[cfg(feature = "py-bindings")]
use pyo3::prelude::*;

#[streamable]
#[streamable(subclass)]
pub struct SpendBundle {
coin_spends: Vec<CoinSpend>,
aggregated_signature: G2Element,
Expand Down
9 changes: 8 additions & 1 deletion crates/chia_streamable_macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub fn streamable(attr: TokenStream, item: TokenStream) -> TokenStream {
};

let is_message = &attr.to_string() == "message";
let is_subclass = &attr.to_string() == "subclass";

let mut input: DeriveInput = parse_macro_input!(item);
let name = input.ident.clone();
Expand Down Expand Up @@ -92,13 +93,19 @@ pub fn streamable(attr: TokenStream, item: TokenStream) -> TokenStream {
#[derive(chia_streamable_macro::Streamable, Hash, Debug, Clone, Eq, PartialEq)]
};

let class_attrs = if is_subclass {
quote!(frozen, subclass)
} else {
quote!(frozen)
};

// If you're calling the macro from `chia-protocol`, enable Python bindings and arbitrary conditionally.
// Otherwise, you're calling it from an external crate which doesn't have this infrastructure setup.
// In that case, the caller can add these macros manually if they want to.
let attrs = if matches!(found_crate, FoundCrate::Itself) {
quote! {
#[cfg_attr(
feature = "py-bindings", pyo3::pyclass(frozen, subclass), derive(
feature = "py-bindings", pyo3::pyclass(#class_attrs), derive(
chia_py_streamable_macro::PyJsonDict,
chia_py_streamable_macro::PyStreamable,
chia_py_streamable_macro::PyGetters
Expand Down

0 comments on commit c208121

Please sign in to comment.