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

Subclassable spend bundle #600

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
10 changes: 8 additions & 2 deletions wheel/generate_type_stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ class {name}:{"".join(map(add_indent, members))}
def __init__(
self{init_args}
) -> None: ...
def __new__(
cls{init_args}
) -> {name}: ...
def __hash__(self) -> int: ...
def __repr__(self) -> str: ...
def __richcmp__(self) -> Any: ...
Expand Down Expand Up @@ -356,6 +359,7 @@ def get_puzzle_and_solution_for_coin(program: ReadableBuffer, args: ReadableBuff

class BLSCache:
def __init__(self, cache_size: Optional[int] = 50000) -> None: ...
def __new__(cls, cache_size: Optional[int] = 50000) -> BLSCache: ...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need both __init__ and __new__?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we necessarily need this PR anymore, I'll put it into draft when I'm back home

def len(self) -> int: ...
def aggregate_verify(self, pks: List[G1Element], msgs: List[bytes], sig: G2Element) -> bool: ...
def items(self) -> List[Tuple[bytes, bytes]]: ...
Expand Down Expand Up @@ -388,6 +392,10 @@ def __init__(
self,
leafs: List[bytes32],
) -> None: ...
def __new__(
cls,
leafs: List[bytes32],
) -> MerkleSet: ...
"""
)

Expand All @@ -397,7 +405,6 @@ def __init__(
[],
[
"SIZE: ClassVar[int] = ...",
"def __new__(cls) -> G1Element: ...",
"def get_fingerprint(self) -> int: ...",
"def verify(self, signature: G2Element, msg: bytes) -> bool: ...",
"def pair(self, other: G2Element) -> GTElement: ...",
Expand All @@ -415,7 +422,6 @@ def __init__(
[],
[
"SIZE: ClassVar[int] = ...",
"def __new__(cls) -> G2Element: ...",
"def pair(self, other: G1Element) -> GTElement: ...",
"@staticmethod",
"def generator() -> G2Element: ...",
Expand Down
Loading
Loading