From 9b33d14dcd7f89f76471634a949ff6f0e0d4f785 Mon Sep 17 00:00:00 2001 From: Rigidity Date: Mon, 8 Jul 2024 14:54:41 -0400 Subject: [PATCH] Subclassable spend bundle --- crates/chia-protocol/src/spend_bundle.rs | 2 +- crates/chia_streamable_macro/src/lib.rs | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/crates/chia-protocol/src/spend_bundle.rs b/crates/chia-protocol/src/spend_bundle.rs index 1db81fa7f..62778fa65 100644 --- a/crates/chia-protocol/src/spend_bundle.rs +++ b/crates/chia-protocol/src/spend_bundle.rs @@ -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, aggregated_signature: G2Element, diff --git a/crates/chia_streamable_macro/src/lib.rs b/crates/chia_streamable_macro/src/lib.rs index 95b6ee491..3b6360488 100644 --- a/crates/chia_streamable_macro/src/lib.rs +++ b/crates/chia_streamable_macro/src/lib.rs @@ -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(); @@ -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