Emit events for inter contract calls (#12136)

* Add topics to contract events

* Add `Call` events

* Fix compilation for no_std

* Added docs
This commit is contained in:
Alexander Theißen
2022-09-03 10:03:36 +02:00
committed by GitHub
parent 5fb97da337
commit 09a52ef882
4 changed files with 265 additions and 83 deletions
+44 -6
View File
@@ -631,11 +631,14 @@ pub mod pallet {
};
<PrefabWasmModule<T>>::add_user(code_hash)?;
<PrefabWasmModule<T>>::remove_user(contract.code_hash);
Self::deposit_event(Event::ContractCodeUpdated {
contract: dest.clone(),
new_code_hash: code_hash,
old_code_hash: contract.code_hash,
});
Self::deposit_event(
vec![T::Hashing::hash_of(&dest), code_hash, contract.code_hash],
Event::ContractCodeUpdated {
contract: dest.clone(),
new_code_hash: code_hash,
old_code_hash: contract.code_hash,
},
);
contract.code_hash = code_hash;
Ok(())
})
@@ -643,7 +646,6 @@ pub mod pallet {
}
#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
/// Contract deployed by address at the specified address.
Instantiated { deployer: T::AccountId, contract: T::AccountId },
@@ -685,6 +687,35 @@ pub mod pallet {
/// Previous code hash of the contract.
old_code_hash: T::Hash,
},
/// A contract was called either by a plain account or another contract.
///
/// # Note
///
/// Please keep in mind that like all events this is only emitted for successful
/// calls. This is because on failure all storage changes including events are
/// rolled back.
Called {
/// The account that called the `contract`.
caller: T::AccountId,
/// The contract that was called.
contract: T::AccountId,
},
/// A contract delegate called a code hash.
///
/// # Note
///
/// Please keep in mind that like all events this is only emitted for successful
/// calls. This is because on failure all storage changes including events are
/// rolled back.
DelegateCalled {
/// The contract that performed the delegate call and hence in whose context
/// the `code_hash` is executed.
contract: T::AccountId,
/// The code hash that was delegate called.
code_hash: CodeHash<T>,
},
}
#[pallet::error]
@@ -1084,4 +1115,11 @@ where
};
InternalInstantiateOutput { result: try_exec(), gas_meter, storage_deposit }
}
fn deposit_event(topics: Vec<T::Hash>, event: Event<T>) {
<frame_system::Pallet<T>>::deposit_event_indexed(
&topics,
<T as Config>::Event::from(event).into(),
)
}
}