Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
47200ff
contracts: add events to ContractResult
juangirini Apr 3, 2023
a534758
contracts: add encoded events to ContractResult
juangirini Apr 3, 2023
28a9643
contracts: add generic Event to ContractResult
juangirini Apr 3, 2023
cf43686
Merge remote-tracking branch 'origin/master' into jg/12412-contracts-…
juangirini Apr 3, 2023
08db645
contracts: test bare_call events
juangirini Apr 3, 2023
7ca1b4b
contracts: update bare_call test name
juangirini Apr 4, 2023
5ad0868
contracts: add better comments to dry run events
juangirini Apr 4, 2023
dbd8735
contracts: fix pallet contracts primitives implementation
juangirini Apr 4, 2023
1718400
contracts: add EventRecord generic to ContractInstantiateResult
juangirini Apr 4, 2023
782aba7
contracts: make event collection optional
juangirini Apr 5, 2023
74d4b70
contracts: impreved notes on `collect_events`
juangirini Apr 5, 2023
45e6eab
contracts: update benchmarking calls
juangirini Apr 6, 2023
4426bbe
contracts: change bare_call and bare_instantiate to accept enums inst…
juangirini Apr 12, 2023
0de45b6
contracts: add partial eq to new enums
juangirini Apr 17, 2023
8d36e91
contracts: improve comments
juangirini Apr 17, 2023
02c41d3
contracts: improve comments
juangirini Apr 17, 2023
5d4fd5c
contracts: merge master and resolve conflicts
juangirini Apr 17, 2023
b9cb4ef
contracts: fix bare_call benchmarking
juangirini Apr 18, 2023
a8b0c8b
contracts: fix bare call and instantiate in impl_runtime_apis
juangirini Apr 18, 2023
160cfb3
contracts: add api versioning to new ContractsApi functions
juangirini Apr 20, 2023
dacdc53
contracts: modify api versioning to new ContractsApi functions
juangirini Apr 20, 2023
e7fa394
contracts: merge master and fix conflicts
juangirini Apr 28, 2023
337e54e
contracts: create new contracts api trait
juangirini Apr 28, 2023
b9838b1
contracts: clean up code
juangirini May 2, 2023
fca001f
contracts: remove the contract results with events
juangirini May 2, 2023
a8da1ff
contracts: undo contracts api v3
juangirini May 2, 2023
af6587a
contracts: remove commented out code
juangirini May 2, 2023
9919fd1
contracts: add new test bare call result does not return events
juangirini May 2, 2023
51894be
contracts: merge master and resolve conflicts
juangirini May 3, 2023
1e09bdb
contracts: add code review improvements
juangirini May 3, 2023
eef0f97
contracts: remove type imports
juangirini May 3, 2023
3023dfd
contracts: minor code review improvements
juangirini May 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
contracts: add encoded events to ContractResult
  • Loading branch information
juangirini committed Apr 3, 2023
commit a534758d90e9f074bc73b790f9438802948f6ebe
10 changes: 5 additions & 5 deletions frame/contracts/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use sp_weights::Weight;
///
/// It contains the execution result together with some auxiliary information.
#[derive(Eq, PartialEq, Encode, Decode, RuntimeDebug, TypeInfo)]
pub struct ContractResult<R, Balance, Event> {
pub struct ContractResult<R, Balance> {
/// How much weight was consumed during execution.
pub gas_consumed: Weight,
/// How much weight is required as gas limit in order to execute this call.
Expand Down Expand Up @@ -71,16 +71,16 @@ pub struct ContractResult<R, Balance, Event> {
pub debug_message: Vec<u8>,
/// The execution result of the wasm code.
pub result: R,
pub events: Option<Vec<Event>>,
pub events: Option<Vec<Vec<u8>>>,
}

/// Result type of a `bare_call` call.
pub type ContractExecResult<Balance, Event> =
ContractResult<Result<ExecReturnValue, DispatchError>, Balance, Event>;
pub type ContractExecResult<Balance> =
ContractResult<Result<ExecReturnValue, DispatchError>, Balance>;

/// Result type of a `bare_instantiate` call.
pub type ContractInstantiateResult<AccountId, Balance> =
ContractResult<Result<InstantiateReturnValue<AccountId>, DispatchError>, Balance, ()>;
ContractResult<Result<InstantiateReturnValue<AccountId>, DispatchError>, Balance>;

/// Result type of a `bare_code_upload` call.
pub type CodeUploadResult<CodeHash, Balance> =
Expand Down
13 changes: 8 additions & 5 deletions frame/contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ use frame_support::{
weights::{OldWeight, Weight},
BoundedVec, WeakBoundedVec,
};
use frame_system::{EventRecord, Pallet as System};
use frame_system::Pallet as System;
use pallet_contracts_primitives::{
Code, CodeUploadResult, CodeUploadReturnValue, ContractAccessError, ContractExecResult,
ContractInstantiateResult, ExecReturnValue, GetStorageResult, InstantiateReturnValue,
Expand Down Expand Up @@ -1167,7 +1167,7 @@ impl<T: Config> Pallet<T> {
data: Vec<u8>,
debug: bool,
determinism: Determinism,
) -> ContractExecResult<BalanceOf<T>, EventRecord<<T as pallet::Config>::RuntimeEvent, T>> {
) -> ContractExecResult<BalanceOf<T>> {
let mut debug_message = if debug { Some(DebugBufferVec::<T>::default()) } else { None };
let common = CommonInput {
origin,
Expand All @@ -1178,15 +1178,18 @@ impl<T: Config> Pallet<T> {
debug_message: debug_message.as_mut(),
};
let output = CallInput::<T> { dest, determinism }.run_guarded(common);
// We are good to call System::events() from the runtime API (i.e offchain).
// Even though it says it should only be used in tests, it is actually not allowed to be
// read on-chain cause it will put all the Events emitted in the block so far into the PoV.
let events: Vec<Vec<u8>> =
System::<T>::events().iter().map(|e| e.clone().event.encode()).collect(); // todo: should determinism::Relaxed be checked here?
ContractExecResult {
result: output.result.map_err(|r| r.error),
gas_consumed: output.gas_meter.gas_consumed(),
gas_required: output.gas_meter.gas_required(),
storage_deposit: output.storage_deposit,
debug_message: debug_message.unwrap_or_default().to_vec(),
events: Some(System::events()), /* TODO: is it okay to call System::events() here?
* The function says it should only be used in tests.
* But what about offchain calls? */
events: Some(events),
}
}

Expand Down
2 changes: 1 addition & 1 deletion frame/contracts/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ fn compile_module<T>(fixture_name: &str) -> wat::Result<(Vec<u8>, <T::Hashing as
where
T: frame_system::Config,
{
let fixture_path = ["fixtures/", fixture_name, ".wat"].concat();
let fixture_path = ["frame/contracts/fixtures/", fixture_name, ".wat"].concat();
let wasm_binary = wat::parse_file(fixture_path)?;
let code_hash = T::Hashing::hash(&wasm_binary);
Ok((wasm_binary, code_hash))
Expand Down