Skip to content

Commit

Permalink
call_v2 cross-contract calls with additional limit parameters (#2077)
Browse files Browse the repository at this point in the history
* 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 <michi@parity.io>

* Top level gitignore

* Fix tests update comments

* Update upgradeable contracts README.md

* spelling

---------

Co-authored-by: Michael Müller <michi@parity.io>

* 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 <michi@parity.io>
  • Loading branch information
ascjones and Michael Müller authored Feb 8, 2024
1 parent fc51ea7 commit dfcfd85
Show file tree
Hide file tree
Showing 21 changed files with 707 additions and 134 deletions.
2 changes: 2 additions & 0 deletions .config/cargo_spellcheck.dic
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ instantiation/S
layout/JG
namespace/S
parameterize/SD
parachain/S
picosecond/S
runtime/S
storable
struct/S
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [Linter] `non_fallible_api` lint - [#2004](https://github.com/paritytech/ink/pull/2004)
- [Linter] Publish the linting crates on crates.io - [#2060](https://github.com/paritytech/ink/pull/2060)
- [E2E] Added `create_call_builder` for testing existing contracts - [#2075](https://github.com/paritytech/ink/pull/2075)
- `call_v2` cross-contract calls with additional limit parameters - [#2077](https://github.com/paritytech/ink/pull/2077)

### Changed
- `Mapping`: Reflect all possible failure cases in comments ‒ [#2079](https://github.com/paritytech/ink/pull/2079)
Expand Down
36 changes: 36 additions & 0 deletions crates/env/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use crate::{
call::{
Call,
CallParams,
CallV1,
ConstructorReturnType,
CreateParams,
DelegateCall,
Expand Down Expand Up @@ -265,6 +266,9 @@ where
/// This is a low level way to evaluate another smart contract.
/// Prefer to use the ink! guided and type safe approach to using this.
///
/// **This will call into the original version of the host function. It is recommended to
/// use [`invoke_contract`] to use the latest version if the target runtime supports it.**
///
/// # Errors
///
/// - If the called account does not exist.
Expand All @@ -273,6 +277,38 @@ where
/// - If the called contract execution has trapped.
/// - If the called contract ran out of gas upon execution.
/// - If the returned value failed to decode properly.
pub fn invoke_contract_v1<E, Args, R>(
params: &CallParams<E, CallV1<E>, Args, R>,
) -> Result<ink_primitives::MessageResult<R>>
where
E: Environment,
Args: scale::Encode,
R: scale::Decode,
{
<EnvInstance as OnInstance>::on_instance(|instance| {
TypedEnvBackend::invoke_contract_v1::<E, Args, R>(instance, params)
})
}

/// Invokes a contract message and returns its result.
///
/// # Note
///
/// **This will call into the latest version of the host function which allows setting new
/// weight and storage limit parameters.**
///
/// This is a low level way to evaluate another smart contract.
/// Prefer to use the ink! guided and type safe approach to using this.
///
/// # Errors
///
/// - If the called account does not exist.
/// - If the called account is not a contract.
/// - If arguments passed to the called contract message are invalid.
/// - If the called contract execution has trapped.
/// - If the called contract ran out of gas, proof time, or storage deposit upon
/// execution.
/// - If the returned value failed to decode properly.
pub fn invoke_contract<E, Args, R>(
params: &CallParams<E, Call<E>, Args, R>,
) -> Result<ink_primitives::MessageResult<R>>
Expand Down
19 changes: 19 additions & 0 deletions crates/env/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use crate::{
call::{
Call,
CallParams,
CallV1,
ConstructorReturnType,
CreateParams,
DelegateCall,
Expand Down Expand Up @@ -294,6 +295,24 @@ pub trait TypedEnvBackend: EnvBackend {
///
/// # Note
///
/// **This will call into the original `call` host function.**
///
/// For more details visit: [`invoke_contract`][`crate::invoke_contract_v1`]
fn invoke_contract_v1<E, Args, R>(
&mut self,
call_data: &CallParams<E, CallV1<E>, Args, R>,
) -> Result<ink_primitives::MessageResult<R>>
where
E: Environment,
Args: scale::Encode,
R: scale::Decode;

/// Invokes a contract message and returns its result.
///
/// # Note
///
/// **This will call into the latest `call_v2` host function.**
///
/// For more details visit: [`invoke_contract`][`crate::invoke_contract`]
fn invoke_contract<E, Args, R>(
&mut self,
Expand Down
Loading

0 comments on commit dfcfd85

Please sign in to comment.