@@ -118,7 +118,7 @@ use frame_support::{
118118 weights:: { OldWeight , Weight } ,
119119 BoundedVec , WeakBoundedVec ,
120120} ;
121- use frame_system:: { EventRecord , Pallet as System } ;
121+ use frame_system:: Pallet as System ;
122122use pallet_contracts_primitives:: {
123123 Code , CodeUploadResult , CodeUploadReturnValue , ContractAccessError , ContractExecResult ,
124124 ContractInstantiateResult , ExecReturnValue , GetStorageResult , InstantiateReturnValue ,
@@ -1167,7 +1167,7 @@ impl<T: Config> Pallet<T> {
11671167 data : Vec < u8 > ,
11681168 debug : bool ,
11691169 determinism : Determinism ,
1170- ) -> ContractExecResult < BalanceOf < T > , EventRecord < < T as pallet :: Config > :: RuntimeEvent , T > > {
1170+ ) -> ContractExecResult < BalanceOf < T > > {
11711171 let mut debug_message = if debug { Some ( DebugBufferVec :: < T > :: default ( ) ) } else { None } ;
11721172 let common = CommonInput {
11731173 origin,
@@ -1178,15 +1178,18 @@ impl<T: Config> Pallet<T> {
11781178 debug_message : debug_message. as_mut ( ) ,
11791179 } ;
11801180 let output = CallInput :: < T > { dest, determinism } . run_guarded ( common) ;
1181+ // We are good to call System::events() from the runtime API (i.e offchain).
1182+ // Even though it says it should only be used in tests, it is actually not allowed to be
1183+ // read on-chain cause it will put all the Events emitted in the block so far into the PoV.
1184+ let events: Vec < Vec < u8 > > =
1185+ System :: < T > :: events ( ) . iter ( ) . map ( |e| e. clone ( ) . event . encode ( ) ) . collect ( ) ; // todo: should determinism::Relaxed be checked here?
11811186 ContractExecResult {
11821187 result : output. result . map_err ( |r| r. error ) ,
11831188 gas_consumed : output. gas_meter . gas_consumed ( ) ,
11841189 gas_required : output. gas_meter . gas_required ( ) ,
11851190 storage_deposit : output. storage_deposit ,
11861191 debug_message : debug_message. unwrap_or_default ( ) . to_vec ( ) ,
1187- events : Some ( System :: events ( ) ) , /* TODO: is it okay to call System::events() here?
1188- * The function says it should only be used in tests.
1189- * But what about offchain calls? */
1192+ events : Some ( events) ,
11901193 }
11911194 }
11921195
0 commit comments