From 68d9f6494abb6c552d44f5f7f3484f7c739b6483 Mon Sep 17 00:00:00 2001 From: Gherman Date: Tue, 20 Feb 2024 15:48:56 +0000 Subject: [PATCH] `call_v2` migration notes (#317) * call_v2 notes * fix * Apply suggestions from code review Co-authored-by: Andrew Jones --------- Co-authored-by: Andrew Jones --- .../faq/migrating-from-ink-4-to-5.md | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/versioned_docs/version-5.x/faq/migrating-from-ink-4-to-5.md b/versioned_docs/version-5.x/faq/migrating-from-ink-4-to-5.md index dfa3b73499..cfd6a1aeb8 100644 --- a/versioned_docs/version-5.x/faq/migrating-from-ink-4-to-5.md +++ b/versioned_docs/version-5.x/faq/migrating-from-ink-4-to-5.md @@ -585,3 +585,46 @@ You can find a contract example and a comparison with chain extensions [here](https://github.com/paritytech/ink/tree/master/integration-tests/call-runtime). We've added an example of how to end-to-end test `call_runtime` [here](https://github.com/paritytech/ink/tree/master/integration-tests/e2e-call-runtime). + + +### `call_v2` + +There is a new host function `call_v2` which allows passing both `Weight` parts: +`ref_time_limit` and `proof_time_limit` and the `storage_deposit_limit`. +The legacy call function only provides the single `gas_limit` parameter, +which is used as the value for `ref_time_limit`. + +These parameters can be set on a call builder instance: +```rust +call_builder + .ref_time_limit(ref_time_limit) + .proof_time_limit(proof_time_limit) + .storage_deposit_limit(storage_deposit_limit) + .invoke(); +``` + +:::Note +These changes depend on the [`60310de`](https://github.com/paritytech/polkadot-sdk/commit/60310de7d6402b6e44624aaa9b5db2dd848545e7) +commit of `pallet-contracts`. +::: + +If you are developing a contract for an older version of `pallet-contracts` +that uses the old `Weight` API, you can still use the legacy call builder by first calling `call_v1`: +```rust +call_builder + .call_v1() + .gas_limit(ref_time_limit) + .invoke(); +``` + +Please note that that if you using trait definition for cross-contract call, +direct calls from `contract_ref!` macro are only supported with the `call_v2`. +Otherwise, you need to get the `CallBuilder` from the structure +and build the call manually. + +```rust +type Erc20Wrapper = contract_ref!(Erc20); +let erc20: Erc20Wrapper = new_erc20.into(); +let erc20_builder = self.erc20.call(); +erc20_builder.total_supply().call_v1().invoke() +``` \ No newline at end of file