@@ -65,7 +65,9 @@ pub mod pallet {
65
65
pub struct Pallet < T > ( PhantomData < T > ) ;
66
66
67
67
#[ pallet:: config]
68
- pub trait Config : frame_system:: Config + pallet_timestamp:: Config {
68
+ pub trait Config :
69
+ frame_system:: Config + pallet_timestamp:: Config + pallet_utility:: Config
70
+ {
69
71
type RuntimeEvent : From < Event < Self > > + IsType < <Self as frame_system:: Config >:: RuntimeEvent > ;
70
72
/// Weight information for extrinsics in this pallet.
71
73
type WeightInfo : WeightInfo ;
@@ -668,6 +670,38 @@ pub mod pallet {
668
670
Self :: finalize_block ( sender, shard, confirmation) ;
669
671
Ok ( Pays :: No . into ( ) )
670
672
}
673
+
674
+ // A wrapper to utility.call to waive the tx fee if the caller is tee-worker
675
+ // the weight is copied from pallet_utility
676
+ #[ pallet:: call_index( 23 ) ]
677
+ #[ pallet:: weight( {
678
+ use pallet_utility:: WeightInfo ;
679
+ let dispatch_infos = calls. iter( ) . map( |call| call. get_dispatch_info( ) ) . collect:: <Vec <_>>( ) ;
680
+ let dispatch_weight = dispatch_infos. iter( )
681
+ . map( |di| di. weight)
682
+ . fold( Weight :: zero( ) , |total: Weight , weight: Weight | total. saturating_add( weight) )
683
+ . saturating_add( <T as pallet_utility:: Config >:: WeightInfo :: batch( calls. len( ) as u32 ) ) ;
684
+ let dispatch_class = {
685
+ let all_operational = dispatch_infos. iter( )
686
+ . map( |di| di. class)
687
+ . all( |class| class == DispatchClass :: Operational ) ;
688
+ if all_operational {
689
+ DispatchClass :: Operational
690
+ } else {
691
+ DispatchClass :: Normal
692
+ }
693
+ } ;
694
+ ( dispatch_weight, dispatch_class)
695
+ } ) ]
696
+ pub fn batch (
697
+ origin : OriginFor < T > ,
698
+ calls : Vec < <T as pallet_utility:: Config >:: RuntimeCall > ,
699
+ ) -> DispatchResultWithPostInfo {
700
+ let sender = ensure_signed ( origin. clone ( ) ) ?;
701
+ let _ = EnclaveRegistry :: < T > :: get ( & sender) . ok_or ( Error :: < T > :: EnclaveNotExist ) ?;
702
+ let _ = pallet_utility:: Pallet :: < T > :: batch ( origin, calls) ?;
703
+ Ok ( Pays :: No . into ( ) )
704
+ }
671
705
}
672
706
}
673
707
0 commit comments