@@ -101,11 +101,19 @@ pub fn tuxedo_verifier(_: TokenStream, body: TokenStream) -> TokenStream {
101
101
let mut redeemer_type_name = outer_type. to_string ( ) ;
102
102
redeemer_type_name. push_str ( "Redeemer" ) ;
103
103
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." ) ;
104
108
105
109
// TODO there must be a better way to do this, right?
106
110
let inner_types2 = inner_types. clone ( ) ;
107
111
let variants2 = variants. clone ( ) ;
108
112
let variants3 = variants. clone ( ) ;
113
+ let variant_for_new_unspendable = variants
114
+ . clone ( )
115
+ . next ( )
116
+ . expect ( "At least one verifier variant expected." ) ;
109
117
110
118
let as_variants = variants. clone ( ) . map ( |v| {
111
119
let s = format ! ( "as_{}" , v) ;
@@ -160,6 +168,14 @@ pub fn tuxedo_verifier(_: TokenStream, body: TokenStream) -> TokenStream {
160
168
) *
161
169
}
162
170
}
171
+
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
+ }
163
179
}
164
180
} ;
165
181
output. into ( )
@@ -173,9 +189,8 @@ pub fn tuxedo_verifier(_: TokenStream, body: TokenStream) -> TokenStream {
173
189
/// just like this original enum. however, the contained values in the error enum are of the corresponding types
174
190
/// for the inner constraint checker.
175
191
#[ proc_macro_attribute]
176
- pub fn tuxedo_constraint_checker ( attrs : TokenStream , body : TokenStream ) -> TokenStream {
192
+ pub fn tuxedo_constraint_checker ( _attrs : TokenStream , body : TokenStream ) -> TokenStream {
177
193
let ast = parse_macro_input ! ( body as ItemEnum ) ;
178
- let verifier = parse_macro_input ! ( attrs as Ident ) ;
179
194
let original_code = ast. clone ( ) ;
180
195
181
196
let outer_type = ast. ident ;
@@ -204,23 +219,16 @@ pub fn tuxedo_constraint_checker(attrs: TokenStream, body: TokenStream) -> Token
204
219
error_type_name. push_str ( "Error" ) ;
205
220
let error_type = Ident :: new ( & error_type_name, outer_type. span ( ) ) ;
206
221
207
- let mut inherent_hooks_name = outer_type. to_string ( ) ;
208
- inherent_hooks_name. push_str ( "InherentHooks" ) ;
209
- let inherent_hooks = Ident :: new ( & inherent_hooks_name, outer_type. span ( ) ) ;
210
-
211
222
let vis = ast. vis ;
212
223
213
224
// TODO there must be a better way to do this, right?
214
225
let inner_types2 = inner_types. clone ( ) ;
215
226
let inner_types3 = inner_types. clone ( ) ;
216
227
let inner_types4 = inner_types. clone ( ) ;
217
- let inner_types6 = inner_types. clone ( ) ;
218
- let inner_types7 = inner_types. clone ( ) ;
219
228
let variants2 = variants. clone ( ) ;
220
229
let variants3 = variants. clone ( ) ;
221
230
let variants4 = variants. clone ( ) ;
222
231
let variants5 = variants. clone ( ) ;
223
- let variants6 = variants. clone ( ) ;
224
232
225
233
let output = quote ! {
226
234
// Preserve the original enum, and write the From impls
@@ -235,27 +243,39 @@ pub fn tuxedo_constraint_checker(attrs: TokenStream, body: TokenStream) -> Token
235
243
#[ derive( Debug ) ]
236
244
#vis enum #error_type {
237
245
#(
238
- #variants( <#inner_types as tuxedo_core:: ConstraintChecker <#verifier> >:: Error ) ,
246
+ #variants( <#inner_types as tuxedo_core:: ConstraintChecker >:: Error ) ,
239
247
) *
240
248
}
241
249
242
- /// This type is generated by the `#[tuxedo_constraint_checker]` macro.
243
- /// It is a combined set of inherent hooks for the inherent hooks of each individual checker.
244
- ///
245
- /// This type is accessible downstream as `<OuterConstraintChecker as ConstraintChecker>::InherentHooks`
246
- #[ derive( Debug , scale_info:: TypeInfo ) ]
247
- #vis enum #inherent_hooks {
248
- #(
249
- #variants2( <#inner_types2 as tuxedo_core:: ConstraintChecker <#verifier>>:: InherentHooks ) ,
250
- ) *
251
- }
250
+ impl tuxedo_core:: ConstraintChecker for #outer_type {
251
+ type Error = #error_type;
252
252
253
- impl tuxedo_core:: inherents:: InherentInternal <#verifier, #outer_type> for #inherent_hooks {
253
+ fn check (
254
+ & self ,
255
+ inputs: & [ tuxedo_core:: dynamic_typing:: DynamicallyTypedData ] ,
256
+ peeks: & [ tuxedo_core:: dynamic_typing:: DynamicallyTypedData ] ,
257
+ outputs: & [ tuxedo_core:: dynamic_typing:: DynamicallyTypedData ] ,
258
+ ) -> Result <TransactionPriority , Self :: Error > {
259
+ match self {
260
+ #(
261
+ Self :: #variants5( inner) => inner. check( inputs, peeks, outputs) . map_err( |e| Self :: Error :: #variants5( e) ) ,
262
+ ) *
263
+ }
264
+ }
265
+
266
+ fn is_inherent( & self ) -> bool {
267
+ match self {
268
+ #(
269
+ Self :: #variants2( inner) => inner. is_inherent( ) ,
270
+ ) *
271
+ }
254
272
255
- fn create_inherents(
273
+ }
274
+
275
+ fn create_inherents<V : tuxedo_core:: Verifier >(
256
276
authoring_inherent_data: & InherentData ,
257
- previous_inherents: Vec <( tuxedo_core:: types:: Transaction <#verifier , #outer_type>, sp_core:: H256 ) >,
258
- ) -> Vec <tuxedo_core:: types:: Transaction <#verifier , #outer_type>> {
277
+ previous_inherents: Vec <( tuxedo_core:: types:: Transaction <V , #outer_type>, sp_core:: H256 ) >,
278
+ ) -> Vec <tuxedo_core:: types:: Transaction <V , #outer_type>> {
259
279
260
280
let mut all_inherents = Vec :: new( ) ;
261
281
@@ -272,7 +292,7 @@ pub fn tuxedo_constraint_checker(attrs: TokenStream, body: TokenStream) -> Token
272
292
} )
273
293
. collect( ) ;
274
294
275
- let inherents = <#inner_types3 as tuxedo_core:: ConstraintChecker <#verifier>> :: InherentHooks :: create_inherents( authoring_inherent_data, previous_inherents)
295
+ let inherents = <#inner_types3 as tuxedo_core:: ConstraintChecker > :: create_inherents( authoring_inherent_data, previous_inherents)
276
296
. iter( )
277
297
. map( |tx| tx. transform:: <#outer_type>( ) )
278
298
. collect:: <Vec <_>>( ) ;
@@ -284,13 +304,13 @@ pub fn tuxedo_constraint_checker(attrs: TokenStream, body: TokenStream) -> Token
284
304
all_inherents
285
305
}
286
306
287
- fn check_inherents(
307
+ fn check_inherents< V : tuxedo_core :: Verifier > (
288
308
importing_inherent_data: & sp_inherents:: InherentData ,
289
- inherents: Vec <tuxedo_core:: types:: Transaction <#verifier , #outer_type>>,
309
+ inherents: Vec <tuxedo_core:: types:: Transaction <V , #outer_type>>,
290
310
result: & mut sp_inherents:: CheckInherentsResult ,
291
311
) {
292
312
#(
293
- let relevant_inherents: Vec <tuxedo_core:: types:: Transaction <#verifier , #inner_types4>> = inherents
313
+ let relevant_inherents: Vec <tuxedo_core:: types:: Transaction <V , #inner_types4>> = inherents
294
314
. iter( )
295
315
. filter_map( |tx| {
296
316
match tx. checker {
@@ -300,7 +320,7 @@ pub fn tuxedo_constraint_checker(attrs: TokenStream, body: TokenStream) -> Token
300
320
} )
301
321
. collect( ) ;
302
322
303
- <#inner_types4 as tuxedo_core:: ConstraintChecker <#verifier>> :: InherentHooks :: check_inherents( importing_inherent_data, relevant_inherents, result) ;
323
+ <#inner_types4 as tuxedo_core:: ConstraintChecker > :: check_inherents( importing_inherent_data, relevant_inherents, result) ;
304
324
305
325
// According to https://paritytech.github.io/polkadot-sdk/master/sp_inherents/struct.CheckInherentsResult.html
306
326
// "When a fatal error occurs, all other errors are removed and the implementation needs to abort checking inherents."
@@ -311,12 +331,12 @@ pub fn tuxedo_constraint_checker(attrs: TokenStream, body: TokenStream) -> Token
311
331
}
312
332
313
333
#[ cfg( feature = "std" ) ]
314
- fn genesis_transactions( ) -> Vec <tuxedo_core:: types:: Transaction <#verifier , #outer_type>> {
315
- let mut all_transactions: Vec <tuxedo_core:: types:: Transaction <#verifier , #outer_type>> = Vec :: new( ) ;
334
+ fn genesis_transactions< V : tuxedo_core :: Verifier > ( ) -> Vec <tuxedo_core:: types:: Transaction <V , #outer_type>> {
335
+ let mut all_transactions: Vec <tuxedo_core:: types:: Transaction <V , #outer_type>> = Vec :: new( ) ;
316
336
317
337
#(
318
338
let transactions =
319
- <<#inner_types6 as tuxedo_core:: ConstraintChecker <#verifier>> :: InherentHooks as tuxedo_core :: inherents :: InherentInternal <#verifier , #inner_types6> >:: genesis_transactions( ) ;
339
+ <#inner_types2 as tuxedo_core:: ConstraintChecker >:: genesis_transactions( ) ;
320
340
all_transactions. extend(
321
341
transactions
322
342
. into_iter( )
@@ -329,35 +349,6 @@ pub fn tuxedo_constraint_checker(attrs: TokenStream, body: TokenStream) -> Token
329
349
}
330
350
331
351
}
332
-
333
- impl tuxedo_core:: ConstraintChecker <#verifier> for #outer_type {
334
- type Error = #error_type;
335
-
336
- type InherentHooks = #inherent_hooks;
337
-
338
- fn check (
339
- & self ,
340
- inputs: & [ tuxedo_core:: types:: Output <#verifier>] ,
341
- peeks: & [ tuxedo_core:: types:: Output <#verifier>] ,
342
- outputs: & [ tuxedo_core:: types:: Output <#verifier>] ,
343
- ) -> Result <TransactionPriority , Self :: Error > {
344
- match self {
345
- #(
346
- Self :: #variants5( inner) => inner. check( inputs, peeks, outputs) . map_err( |e| Self :: Error :: #variants5( e) ) ,
347
- ) *
348
- }
349
- }
350
-
351
- fn is_inherent( & self ) -> bool {
352
- match self {
353
- #(
354
- Self :: #variants6( inner) => <#inner_types7 as tuxedo_core:: ConstraintChecker <#verifier>>:: is_inherent( inner) ,
355
- ) *
356
- }
357
-
358
- }
359
-
360
- }
361
352
} ;
362
353
363
354
output. into ( )
0 commit comments