Skip to content

Commit dfcfd85

Browse files
ascjonesMichael Müller
andauthored
call_v2 cross-contract calls with additional limit parameters (#2077)
* init call_v2 methods and types * add e2e tests to basic-contract-caller example * Add storage_deposit * Fix basic-contract-caller e2e tests * Remove `basic_contract_caller` integration test, moved to #1909 * WIP adding cross_contract_calls test * Add `integration-test` for possible migration pattern (#1909) * WIP * Update versions * WIP * WIP migration * WIP * Make test pass * Move e2e tests mod to own file * Update comment * Update example for new e2e API * Update integration-tests/upgradeable-contracts/set-code-hash-migration/lib.rs Co-authored-by: Michael Müller <[email protected]> * Top level gitignore * Fix tests update comments * Update upgradeable contracts README.md * spelling --------- Co-authored-by: Michael Müller <[email protected]> * Add `basic-contract-caller` E2E test (#2085) * add e2e tests to basic-contract-caller example * Fix basic-contract-caller e2e tests * Remove `call_builder` change * Remove `basic_contract_caller` integration test, moved to #1909 * Revert "Remove `basic_contract_caller` integration test, moved to #1909" This reverts commit 8f3ab31. * fmt * Only need one .gitignore * WIP adding create v2 API * Revert "WIP adding create v2 API" This reverts commit bd83e18. * WIP e2e tests * Add CallV2 builder methods * Pass weight limit as params * Allow deprecated * Add storage_deposit_limit * Clippy * Use struct update syntax * Remove space * CHANGELOG * fmt * Import OtherContract directly instead of reexporting * Make other_contract pub * Revert prev * docs * top level gitignore for integration-tests * Remove unused setters * Use ContractRef * integration-test comments * Rename to `call_v2` * Comments and builder method * SP * comments * fix doc test --------- Co-authored-by: Michael Müller <[email protected]>
1 parent fc51ea7 commit dfcfd85

File tree

21 files changed

+707
-134
lines changed

21 files changed

+707
-134
lines changed

.config/cargo_spellcheck.dic

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ instantiation/S
109109
layout/JG
110110
namespace/S
111111
parameterize/SD
112+
parachain/S
113+
picosecond/S
112114
runtime/S
113115
storable
114116
struct/S

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111
- [Linter] `non_fallible_api` lint - [#2004](https://github.com/paritytech/ink/pull/2004)
1212
- [Linter] Publish the linting crates on crates.io - [#2060](https://github.com/paritytech/ink/pull/2060)
1313
- [E2E] Added `create_call_builder` for testing existing contracts - [#2075](https://github.com/paritytech/ink/pull/2075)
14+
- `call_v2` cross-contract calls with additional limit parameters - [#2077](https://github.com/paritytech/ink/pull/2077)
1415

1516
### Changed
1617
- `Mapping`: Reflect all possible failure cases in comments ‒ [#2079](https://github.com/paritytech/ink/pull/2079)

crates/env/src/api.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use crate::{
2222
call::{
2323
Call,
2424
CallParams,
25+
CallV1,
2526
ConstructorReturnType,
2627
CreateParams,
2728
DelegateCall,
@@ -265,6 +266,9 @@ where
265266
/// This is a low level way to evaluate another smart contract.
266267
/// Prefer to use the ink! guided and type safe approach to using this.
267268
///
269+
/// **This will call into the original version of the host function. It is recommended to
270+
/// use [`invoke_contract`] to use the latest version if the target runtime supports it.**
271+
///
268272
/// # Errors
269273
///
270274
/// - If the called account does not exist.
@@ -273,6 +277,38 @@ where
273277
/// - If the called contract execution has trapped.
274278
/// - If the called contract ran out of gas upon execution.
275279
/// - If the returned value failed to decode properly.
280+
pub fn invoke_contract_v1<E, Args, R>(
281+
params: &CallParams<E, CallV1<E>, Args, R>,
282+
) -> Result<ink_primitives::MessageResult<R>>
283+
where
284+
E: Environment,
285+
Args: scale::Encode,
286+
R: scale::Decode,
287+
{
288+
<EnvInstance as OnInstance>::on_instance(|instance| {
289+
TypedEnvBackend::invoke_contract_v1::<E, Args, R>(instance, params)
290+
})
291+
}
292+
293+
/// Invokes a contract message and returns its result.
294+
///
295+
/// # Note
296+
///
297+
/// **This will call into the latest version of the host function which allows setting new
298+
/// weight and storage limit parameters.**
299+
///
300+
/// This is a low level way to evaluate another smart contract.
301+
/// Prefer to use the ink! guided and type safe approach to using this.
302+
///
303+
/// # Errors
304+
///
305+
/// - If the called account does not exist.
306+
/// - If the called account is not a contract.
307+
/// - If arguments passed to the called contract message are invalid.
308+
/// - If the called contract execution has trapped.
309+
/// - If the called contract ran out of gas, proof time, or storage deposit upon
310+
/// execution.
311+
/// - If the returned value failed to decode properly.
276312
pub fn invoke_contract<E, Args, R>(
277313
params: &CallParams<E, Call<E>, Args, R>,
278314
) -> Result<ink_primitives::MessageResult<R>>

crates/env/src/backend.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use crate::{
1616
call::{
1717
Call,
1818
CallParams,
19+
CallV1,
1920
ConstructorReturnType,
2021
CreateParams,
2122
DelegateCall,
@@ -294,6 +295,24 @@ pub trait TypedEnvBackend: EnvBackend {
294295
///
295296
/// # Note
296297
///
298+
/// **This will call into the original `call` host function.**
299+
///
300+
/// For more details visit: [`invoke_contract`][`crate::invoke_contract_v1`]
301+
fn invoke_contract_v1<E, Args, R>(
302+
&mut self,
303+
call_data: &CallParams<E, CallV1<E>, Args, R>,
304+
) -> Result<ink_primitives::MessageResult<R>>
305+
where
306+
E: Environment,
307+
Args: scale::Encode,
308+
R: scale::Decode;
309+
310+
/// Invokes a contract message and returns its result.
311+
///
312+
/// # Note
313+
///
314+
/// **This will call into the latest `call_v2` host function.**
315+
///
297316
/// For more details visit: [`invoke_contract`][`crate::invoke_contract`]
298317
fn invoke_contract<E, Args, R>(
299318
&mut self,

0 commit comments

Comments
 (0)