Skip to content

Commit

Permalink
Merge pull request #653 from Chia-Network/subclass-v2
Browse files Browse the repository at this point in the history
Subclass on SpendBundle only
  • Loading branch information
arvidn authored Aug 7, 2024
2 parents e1cb0e8 + c208121 commit ad3235e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
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), 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 ad3235e

Please sign in to comment.