Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 28a9643

Browse files
committed
contracts: add generic Event to ContractResult
1 parent a534758 commit 28a9643

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

frame/contracts/primitives/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use sp_weights::Weight;
3333
///
3434
/// It contains the execution result together with some auxiliary information.
3535
#[derive(Eq, PartialEq, Encode, Decode, RuntimeDebug, TypeInfo)]
36-
pub struct ContractResult<R, Balance> {
36+
pub struct ContractResult<R, Balance, Event> {
3737
/// How much weight was consumed during execution.
3838
pub gas_consumed: Weight,
3939
/// How much weight is required as gas limit in order to execute this call.
@@ -71,16 +71,16 @@ pub struct ContractResult<R, Balance> {
7171
pub debug_message: Vec<u8>,
7272
/// The execution result of the wasm code.
7373
pub result: R,
74-
pub events: Option<Vec<Vec<u8>>>,
74+
pub events: Option<Vec<Event>>,
7575
}
7676

7777
/// Result type of a `bare_call` call.
78-
pub type ContractExecResult<Balance> =
79-
ContractResult<Result<ExecReturnValue, DispatchError>, Balance>;
78+
pub type ContractExecResult<Balance, Event> =
79+
ContractResult<Result<ExecReturnValue, DispatchError>, Balance, Event>;
8080

8181
/// Result type of a `bare_instantiate` call.
8282
pub type ContractInstantiateResult<AccountId, Balance> =
83-
ContractResult<Result<InstantiateReturnValue<AccountId>, DispatchError>, Balance>;
83+
ContractResult<Result<InstantiateReturnValue<AccountId>, DispatchError>, Balance, ()>;
8484

8585
/// Result type of a `bare_code_upload` call.
8686
pub type CodeUploadResult<CodeHash, Balance> =

frame/contracts/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,7 +1167,7 @@ impl<T: Config> Pallet<T> {
11671167
data: Vec<u8>,
11681168
debug: bool,
11691169
determinism: Determinism,
1170-
) -> ContractExecResult<BalanceOf<T>> {
1170+
) -> ContractExecResult<BalanceOf<T>, <T as frame_system::Config>::RuntimeEvent> {
11711171
let mut debug_message = if debug { Some(DebugBufferVec::<T>::default()) } else { None };
11721172
let common = CommonInput {
11731173
origin,
@@ -1181,8 +1181,7 @@ impl<T: Config> Pallet<T> {
11811181
// We are good to call System::events() from the runtime API (i.e offchain).
11821182
// Even though it says it should only be used in tests, it is actually not allowed to be
11831183
// 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?
1184+
let events = System::<T>::events().iter().map(|e| e.clone().event).collect::<Vec<_>>(); // todo: should determinism::Relaxed be checked here?
11861185
ContractExecResult {
11871186
result: output.result.map_err(|r| r.error),
11881187
gas_consumed: output.gas_meter.gas_consumed(),
@@ -1342,11 +1341,12 @@ impl<T: Config> Pallet<T> {
13421341
sp_api::decl_runtime_apis! {
13431342
/// The API used to dry-run contract interactions.
13441343
#[api_version(2)]
1345-
pub trait ContractsApi<AccountId, Balance, BlockNumber, Hash> where
1344+
pub trait ContractsApi<AccountId, Balance, BlockNumber, Hash, Event> where
13461345
AccountId: Codec,
13471346
Balance: Codec,
13481347
BlockNumber: Codec,
13491348
Hash: Codec,
1349+
Event: Codec,
13501350
{
13511351
/// Perform a call from a specified account to a given contract.
13521352
///
@@ -1358,7 +1358,7 @@ sp_api::decl_runtime_apis! {
13581358
gas_limit: Option<Weight>,
13591359
storage_deposit_limit: Option<Balance>,
13601360
input_data: Vec<u8>,
1361-
) -> ContractExecResult<Balance>;
1361+
) -> ContractExecResult<Balance, Event>;
13621362

13631363
/// Instantiate a new contract.
13641364
///

frame/contracts/src/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ fn compile_module<T>(fixture_name: &str) -> wat::Result<(Vec<u8>, <T::Hashing as
458458
where
459459
T: frame_system::Config,
460460
{
461-
let fixture_path = ["frame/contracts/fixtures/", fixture_name, ".wat"].concat();
461+
let fixture_path = ["fixtures/", fixture_name, ".wat"].concat();
462462
let wasm_binary = wat::parse_file(fixture_path)?;
463463
let code_hash = T::Hashing::hash(&wasm_binary);
464464
Ok((wasm_binary, code_hash))

0 commit comments

Comments
 (0)