From 947cf6cdca78b3d8fbc7ef5f0f52890566d97f56 Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Thu, 19 Jan 2023 15:25:05 -0800 Subject: [PATCH 01/11] Make default behaviour of `fire()` to return "raw" return value --- crates/env/src/call/call_builder.rs | 46 ++++---- .../src/generator/trait_def/call_forwarder.rs | 5 +- .../fail/message_input_non_codec.stderr | 100 +++++++++--------- .../fail/message_output_non_codec.stderr | 2 +- .../call-builder/lib.rs | 1 - examples/multisig/lib.rs | 12 +-- .../forward-calls/lib.rs | 12 ++- 7 files changed, 93 insertions(+), 85 deletions(-) diff --git a/crates/env/src/call/call_builder.rs b/crates/env/src/call/call_builder.rs index 3c208c5cddb..c1e141428e2 100644 --- a/crates/env/src/call/call_builder.rs +++ b/crates/env/src/call/call_builder.rs @@ -112,14 +112,17 @@ where /// /// # Panics /// - /// This method panics if it encounters an [`ink_primitives::LangError`]. If you want to handle - /// those use the [`try_invoke`][`CallParams::try_invoke`] method instead. - pub fn invoke(&self) -> Result { - crate::invoke_contract(self).map(|inner| { - inner.unwrap_or_else(|lang_error| { + /// This method panics if it encounters an [`ink::env::Error`][`crate::Error`] or an + /// [`ink::primitives::LangError`][`ink_primitives::LangError`]. If you want to handle those + /// use the [`try_invoke`][`CallParams::try_invoke`] method instead. + pub fn invoke(&self) -> R { + crate::invoke_contract(self) + .unwrap_or_else(|env_error| { + panic!("Cross-contract call failed with {:?}", env_error) + }) + .unwrap_or_else(|lang_error| { panic!("Cross-contract call failed with {:?}", lang_error) }) - }) } /// Invokes the contract with the given built-up call parameters. @@ -128,7 +131,8 @@ where /// /// # Note /// - /// On failure this returns an [`ink_primitives::LangError`] which can be handled by the caller. + /// On failure this returns an outer [`ink::env::Error`][`crate::Error`] or inner + /// [`ink_primitives::LangError`], both of which can be handled by the caller. pub fn try_invoke(&self) -> Result, crate::Error> { crate::invoke_contract(self) } @@ -192,8 +196,7 @@ where /// .push_arg(&[0x10u8; 32]) /// ) /// .returns::<()>() -/// .fire() -/// .expect("Got an error from the Contract's pallet."); +/// .fire(); /// ``` /// /// ## Example 2: With Return Value @@ -228,8 +231,7 @@ where /// .push_arg(&[0x10u8; 32]) /// ) /// .returns::() -/// .fire() -/// .expect("Got an error from the Contract's pallet."); +/// .fire(); /// ``` /// /// ## Example 3: Delegate call @@ -660,9 +662,10 @@ where /// /// # Panics /// - /// This method panics if it encounters an [`ink_primitives::LangError`]. If you want to handle - /// those use the [`try_fire`][`CallBuilder::try_fire`] method instead. - pub fn fire(self) -> Result<(), Error> { + /// This method panics if it encounters an [`ink::env::Error`][`crate::Error`] or an + /// [`ink::primitives::LangError`][`ink_primitives::LangError`]. If you want to handle those + /// use the [`try_fire`][`CallBuilder::try_fire`] method instead. + pub fn fire(self) { self.params().invoke() } @@ -670,7 +673,8 @@ where /// /// # Note /// - /// On failure this returns an [`ink_primitives::LangError`] which can be handled by the caller. + /// On failure this returns an outer [`ink::env::Error`][`crate::Error`] or inner + /// [`ink_primitives::LangError`], both of which can be handled by the caller. pub fn try_fire(self) -> Result, Error> { self.params().try_invoke() } @@ -687,7 +691,7 @@ where E: Environment, { /// Invokes the cross-chain function call. - pub fn fire(self) -> Result<(), Error> { + pub fn fire(self) -> Result<(), crate::Error> { self.params().invoke() } } @@ -703,9 +707,10 @@ where /// /// # Panics /// - /// This method panics if it encounters an [`ink_primitives::LangError`]. If you want to handle - /// those use the [`try_fire`][`CallBuilder::try_fire`] method instead. - pub fn fire(self) -> Result { + /// This method panics if it encounters an [`ink::env::Error`][`crate::Error`] or an + /// [`ink::primitives::LangError`][`ink_primitives::LangError`]. If you want to handle those + /// use the [`try_fire`][`CallBuilder::try_fire`] method instead. + pub fn fire(self) -> R { self.params().invoke() } @@ -713,7 +718,8 @@ where /// /// # Note /// - /// On failure this returns an [`ink_primitives::LangError`] which can be handled by the caller. + /// On failure this returns an outer [`ink::env::Error`][`crate::Error`] or inner + /// [`ink_primitives::LangError`], both of which can be handled by the caller. pub fn try_fire(self) -> Result, Error> { self.params().try_invoke() } diff --git a/crates/ink/codegen/src/generator/trait_def/call_forwarder.rs b/crates/ink/codegen/src/generator/trait_def/call_forwarder.rs index d2828712aa7..46017c5dff2 100644 --- a/crates/ink/codegen/src/generator/trait_def/call_forwarder.rs +++ b/crates/ink/codegen/src/generator/trait_def/call_forwarder.rs @@ -355,8 +355,9 @@ impl CallForwarder<'_> { , #input_bindings )* ) - .fire() - .unwrap_or_else(|err| ::core::panic!("{}: {:?}", #panic_str, err)) + .try_fire() + .unwrap_or_else(|env_err| ::core::panic!("{}: {:?}", #panic_str, env_err)) + .unwrap_or_else(|lang_err| ::core::panic!("{}: {:?}", #panic_str, lang_err)) } ) } diff --git a/crates/ink/tests/ui/trait_def/fail/message_input_non_codec.stderr b/crates/ink/tests/ui/trait_def/fail/message_input_non_codec.stderr index 63b1a30a63a..a4a79052510 100644 --- a/crates/ink/tests/ui/trait_def/fail/message_input_non_codec.stderr +++ b/crates/ink/tests/ui/trait_def/fail/message_input_non_codec.stderr @@ -1,56 +1,56 @@ error[E0277]: the trait bound `NonCodec: WrapperTypeDecode` is not satisfied - --> tests/ui/trait_def/fail/message_input_non_codec.rs:6:23 - | -6 | fn message(&self, input: NonCodec); - | ^^^^^ the trait `WrapperTypeDecode` is not implemented for `NonCodec` - | - = help: the following other types implement trait `WrapperTypeDecode`: - Arc - Box - Rc - = note: required for `NonCodec` to implement `parity_scale_codec::Decode` + --> tests/ui/trait_def/fail/message_input_non_codec.rs:6:23 + | +6 | fn message(&self, input: NonCodec); + | ^^^^^ the trait `WrapperTypeDecode` is not implemented for `NonCodec` + | + = help: the following other types implement trait `WrapperTypeDecode`: + Arc + Box + Rc + = note: required for `NonCodec` to implement `parity_scale_codec::Decode` note: required by a bound in `DispatchInput` - --> src/codegen/dispatch/type_check.rs - | - | T: scale::Decode + 'static; - | ^^^^^^^^^^^^^ required by this bound in `DispatchInput` + --> src/codegen/dispatch/type_check.rs + | + | T: scale::Decode + 'static; + | ^^^^^^^^^^^^^ required by this bound in `DispatchInput` error[E0277]: the trait bound `NonCodec: WrapperTypeEncode` is not satisfied - --> tests/ui/trait_def/fail/message_input_non_codec.rs:3:1 - | -3 | #[ink::trait_definition] - | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `WrapperTypeEncode` is not implemented for `NonCodec` -4 | pub trait TraitDefinition { -5 | #[ink(message)] - | - required by a bound introduced by this call - | - = help: the following other types implement trait `WrapperTypeEncode`: - &T - &mut T - Arc - Box - Cow<'a, T> - Rc - String - Vec - parity_scale_codec::Ref<'a, T, U> - = note: required for `NonCodec` to implement `Encode` + --> tests/ui/trait_def/fail/message_input_non_codec.rs:3:1 + | +3 | #[ink::trait_definition] + | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `WrapperTypeEncode` is not implemented for `NonCodec` +4 | pub trait TraitDefinition { +5 | #[ink(message)] + | - required by a bound introduced by this call + | + = help: the following other types implement trait `WrapperTypeEncode`: + &T + &mut T + Arc + Box + Cow<'a, T> + Rc + String + Vec + parity_scale_codec::Ref<'a, T, U> + = note: required for `NonCodec` to implement `Encode` note: required by a bound in `ExecutionInput::>::push_arg` - --> $WORKSPACE/crates/env/src/call/execution_input.rs - | - | T: scale::Encode, - | ^^^^^^^^^^^^^ required by this bound in `ExecutionInput::>::push_arg` + --> $WORKSPACE/crates/env/src/call/execution_input.rs + | + | T: scale::Encode, + | ^^^^^^^^^^^^^ required by this bound in `ExecutionInput::>::push_arg` -error[E0599]: the method `fire` exists for struct `CallBuilder>, Set, ArgumentList>>>, Set>>`, but its trait bounds were not satisfied - --> tests/ui/trait_def/fail/message_input_non_codec.rs:5:5 - | -5 | #[ink(message)] - | ^ method cannot be called on `CallBuilder>, Set, ArgumentList>>>, Set>>` due to unsatisfied trait bounds - | - ::: $WORKSPACE/crates/env/src/call/execution_input.rs - | - | pub struct ArgumentList { - | ----------------------------------- doesn't satisfy `_: Encode` - | - = note: the following trait bounds were not satisfied: - `ArgumentList, ArgumentList>: Encode` +error[E0599]: the method `try_fire` exists for struct `CallBuilder>, Set, ArgumentList>>>, Set>>`, but its trait bounds were not satisfied + --> tests/ui/trait_def/fail/message_input_non_codec.rs:5:5 + | +5 | #[ink(message)] + | ^ method cannot be called on `CallBuilder>, Set, ArgumentList>>>, Set>>` due to unsatisfied trait bounds + | + ::: $WORKSPACE/crates/env/src/call/execution_input.rs + | + | pub struct ArgumentList { + | ----------------------------------- doesn't satisfy `_: Encode` + | + = note: the following trait bounds were not satisfied: + `ArgumentList, ArgumentList>: Encode` diff --git a/crates/ink/tests/ui/trait_def/fail/message_output_non_codec.stderr b/crates/ink/tests/ui/trait_def/fail/message_output_non_codec.stderr index 2c487dcca6f..2cbf7883085 100644 --- a/crates/ink/tests/ui/trait_def/fail/message_output_non_codec.stderr +++ b/crates/ink/tests/ui/trait_def/fail/message_output_non_codec.stderr @@ -21,7 +21,7 @@ note: required by a bound in `DispatchOutput` | T: scale::Encode + 'static; | ^^^^^^^^^^^^^ required by this bound in `DispatchOutput` -error[E0599]: the method `fire` exists for struct `CallBuilder>, Set>>, Set>>`, but its trait bounds were not satisfied +error[E0599]: the method `try_fire` exists for struct `CallBuilder>, Set>>, Set>>`, but its trait bounds were not satisfied --> tests/ui/trait_def/fail/message_output_non_codec.rs:5:5 | 1 | pub struct NonCodec; diff --git a/examples/lang-err-integration-tests/call-builder/lib.rs b/examples/lang-err-integration-tests/call-builder/lib.rs index 0a3de1e94ef..afffa04ba67 100755 --- a/examples/lang-err-integration-tests/call-builder/lib.rs +++ b/examples/lang-err-integration-tests/call-builder/lib.rs @@ -72,7 +72,6 @@ mod call_builder { .exec_input(ExecutionInput::new(Selector::new(selector))) .returns::<()>() .fire() - .expect("Error from the Contracts pallet.") } #[ink(message)] diff --git a/examples/multisig/lib.rs b/examples/multisig/lib.rs index 16a35430528..4095a4c548c 100755 --- a/examples/multisig/lib.rs +++ b/examples/multisig/lib.rs @@ -348,8 +348,7 @@ mod multisig { /// .push_arg(&transaction_candidate) /// ) /// .returns::<(u32, ConfirmationStatus)>() - /// .fire() - /// .expect("submit_transaction won't panic"); + /// .fire(); /// /// // Wait until all required owners have confirmed and then execute the transaction /// // @@ -362,8 +361,7 @@ mod multisig { /// .push_arg(&id) /// ) /// .returns::<()>() - /// .fire() - /// .expect("invoke_transaction won't panic"); + /// .fire(); /// ``` #[ink(message)] pub fn add_owner(&mut self, new_owner: AccountId) { @@ -549,8 +547,7 @@ mod multisig { ExecutionInput::new(t.selector.into()).push_arg(CallInput(&t.input)), ) .returns::<()>() - .fire() - .map_err(|_| Error::TransactionFailed); + .fire(); self.env().emit_event(Execution { transaction: trans_id, result: result.map(|_| None), @@ -582,8 +579,7 @@ mod multisig { ExecutionInput::new(t.selector.into()).push_arg(CallInput(&t.input)), ) .returns::>() - .fire() - .map_err(|_| Error::TransactionFailed); + .fire(); self.env().emit_event(Execution { transaction: trans_id, result: result.clone().map(Some), diff --git a/examples/upgradeable-contracts/forward-calls/lib.rs b/examples/upgradeable-contracts/forward-calls/lib.rs index 09a47cd3996..b4b073a512b 100644 --- a/examples/upgradeable-contracts/forward-calls/lib.rs +++ b/examples/upgradeable-contracts/forward-calls/lib.rs @@ -81,11 +81,17 @@ pub mod proxy { .set_forward_input(true) .set_tail_call(true), ) - .fire() - .unwrap_or_else(|err| { + .try_fire() + .unwrap_or_else(|env_err| { panic!( "cross-contract call to {:?} failed due to {:?}", - self.forward_to, err + self.forward_to, env_err + ) + }) + .unwrap_or_else(|lang_err| { + panic!( + "cross-contract call to {:?} failed due to {:?}", + self.forward_to, lang_err ) }); unreachable!( From 5ff7feea2d343eb572331a8c9026ffe599d9a400 Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Thu, 19 Jan 2023 15:39:16 -0800 Subject: [PATCH 02/11] Update delegate call codepath to give option to handle `EnvError` --- crates/env/src/call/call_builder.rs | 63 ++++++++++++++++++++++++----- 1 file changed, 54 insertions(+), 9 deletions(-) diff --git a/crates/env/src/call/call_builder.rs b/crates/env/src/call/call_builder.rs index c1e141428e2..e88ec37df1a 100644 --- a/crates/env/src/call/call_builder.rs +++ b/crates/env/src/call/call_builder.rs @@ -144,11 +144,29 @@ where Args: scale::Encode, R: scale::Decode, { - /// Invokes the contract via delegated call with the given - /// built-up call parameters. + /// Invoke the contract using Delegate Call semantics with the given built-up call parameters. /// /// Returns the result of the contract execution. - pub fn invoke(&self) -> Result { + /// + /// # Panics + /// + /// This method panics if it encounters an [`ink::env::Error`][`crate::Error`] If you want to + /// handle those use the [`try_invoke`][`CallParams::try_invoke`] method instead. + pub fn invoke(&self) -> R { + crate::invoke_contract_delegate(self).unwrap_or_else(|env_error| { + panic!("Cross-contract call failed with {:?}", env_error) + }) + } + + /// Invoke the contract using Delegate Call semantics with the given built-up call parameters. + /// + /// Returns the result of the contract execution. + /// + /// # Note + /// + /// On failure this returns an [`ink::env::Error`][`crate::Error`] which can be handled by the + /// caller. + pub fn try_invoke(&self) -> Result { crate::invoke_contract_delegate(self) } } @@ -258,8 +276,7 @@ where /// .push_arg(&[0x10u8; 32]) /// ) /// .returns::() -/// .fire() -/// .expect("Got an error from the Contract's pallet."); +/// .fire(); /// ``` /// /// # Handling `LangError`s @@ -690,10 +707,24 @@ impl where E: Environment, { - /// Invokes the cross-chain function call. - pub fn fire(self) -> Result<(), crate::Error> { + /// Invokes the cross-chain function call using Delegate Call semantics. + /// + /// # Panics + /// + /// This method panics if it encounters an [`ink::env::Error`][`crate::Error`] + /// If you want to handle those use the [`try_fire`][`CallBuilder::try_fire`] method instead. + pub fn fire(self) { self.params().invoke() } + + /// Invokes the cross-chain function call using Delegate Call semantics. + /// + /// # Note + /// + /// On failure this an [`ink::env::Error`][`crate::Error`] which can be handled by the caller. + pub fn try_fire(self) -> Result<(), Error> { + self.params().try_invoke() + } } impl @@ -732,8 +763,22 @@ where Args: scale::Encode, R: scale::Decode, { - /// Invokes the cross-chain function call and returns the result. - pub fn fire(self) -> Result { + /// Invokes the cross-chain function call using Delegate Call semantics and returns the result. + /// + /// # Panics + /// + /// This method panics if it encounters an [`ink::env::Error`][`crate::Error`] + /// If you want to handle those use the [`try_fire`][`CallBuilder::try_fire`] method instead. + pub fn fire(self) -> R { self.params().invoke() } + + /// Invokes the cross-chain function call using Delegate Call semantics and returns the result. + /// + /// # Note + /// + /// On failure this an [`ink::env::Error`][`crate::Error`] which can be handled by the caller. + pub fn try_fire(self) -> Result { + self.params().try_invoke() + } } From 503fddb6fd284f1272e4c96b8cc4b3cc7fc55b80 Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Thu, 19 Jan 2023 15:55:33 -0800 Subject: [PATCH 03/11] Update `CreateBuilder::instantiate()`'s default cleaner as well --- crates/env/src/call/create_builder.rs | 45 ++++++++++++++++--- .../call-builder/lib.rs | 2 +- 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/crates/env/src/call/create_builder.rs b/crates/env/src/call/create_builder.rs index c0657858377..527ede79dcb 100644 --- a/crates/env/src/call/create_builder.rs +++ b/crates/env/src/call/create_builder.rs @@ -119,8 +119,28 @@ where R: FromAccountId, { /// Instantiates the contract and returns its account ID back to the caller. + /// + /// # Panics + /// + /// This method panics if it encounters an [`ink::env::Error`][`crate::Error`]. If you want to + /// handle those use the [`try_instantiate`][`CreateParams::try_instantiate`] method instead. #[inline] - pub fn instantiate(&self) -> Result { + pub fn instantiate(&self) -> R { + crate::instantiate_contract(self) + .map(FromAccountId::from_account_id) + .unwrap_or_else(|env_error| { + panic!("Cross-contract instantiation failed with {:?}", env_error) + }) + } + + /// Instantiates the contract and returns its account ID back to the caller. + /// + /// # Note + /// + /// On failure this returns an [`ink::env::Error`][`crate::Error`] which can be handled by the + /// caller. + #[inline] + pub fn try_instantiate(&self) -> Result { crate::instantiate_contract(self).map(FromAccountId::from_account_id) } } @@ -180,8 +200,7 @@ where /// ) /// .salt_bytes(&[0xDE, 0xAD, 0xBE, 0xEF]) /// .params() -/// .instantiate() -/// .unwrap(); +/// .instantiate(); /// ``` /// /// **Note:** The shown example panics because there is currently no cross-calling @@ -384,9 +403,25 @@ where Salt: AsRef<[u8]>, R: FromAccountId, { - /// Instantiates the contract using the given instantiation parameters. + /// Instantiates the contract and returns its account ID back to the caller. + /// + /// # Panics + /// + /// This method panics if it encounters an [`ink::env::Error`][`crate::Error`]. If you want to + /// handle those use the [`try_instantiate`][`CreateBuilder::try_instantiate`] method instead. #[inline] - pub fn instantiate(self) -> Result { + pub fn instantiate(self) -> R { self.params().instantiate() } + + /// Instantiates the contract and returns its account ID back to the caller. + /// + /// # Note + /// + /// On failure this returns an [`ink::env::Error`][`crate::Error`] which can be handled by the + /// caller. + #[inline] + pub fn try_instantiate(self) -> Result { + self.params().try_instantiate() + } } diff --git a/examples/lang-err-integration-tests/call-builder/lib.rs b/examples/lang-err-integration-tests/call-builder/lib.rs index afffa04ba67..454ecdbe828 100755 --- a/examples/lang-err-integration-tests/call-builder/lib.rs +++ b/examples/lang-err-integration-tests/call-builder/lib.rs @@ -93,7 +93,7 @@ mod call_builder { .exec_input(ExecutionInput::new(Selector::new(selector)).push_arg(init_value)) .salt_bytes(&[0xDE, 0xAD, 0xBE, 0xEF]) .params() - .instantiate(); + .try_instantiate(); // NOTE: Right now we can't handle any `LangError` from `instantiate`, we can only tell // that our contract reverted (i.e we see error from the Contracts pallet). From 48023ca361f3aa6bbdeff405f189ba3551cd07c6 Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Thu, 19 Jan 2023 16:05:51 -0800 Subject: [PATCH 04/11] Add a breaking change note in the changelog --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 754fada5fe1..e447c852d73 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased - Add E2E testing framework MVP ‒ [#1395](https://github.com/paritytech/ink/pull/1395) - Add E2E tests for `Mapping` functions - [#1492](https://github.com/paritytech/ink/pull/1492) +- Make CallBuilder and CreateBuilder error handling optional - [#1602](https://github.com/paritytech/ink/pull/1602) + +### Breaking Changes +With the addition of [#1602](https://github.com/paritytech/ink/pull/1602), +the `CallBuilder::fire()`, `CallParams::invoke()`, and `CreateBuilder::instantiate()` +methods now unwrap the `Result` from `pallet-contracts` under the hood. + +If you wish to handle the error use the new `try_` variants of those methods instead. ## Version 4.0.0-beta From dbf7ac411927e242bcdd99d7cb102c98b875dba4 Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Thu, 19 Jan 2023 16:07:16 -0800 Subject: [PATCH 05/11] Fix delegator example --- examples/delegator/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/delegator/lib.rs b/examples/delegator/lib.rs index 074ac5cae7b..fe094f9828b 100644 --- a/examples/delegator/lib.rs +++ b/examples/delegator/lib.rs @@ -63,7 +63,7 @@ mod delegator { .endowment(total_balance / 4) .code_hash(accumulator_code_hash) .salt_bytes(salt) - .instantiate() + .try_instantiate() .unwrap_or_else(|error| { panic!( "failed at instantiating the Accumulator contract: {:?}", @@ -74,7 +74,7 @@ mod delegator { .endowment(total_balance / 4) .code_hash(adder_code_hash) .salt_bytes(salt) - .instantiate() + .try_instantiate() .unwrap_or_else(|error| { panic!("failed at instantiating the Adder contract: {:?}", error) }); @@ -82,7 +82,7 @@ mod delegator { .endowment(total_balance / 4) .code_hash(subber_code_hash) .salt_bytes(salt) - .instantiate() + .try_instantiate() .unwrap_or_else(|error| { panic!("failed at instantiating the Subber contract: {:?}", error) }); From 72add05d0c6dcc703502e11c7e862a0a03222eac Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Thu, 19 Jan 2023 16:13:19 -0800 Subject: [PATCH 06/11] Drive-by: rename `fire()` method to `invoke()` This keeps this more consistent since we're wrapping a few methods with `invoke` in the name anyways. --- CHANGELOG.md | 8 +++-- crates/env/src/call/call_builder.rs | 36 +++++++++---------- .../generator/as_dependency/contract_ref.rs | 2 +- .../src/generator/trait_def/call_forwarder.rs | 2 +- .../fail/message-input-non-codec.stderr | 2 +- .../fail/message-returns-non-codec.stderr | 2 +- .../fail/message_input_non_codec.stderr | 2 +- .../fail/message_output_non_codec.stderr | 2 +- .../call-builder/lib.rs | 12 +++---- examples/multisig/lib.rs | 8 ++--- .../forward-calls/lib.rs | 2 +- 11 files changed, 40 insertions(+), 38 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e447c852d73..85c58d86c43 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,9 +10,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Make CallBuilder and CreateBuilder error handling optional - [#1602](https://github.com/paritytech/ink/pull/1602) ### Breaking Changes -With the addition of [#1602](https://github.com/paritytech/ink/pull/1602), -the `CallBuilder::fire()`, `CallParams::invoke()`, and `CreateBuilder::instantiate()` -methods now unwrap the `Result` from `pallet-contracts` under the hood. +With the addition of [#1602](https://github.com/paritytech/ink/pull/1602), there are two +breaking changes to the `CallBuilder` and `CreateBuilder`. + +1. The `fire()` method has been renamed to `invoke()` +2. The `invoke()` methods now unwrap the `Result` from `pallet-contracts` under the hood If you wish to handle the error use the new `try_` variants of those methods instead. diff --git a/crates/env/src/call/call_builder.rs b/crates/env/src/call/call_builder.rs index e88ec37df1a..01c990cde74 100644 --- a/crates/env/src/call/call_builder.rs +++ b/crates/env/src/call/call_builder.rs @@ -214,7 +214,7 @@ where /// .push_arg(&[0x10u8; 32]) /// ) /// .returns::<()>() -/// .fire(); +/// .invoke(); /// ``` /// /// ## Example 2: With Return Value @@ -249,7 +249,7 @@ where /// .push_arg(&[0x10u8; 32]) /// ) /// .returns::() -/// .fire(); +/// .invoke(); /// ``` /// /// ## Example 3: Delegate call @@ -276,7 +276,7 @@ where /// .push_arg(&[0x10u8; 32]) /// ) /// .returns::() -/// .fire(); +/// .invoke(); /// ``` /// /// # Handling `LangError`s @@ -284,8 +284,8 @@ where /// It is also important to note that there are certain types of errors which can happen during /// cross-contract calls which can be handled know as [`LangError`][`ink_primitives::LangError`]. /// -/// If you want to handle these errors use the [`CallBuilder::try_fire`] methods instead of the -/// [`CallBuilder::fire`] ones. +/// If you want to handle these errors use the [`CallBuilder::try_invoke`] methods instead of the +/// [`CallBuilder::invoke`] ones. /// /// **Note:** The shown examples panic because there is currently no cross-calling /// support in the off-chain testing environment. However, this code @@ -309,7 +309,7 @@ where /// .gas_limit(5000) /// .transferred_value(10), /// ) -/// .try_fire() +/// .try_invoke() /// .expect("Got an error from the Contract's pallet."); /// /// match call_result { @@ -681,8 +681,8 @@ where /// /// This method panics if it encounters an [`ink::env::Error`][`crate::Error`] or an /// [`ink::primitives::LangError`][`ink_primitives::LangError`]. If you want to handle those - /// use the [`try_fire`][`CallBuilder::try_fire`] method instead. - pub fn fire(self) { + /// use the [`try_invoke`][`CallBuilder::try_invoke`] method instead. + pub fn invoke(self) { self.params().invoke() } @@ -692,7 +692,7 @@ where /// /// On failure this returns an outer [`ink::env::Error`][`crate::Error`] or inner /// [`ink_primitives::LangError`], both of which can be handled by the caller. - pub fn try_fire(self) -> Result, Error> { + pub fn try_invoke(self) -> Result, Error> { self.params().try_invoke() } } @@ -712,8 +712,8 @@ where /// # Panics /// /// This method panics if it encounters an [`ink::env::Error`][`crate::Error`] - /// If you want to handle those use the [`try_fire`][`CallBuilder::try_fire`] method instead. - pub fn fire(self) { + /// If you want to handle those use the [`try_invoke`][`CallBuilder::try_invoke`] method instead. + pub fn invoke(self) { self.params().invoke() } @@ -722,7 +722,7 @@ where /// # Note /// /// On failure this an [`ink::env::Error`][`crate::Error`] which can be handled by the caller. - pub fn try_fire(self) -> Result<(), Error> { + pub fn try_invoke(self) -> Result<(), Error> { self.params().try_invoke() } } @@ -740,8 +740,8 @@ where /// /// This method panics if it encounters an [`ink::env::Error`][`crate::Error`] or an /// [`ink::primitives::LangError`][`ink_primitives::LangError`]. If you want to handle those - /// use the [`try_fire`][`CallBuilder::try_fire`] method instead. - pub fn fire(self) -> R { + /// use the [`try_invoke`][`CallBuilder::try_invoke`] method instead. + pub fn invoke(self) -> R { self.params().invoke() } @@ -751,7 +751,7 @@ where /// /// On failure this returns an outer [`ink::env::Error`][`crate::Error`] or inner /// [`ink_primitives::LangError`], both of which can be handled by the caller. - pub fn try_fire(self) -> Result, Error> { + pub fn try_invoke(self) -> Result, Error> { self.params().try_invoke() } } @@ -768,8 +768,8 @@ where /// # Panics /// /// This method panics if it encounters an [`ink::env::Error`][`crate::Error`] - /// If you want to handle those use the [`try_fire`][`CallBuilder::try_fire`] method instead. - pub fn fire(self) -> R { + /// If you want to handle those use the [`try_invoke`][`CallBuilder::try_invoke`] method instead. + pub fn invoke(self) -> R { self.params().invoke() } @@ -778,7 +778,7 @@ where /// # Note /// /// On failure this an [`ink::env::Error`][`crate::Error`] which can be handled by the caller. - pub fn try_fire(self) -> Result { + pub fn try_invoke(self) -> Result { self.params().try_invoke() } } diff --git a/crates/ink/codegen/src/generator/as_dependency/contract_ref.rs b/crates/ink/codegen/src/generator/as_dependency/contract_ref.rs index 2cf5fe71b26..4c03e90e6f1 100644 --- a/crates/ink/codegen/src/generator/as_dependency/contract_ref.rs +++ b/crates/ink/codegen/src/generator/as_dependency/contract_ref.rs @@ -370,7 +370,7 @@ impl ContractRef<'_> { ) -> #wrapped_output_type { ::#call_operator(self) .#message_ident( #( #input_bindings ),* ) - .try_fire() + .try_invoke() .unwrap_or_else(|error| ::core::panic!( "encountered error while calling {}::{}: {:?}", ::core::stringify!(#storage_ident), diff --git a/crates/ink/codegen/src/generator/trait_def/call_forwarder.rs b/crates/ink/codegen/src/generator/trait_def/call_forwarder.rs index 46017c5dff2..8fd6fc85995 100644 --- a/crates/ink/codegen/src/generator/trait_def/call_forwarder.rs +++ b/crates/ink/codegen/src/generator/trait_def/call_forwarder.rs @@ -355,7 +355,7 @@ impl CallForwarder<'_> { , #input_bindings )* ) - .try_fire() + .try_invoke() .unwrap_or_else(|env_err| ::core::panic!("{}: {:?}", #panic_str, env_err)) .unwrap_or_else(|lang_err| ::core::panic!("{}: {:?}", #panic_str, lang_err)) } diff --git a/crates/ink/tests/ui/contract/fail/message-input-non-codec.stderr b/crates/ink/tests/ui/contract/fail/message-input-non-codec.stderr index a083a628f30..92f73a26387 100644 --- a/crates/ink/tests/ui/contract/fail/message-input-non-codec.stderr +++ b/crates/ink/tests/ui/contract/fail/message-input-non-codec.stderr @@ -53,7 +53,7 @@ note: required by a bound in `ExecutionInput::>::push_arg` -error[E0599]: the method `try_fire` exists for struct `ink::ink_env::call::CallBuilder>, Set, ArgumentList>>>, Set>>`, but its trait bounds were not satisfied +error[E0599]: the method `try_invoke` exists for struct `ink::ink_env::call::CallBuilder>, Set, ArgumentList>>>, Set>>`, but its trait bounds were not satisfied --> tests/ui/contract/fail/message-input-non-codec.rs:16:9 | 16 | pub fn message(&self, _input: NonCodecType) {} diff --git a/crates/ink/tests/ui/contract/fail/message-returns-non-codec.stderr b/crates/ink/tests/ui/contract/fail/message-returns-non-codec.stderr index 1bdb9e94006..8b9240b02c3 100644 --- a/crates/ink/tests/ui/contract/fail/message-returns-non-codec.stderr +++ b/crates/ink/tests/ui/contract/fail/message-returns-non-codec.stderr @@ -34,7 +34,7 @@ note: required by a bound in `return_value` | R: scale::Encode, | ^^^^^^^^^^^^^ required by this bound in `return_value` -error[E0599]: the method `try_fire` exists for struct `ink::ink_env::call::CallBuilder>, Set>>, Set>>`, but its trait bounds were not satisfied +error[E0599]: the method `try_invoke` exists for struct `ink::ink_env::call::CallBuilder>, Set>>, Set>>`, but its trait bounds were not satisfied --> tests/ui/contract/fail/message-returns-non-codec.rs:16:9 | 4 | pub struct NonCodecType; diff --git a/crates/ink/tests/ui/trait_def/fail/message_input_non_codec.stderr b/crates/ink/tests/ui/trait_def/fail/message_input_non_codec.stderr index a4a79052510..eafe57d892a 100644 --- a/crates/ink/tests/ui/trait_def/fail/message_input_non_codec.stderr +++ b/crates/ink/tests/ui/trait_def/fail/message_input_non_codec.stderr @@ -41,7 +41,7 @@ note: required by a bound in `ExecutionInput::>::push_arg` -error[E0599]: the method `try_fire` exists for struct `CallBuilder>, Set, ArgumentList>>>, Set>>`, but its trait bounds were not satisfied +error[E0599]: the method `try_invoke` exists for struct `CallBuilder>, Set, ArgumentList>>>, Set>>`, but its trait bounds were not satisfied --> tests/ui/trait_def/fail/message_input_non_codec.rs:5:5 | 5 | #[ink(message)] diff --git a/crates/ink/tests/ui/trait_def/fail/message_output_non_codec.stderr b/crates/ink/tests/ui/trait_def/fail/message_output_non_codec.stderr index 2cbf7883085..46e1e66dc6d 100644 --- a/crates/ink/tests/ui/trait_def/fail/message_output_non_codec.stderr +++ b/crates/ink/tests/ui/trait_def/fail/message_output_non_codec.stderr @@ -21,7 +21,7 @@ note: required by a bound in `DispatchOutput` | T: scale::Encode + 'static; | ^^^^^^^^^^^^^ required by this bound in `DispatchOutput` -error[E0599]: the method `try_fire` exists for struct `CallBuilder>, Set>>, Set>>`, but its trait bounds were not satisfied +error[E0599]: the method `try_invoke` exists for struct `CallBuilder>, Set>>, Set>>`, but its trait bounds were not satisfied --> tests/ui/trait_def/fail/message_output_non_codec.rs:5:5 | 1 | pub struct NonCodec; diff --git a/examples/lang-err-integration-tests/call-builder/lib.rs b/examples/lang-err-integration-tests/call-builder/lib.rs index 454ecdbe828..2099ebe7e40 100755 --- a/examples/lang-err-integration-tests/call-builder/lib.rs +++ b/examples/lang-err-integration-tests/call-builder/lib.rs @@ -44,7 +44,7 @@ mod call_builder { .call_type(Call::new().callee(address)) .exec_input(ExecutionInput::new(Selector::new(selector))) .returns::<()>() - .try_fire() + .try_invoke() .expect("Error from the Contracts pallet."); match result { @@ -64,14 +64,14 @@ mod call_builder { /// This message does not allow the caller to handle any `LangErrors`, for that use the /// `call` message instead. #[ink(message)] - pub fn fire(&mut self, address: AccountId, selector: [u8; 4]) { + pub fn invoke(&mut self, address: AccountId, selector: [u8; 4]) { use ink::env::call::build_call; build_call::() .call_type(Call::new().callee(address)) .exec_input(ExecutionInput::new(Selector::new(selector))) .returns::<()>() - .fire() + .invoke() } #[ink(message)] @@ -173,7 +173,7 @@ mod call_builder { } #[ink_e2e::test(additional_contracts = "../integration-flipper/Cargo.toml")] - async fn e2e_invalid_message_selector_panics_on_fire( + async fn e2e_invalid_message_selector_panics_on_invoke( mut client: ink_e2e::Client, ) -> E2EResult<()> { let constructor = CallBuilderTestRef::new(); @@ -196,11 +196,11 @@ mod call_builder { .expect("instantiate `flipper` failed") .account_id; - // Since `LangError`s can't be handled by the `CallBuilder::fire()` method we expect + // Since `LangError`s can't be handled by the `CallBuilder::invoke()` method we expect // this to panic. let invalid_selector = [0x00, 0x00, 0x00, 0x00]; let call = build_message::(contract_acc_id) - .call(|contract| contract.fire(flipper_acc_id, invalid_selector)); + .call(|contract| contract.invoke(flipper_acc_id, invalid_selector)); let call_result = client.call(&ink_e2e::ferdie(), call, 0, None).await; assert!(call_result.is_err()); diff --git a/examples/multisig/lib.rs b/examples/multisig/lib.rs index 4095a4c548c..d4a0855f587 100755 --- a/examples/multisig/lib.rs +++ b/examples/multisig/lib.rs @@ -348,7 +348,7 @@ mod multisig { /// .push_arg(&transaction_candidate) /// ) /// .returns::<(u32, ConfirmationStatus)>() - /// .fire(); + /// .invoke(); /// /// // Wait until all required owners have confirmed and then execute the transaction /// // @@ -361,7 +361,7 @@ mod multisig { /// .push_arg(&id) /// ) /// .returns::<()>() - /// .fire(); + /// .invoke(); /// ``` #[ink(message)] pub fn add_owner(&mut self, new_owner: AccountId) { @@ -547,7 +547,7 @@ mod multisig { ExecutionInput::new(t.selector.into()).push_arg(CallInput(&t.input)), ) .returns::<()>() - .fire(); + .invoke(); self.env().emit_event(Execution { transaction: trans_id, result: result.map(|_| None), @@ -579,7 +579,7 @@ mod multisig { ExecutionInput::new(t.selector.into()).push_arg(CallInput(&t.input)), ) .returns::>() - .fire(); + .invoke(); self.env().emit_event(Execution { transaction: trans_id, result: result.clone().map(Some), diff --git a/examples/upgradeable-contracts/forward-calls/lib.rs b/examples/upgradeable-contracts/forward-calls/lib.rs index b4b073a512b..51c4144cc06 100644 --- a/examples/upgradeable-contracts/forward-calls/lib.rs +++ b/examples/upgradeable-contracts/forward-calls/lib.rs @@ -81,7 +81,7 @@ pub mod proxy { .set_forward_input(true) .set_tail_call(true), ) - .try_fire() + .try_invoke() .unwrap_or_else(|env_err| { panic!( "cross-contract call to {:?} failed due to {:?}", From 9819e76453ea21c0e54fdb0226200156220ca946 Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Thu, 19 Jan 2023 16:18:35 -0800 Subject: [PATCH 07/11] Fix ERC-1155 example --- examples/erc1155/lib.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/examples/erc1155/lib.rs b/examples/erc1155/lib.rs index 55f86b16f5a..0f86d98d48b 100644 --- a/examples/erc1155/lib.rs +++ b/examples/erc1155/lib.rs @@ -377,17 +377,19 @@ mod erc1155 { ) .returns::>() .params() - .invoke(); + .try_invoke(); match result { Ok(v) => { ink::env::debug_println!( "Received return value \"{:?}\" from contract {:?}", - v, + v.clone().expect( + "Call should be valid, don't expect a `LangError`." + ), from ); assert_eq!( - v, + v.clone().expect("Call should be valid, don't expect a `LangError`."), &ON_ERC_1155_RECEIVED_SELECTOR[..], "The recipient contract at {:?} does not accept token transfers.\n Expected: {:?}, Got {:?}", to, ON_ERC_1155_RECEIVED_SELECTOR, v From ff759b43dcca9ff18c98724f7281f322932c4004 Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Thu, 19 Jan 2023 16:45:55 -0800 Subject: [PATCH 08/11] Update `Multisig` example --- examples/multisig/lib.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/examples/multisig/lib.rs b/examples/multisig/lib.rs index d4a0855f587..ea3b814e273 100755 --- a/examples/multisig/lib.rs +++ b/examples/multisig/lib.rs @@ -547,7 +547,13 @@ mod multisig { ExecutionInput::new(t.selector.into()).push_arg(CallInput(&t.input)), ) .returns::<()>() - .invoke(); + .try_invoke(); + + let result = match result { + Ok(Ok(_)) => Ok(()), + _ => Err(Error::TransactionFailed), + }; + self.env().emit_event(Execution { transaction: trans_id, result: result.map(|_| None), @@ -579,7 +585,13 @@ mod multisig { ExecutionInput::new(t.selector.into()).push_arg(CallInput(&t.input)), ) .returns::>() - .invoke(); + .try_invoke(); + + let result = match result { + Ok(Ok(v)) => Ok(v), + _ => Err(Error::TransactionFailed), + }; + self.env().emit_event(Execution { transaction: trans_id, result: result.clone().map(Some), From 0d3781144b7d656d01ec30d00884da716538a222 Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Thu, 19 Jan 2023 16:49:37 -0800 Subject: [PATCH 09/11] Fix ContractRef tests --- examples/lang-err-integration-tests/contract-ref/lib.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/examples/lang-err-integration-tests/contract-ref/lib.rs b/examples/lang-err-integration-tests/contract-ref/lib.rs index 64074d14faa..bd6e6108e1f 100755 --- a/examples/lang-err-integration-tests/contract-ref/lib.rs +++ b/examples/lang-err-integration-tests/contract-ref/lib.rs @@ -17,10 +17,7 @@ mod contract_ref { .endowment(0) .code_hash(flipper_code_hash) .salt_bytes(salt) - .instantiate() - .unwrap_or_else(|error| { - panic!("failed at instantiating the Flipper contract: {:?}", error) - }); + .instantiate(); Self { flipper } } From 155d41636d8e141a360d238e995ac1515ac73de9 Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Thu, 19 Jan 2023 16:53:31 -0800 Subject: [PATCH 10/11] Revert "Drive-by: rename `fire()` method to `invoke()`" This reverts commit 72add05d0c6dcc703502e11c7e862a0a03222eac. Decided it's best to do this in a standalone PR. --- CHANGELOG.md | 8 ++--- crates/env/src/call/call_builder.rs | 36 +++++++++---------- .../generator/as_dependency/contract_ref.rs | 2 +- .../src/generator/trait_def/call_forwarder.rs | 2 +- .../fail/message-input-non-codec.stderr | 2 +- .../fail/message-returns-non-codec.stderr | 2 +- .../fail/message_input_non_codec.stderr | 2 +- .../fail/message_output_non_codec.stderr | 2 +- .../call-builder/lib.rs | 12 +++---- examples/multisig/lib.rs | 8 ++--- .../forward-calls/lib.rs | 2 +- 11 files changed, 38 insertions(+), 40 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 85c58d86c43..e447c852d73 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,11 +10,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Make CallBuilder and CreateBuilder error handling optional - [#1602](https://github.com/paritytech/ink/pull/1602) ### Breaking Changes -With the addition of [#1602](https://github.com/paritytech/ink/pull/1602), there are two -breaking changes to the `CallBuilder` and `CreateBuilder`. - -1. The `fire()` method has been renamed to `invoke()` -2. The `invoke()` methods now unwrap the `Result` from `pallet-contracts` under the hood +With the addition of [#1602](https://github.com/paritytech/ink/pull/1602), +the `CallBuilder::fire()`, `CallParams::invoke()`, and `CreateBuilder::instantiate()` +methods now unwrap the `Result` from `pallet-contracts` under the hood. If you wish to handle the error use the new `try_` variants of those methods instead. diff --git a/crates/env/src/call/call_builder.rs b/crates/env/src/call/call_builder.rs index 01c990cde74..e88ec37df1a 100644 --- a/crates/env/src/call/call_builder.rs +++ b/crates/env/src/call/call_builder.rs @@ -214,7 +214,7 @@ where /// .push_arg(&[0x10u8; 32]) /// ) /// .returns::<()>() -/// .invoke(); +/// .fire(); /// ``` /// /// ## Example 2: With Return Value @@ -249,7 +249,7 @@ where /// .push_arg(&[0x10u8; 32]) /// ) /// .returns::() -/// .invoke(); +/// .fire(); /// ``` /// /// ## Example 3: Delegate call @@ -276,7 +276,7 @@ where /// .push_arg(&[0x10u8; 32]) /// ) /// .returns::() -/// .invoke(); +/// .fire(); /// ``` /// /// # Handling `LangError`s @@ -284,8 +284,8 @@ where /// It is also important to note that there are certain types of errors which can happen during /// cross-contract calls which can be handled know as [`LangError`][`ink_primitives::LangError`]. /// -/// If you want to handle these errors use the [`CallBuilder::try_invoke`] methods instead of the -/// [`CallBuilder::invoke`] ones. +/// If you want to handle these errors use the [`CallBuilder::try_fire`] methods instead of the +/// [`CallBuilder::fire`] ones. /// /// **Note:** The shown examples panic because there is currently no cross-calling /// support in the off-chain testing environment. However, this code @@ -309,7 +309,7 @@ where /// .gas_limit(5000) /// .transferred_value(10), /// ) -/// .try_invoke() +/// .try_fire() /// .expect("Got an error from the Contract's pallet."); /// /// match call_result { @@ -681,8 +681,8 @@ where /// /// This method panics if it encounters an [`ink::env::Error`][`crate::Error`] or an /// [`ink::primitives::LangError`][`ink_primitives::LangError`]. If you want to handle those - /// use the [`try_invoke`][`CallBuilder::try_invoke`] method instead. - pub fn invoke(self) { + /// use the [`try_fire`][`CallBuilder::try_fire`] method instead. + pub fn fire(self) { self.params().invoke() } @@ -692,7 +692,7 @@ where /// /// On failure this returns an outer [`ink::env::Error`][`crate::Error`] or inner /// [`ink_primitives::LangError`], both of which can be handled by the caller. - pub fn try_invoke(self) -> Result, Error> { + pub fn try_fire(self) -> Result, Error> { self.params().try_invoke() } } @@ -712,8 +712,8 @@ where /// # Panics /// /// This method panics if it encounters an [`ink::env::Error`][`crate::Error`] - /// If you want to handle those use the [`try_invoke`][`CallBuilder::try_invoke`] method instead. - pub fn invoke(self) { + /// If you want to handle those use the [`try_fire`][`CallBuilder::try_fire`] method instead. + pub fn fire(self) { self.params().invoke() } @@ -722,7 +722,7 @@ where /// # Note /// /// On failure this an [`ink::env::Error`][`crate::Error`] which can be handled by the caller. - pub fn try_invoke(self) -> Result<(), Error> { + pub fn try_fire(self) -> Result<(), Error> { self.params().try_invoke() } } @@ -740,8 +740,8 @@ where /// /// This method panics if it encounters an [`ink::env::Error`][`crate::Error`] or an /// [`ink::primitives::LangError`][`ink_primitives::LangError`]. If you want to handle those - /// use the [`try_invoke`][`CallBuilder::try_invoke`] method instead. - pub fn invoke(self) -> R { + /// use the [`try_fire`][`CallBuilder::try_fire`] method instead. + pub fn fire(self) -> R { self.params().invoke() } @@ -751,7 +751,7 @@ where /// /// On failure this returns an outer [`ink::env::Error`][`crate::Error`] or inner /// [`ink_primitives::LangError`], both of which can be handled by the caller. - pub fn try_invoke(self) -> Result, Error> { + pub fn try_fire(self) -> Result, Error> { self.params().try_invoke() } } @@ -768,8 +768,8 @@ where /// # Panics /// /// This method panics if it encounters an [`ink::env::Error`][`crate::Error`] - /// If you want to handle those use the [`try_invoke`][`CallBuilder::try_invoke`] method instead. - pub fn invoke(self) -> R { + /// If you want to handle those use the [`try_fire`][`CallBuilder::try_fire`] method instead. + pub fn fire(self) -> R { self.params().invoke() } @@ -778,7 +778,7 @@ where /// # Note /// /// On failure this an [`ink::env::Error`][`crate::Error`] which can be handled by the caller. - pub fn try_invoke(self) -> Result { + pub fn try_fire(self) -> Result { self.params().try_invoke() } } diff --git a/crates/ink/codegen/src/generator/as_dependency/contract_ref.rs b/crates/ink/codegen/src/generator/as_dependency/contract_ref.rs index 4c03e90e6f1..2cf5fe71b26 100644 --- a/crates/ink/codegen/src/generator/as_dependency/contract_ref.rs +++ b/crates/ink/codegen/src/generator/as_dependency/contract_ref.rs @@ -370,7 +370,7 @@ impl ContractRef<'_> { ) -> #wrapped_output_type { ::#call_operator(self) .#message_ident( #( #input_bindings ),* ) - .try_invoke() + .try_fire() .unwrap_or_else(|error| ::core::panic!( "encountered error while calling {}::{}: {:?}", ::core::stringify!(#storage_ident), diff --git a/crates/ink/codegen/src/generator/trait_def/call_forwarder.rs b/crates/ink/codegen/src/generator/trait_def/call_forwarder.rs index 8fd6fc85995..46017c5dff2 100644 --- a/crates/ink/codegen/src/generator/trait_def/call_forwarder.rs +++ b/crates/ink/codegen/src/generator/trait_def/call_forwarder.rs @@ -355,7 +355,7 @@ impl CallForwarder<'_> { , #input_bindings )* ) - .try_invoke() + .try_fire() .unwrap_or_else(|env_err| ::core::panic!("{}: {:?}", #panic_str, env_err)) .unwrap_or_else(|lang_err| ::core::panic!("{}: {:?}", #panic_str, lang_err)) } diff --git a/crates/ink/tests/ui/contract/fail/message-input-non-codec.stderr b/crates/ink/tests/ui/contract/fail/message-input-non-codec.stderr index 92f73a26387..a083a628f30 100644 --- a/crates/ink/tests/ui/contract/fail/message-input-non-codec.stderr +++ b/crates/ink/tests/ui/contract/fail/message-input-non-codec.stderr @@ -53,7 +53,7 @@ note: required by a bound in `ExecutionInput::>::push_arg` -error[E0599]: the method `try_invoke` exists for struct `ink::ink_env::call::CallBuilder>, Set, ArgumentList>>>, Set>>`, but its trait bounds were not satisfied +error[E0599]: the method `try_fire` exists for struct `ink::ink_env::call::CallBuilder>, Set, ArgumentList>>>, Set>>`, but its trait bounds were not satisfied --> tests/ui/contract/fail/message-input-non-codec.rs:16:9 | 16 | pub fn message(&self, _input: NonCodecType) {} diff --git a/crates/ink/tests/ui/contract/fail/message-returns-non-codec.stderr b/crates/ink/tests/ui/contract/fail/message-returns-non-codec.stderr index 8b9240b02c3..1bdb9e94006 100644 --- a/crates/ink/tests/ui/contract/fail/message-returns-non-codec.stderr +++ b/crates/ink/tests/ui/contract/fail/message-returns-non-codec.stderr @@ -34,7 +34,7 @@ note: required by a bound in `return_value` | R: scale::Encode, | ^^^^^^^^^^^^^ required by this bound in `return_value` -error[E0599]: the method `try_invoke` exists for struct `ink::ink_env::call::CallBuilder>, Set>>, Set>>`, but its trait bounds were not satisfied +error[E0599]: the method `try_fire` exists for struct `ink::ink_env::call::CallBuilder>, Set>>, Set>>`, but its trait bounds were not satisfied --> tests/ui/contract/fail/message-returns-non-codec.rs:16:9 | 4 | pub struct NonCodecType; diff --git a/crates/ink/tests/ui/trait_def/fail/message_input_non_codec.stderr b/crates/ink/tests/ui/trait_def/fail/message_input_non_codec.stderr index eafe57d892a..a4a79052510 100644 --- a/crates/ink/tests/ui/trait_def/fail/message_input_non_codec.stderr +++ b/crates/ink/tests/ui/trait_def/fail/message_input_non_codec.stderr @@ -41,7 +41,7 @@ note: required by a bound in `ExecutionInput::>::push_arg` -error[E0599]: the method `try_invoke` exists for struct `CallBuilder>, Set, ArgumentList>>>, Set>>`, but its trait bounds were not satisfied +error[E0599]: the method `try_fire` exists for struct `CallBuilder>, Set, ArgumentList>>>, Set>>`, but its trait bounds were not satisfied --> tests/ui/trait_def/fail/message_input_non_codec.rs:5:5 | 5 | #[ink(message)] diff --git a/crates/ink/tests/ui/trait_def/fail/message_output_non_codec.stderr b/crates/ink/tests/ui/trait_def/fail/message_output_non_codec.stderr index 46e1e66dc6d..2cbf7883085 100644 --- a/crates/ink/tests/ui/trait_def/fail/message_output_non_codec.stderr +++ b/crates/ink/tests/ui/trait_def/fail/message_output_non_codec.stderr @@ -21,7 +21,7 @@ note: required by a bound in `DispatchOutput` | T: scale::Encode + 'static; | ^^^^^^^^^^^^^ required by this bound in `DispatchOutput` -error[E0599]: the method `try_invoke` exists for struct `CallBuilder>, Set>>, Set>>`, but its trait bounds were not satisfied +error[E0599]: the method `try_fire` exists for struct `CallBuilder>, Set>>, Set>>`, but its trait bounds were not satisfied --> tests/ui/trait_def/fail/message_output_non_codec.rs:5:5 | 1 | pub struct NonCodec; diff --git a/examples/lang-err-integration-tests/call-builder/lib.rs b/examples/lang-err-integration-tests/call-builder/lib.rs index 2099ebe7e40..454ecdbe828 100755 --- a/examples/lang-err-integration-tests/call-builder/lib.rs +++ b/examples/lang-err-integration-tests/call-builder/lib.rs @@ -44,7 +44,7 @@ mod call_builder { .call_type(Call::new().callee(address)) .exec_input(ExecutionInput::new(Selector::new(selector))) .returns::<()>() - .try_invoke() + .try_fire() .expect("Error from the Contracts pallet."); match result { @@ -64,14 +64,14 @@ mod call_builder { /// This message does not allow the caller to handle any `LangErrors`, for that use the /// `call` message instead. #[ink(message)] - pub fn invoke(&mut self, address: AccountId, selector: [u8; 4]) { + pub fn fire(&mut self, address: AccountId, selector: [u8; 4]) { use ink::env::call::build_call; build_call::() .call_type(Call::new().callee(address)) .exec_input(ExecutionInput::new(Selector::new(selector))) .returns::<()>() - .invoke() + .fire() } #[ink(message)] @@ -173,7 +173,7 @@ mod call_builder { } #[ink_e2e::test(additional_contracts = "../integration-flipper/Cargo.toml")] - async fn e2e_invalid_message_selector_panics_on_invoke( + async fn e2e_invalid_message_selector_panics_on_fire( mut client: ink_e2e::Client, ) -> E2EResult<()> { let constructor = CallBuilderTestRef::new(); @@ -196,11 +196,11 @@ mod call_builder { .expect("instantiate `flipper` failed") .account_id; - // Since `LangError`s can't be handled by the `CallBuilder::invoke()` method we expect + // Since `LangError`s can't be handled by the `CallBuilder::fire()` method we expect // this to panic. let invalid_selector = [0x00, 0x00, 0x00, 0x00]; let call = build_message::(contract_acc_id) - .call(|contract| contract.invoke(flipper_acc_id, invalid_selector)); + .call(|contract| contract.fire(flipper_acc_id, invalid_selector)); let call_result = client.call(&ink_e2e::ferdie(), call, 0, None).await; assert!(call_result.is_err()); diff --git a/examples/multisig/lib.rs b/examples/multisig/lib.rs index ea3b814e273..42fa16593df 100755 --- a/examples/multisig/lib.rs +++ b/examples/multisig/lib.rs @@ -348,7 +348,7 @@ mod multisig { /// .push_arg(&transaction_candidate) /// ) /// .returns::<(u32, ConfirmationStatus)>() - /// .invoke(); + /// .fire(); /// /// // Wait until all required owners have confirmed and then execute the transaction /// // @@ -361,7 +361,7 @@ mod multisig { /// .push_arg(&id) /// ) /// .returns::<()>() - /// .invoke(); + /// .fire(); /// ``` #[ink(message)] pub fn add_owner(&mut self, new_owner: AccountId) { @@ -547,7 +547,7 @@ mod multisig { ExecutionInput::new(t.selector.into()).push_arg(CallInput(&t.input)), ) .returns::<()>() - .try_invoke(); + .try_fire(); let result = match result { Ok(Ok(_)) => Ok(()), @@ -585,7 +585,7 @@ mod multisig { ExecutionInput::new(t.selector.into()).push_arg(CallInput(&t.input)), ) .returns::>() - .try_invoke(); + .try_fire(); let result = match result { Ok(Ok(v)) => Ok(v), diff --git a/examples/upgradeable-contracts/forward-calls/lib.rs b/examples/upgradeable-contracts/forward-calls/lib.rs index 51c4144cc06..b4b073a512b 100644 --- a/examples/upgradeable-contracts/forward-calls/lib.rs +++ b/examples/upgradeable-contracts/forward-calls/lib.rs @@ -81,7 +81,7 @@ pub mod proxy { .set_forward_input(true) .set_tail_call(true), ) - .try_invoke() + .try_fire() .unwrap_or_else(|env_err| { panic!( "cross-contract call to {:?} failed due to {:?}", From 22a924da35a274e65706a079c1dc62b976a05021 Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Fri, 20 Jan 2023 14:02:08 +0000 Subject: [PATCH 11/11] Use instantiate instead of `try_instantiate` in `delegator` --- examples/delegator/lib.rs | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/examples/delegator/lib.rs b/examples/delegator/lib.rs index fe094f9828b..69f5c5ab354 100644 --- a/examples/delegator/lib.rs +++ b/examples/delegator/lib.rs @@ -63,29 +63,17 @@ mod delegator { .endowment(total_balance / 4) .code_hash(accumulator_code_hash) .salt_bytes(salt) - .try_instantiate() - .unwrap_or_else(|error| { - panic!( - "failed at instantiating the Accumulator contract: {:?}", - error - ) - }); + .instantiate(); let adder = AdderRef::new(accumulator.clone()) .endowment(total_balance / 4) .code_hash(adder_code_hash) .salt_bytes(salt) - .try_instantiate() - .unwrap_or_else(|error| { - panic!("failed at instantiating the Adder contract: {:?}", error) - }); + .instantiate(); let subber = SubberRef::new(accumulator.clone()) .endowment(total_balance / 4) .code_hash(subber_code_hash) .salt_bytes(salt) - .try_instantiate() - .unwrap_or_else(|error| { - panic!("failed at instantiating the Subber contract: {:?}", error) - }); + .instantiate(); Self { which: Which::Adder, accumulator,