Skip to content

Commit ac2d2dc

Browse files
committed
Aggregator macro provides new_unspendable implementation
1 parent cb48dda commit ac2d2dc

File tree

1 file changed

+15
-4
lines changed
  • tuxedo-core/aggregator/src

1 file changed

+15
-4
lines changed

tuxedo-core/aggregator/src/lib.rs

+15-4
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,19 @@ pub fn tuxedo_verifier(_: TokenStream, body: TokenStream) -> TokenStream {
101101
let mut redeemer_type_name = outer_type.to_string();
102102
redeemer_type_name.push_str("Redeemer");
103103
let redeemer_type = Ident::new(&redeemer_type_name, outer_type.span());
104+
let type_for_new_unspendable = inner_types
105+
.clone()
106+
.next()
107+
.expect("At least one verifier variant expected.");
104108

105109
// TODO there must be a better way to do this, right?
106110
let inner_types2 = inner_types.clone();
107111
let variants2 = variants.clone();
108112
let variants3 = variants.clone();
113+
let variant_for_new_unspendable = variants
114+
.clone()
115+
.next()
116+
.expect("At least one verifier variant expected.");
109117

110118
let as_variants = variants.clone().map(|v| {
111119
let s = format!("as_{}", v);
@@ -161,10 +169,13 @@ pub fn tuxedo_verifier(_: TokenStream, body: TokenStream) -> TokenStream {
161169
}
162170
}
163171

164-
//TODO implement the new_unspendable function as well.
165-
// fn new_unspendable() -> Option<Self> {
166-
// todo!()
167-
// }
172+
// The aggregation macro assumes that the first variant is able to produce a new unspendable instance.
173+
// In the future this could be made nicer (but maybe not worth the complexity) by allowing an additional
174+
// annotation to the one that can be used as unspendable eg `#[unspendable]`
175+
// If this ever becomes a challenge just add an explicit `Unspendable` variant first.
176+
fn new_unspendable() -> Option<Self> {
177+
#type_for_new_unspendable::new_unspendable().map(|inner| Self::#variant_for_new_unspendable(inner))
178+
}
168179
}
169180
};
170181
output.into()

0 commit comments

Comments
 (0)