From aba84ba5305de3ce1b540373b23c61890e5ec4d9 Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Thu, 5 Dec 2024 16:48:05 +0100 Subject: [PATCH] Remove feature gated code --- crates/engine/src/ext.rs | 8 - crates/env/src/api.rs | 94 ------ crates/env/src/backend.rs | 49 --- crates/env/src/call/call_builder/call.rs | 26 -- crates/env/src/call/call_builder/call_v1.rs | 300 ------------------- crates/env/src/call/call_builder/delegate.rs | 3 - crates/env/src/call/call_builder/mod.rs | 19 -- crates/env/src/call/create_builder.rs | 101 ------- crates/env/src/call/mod.rs | 5 - crates/env/src/engine/mod.rs | 4 - crates/env/src/engine/off_chain/impls.rs | 56 ---- crates/env/src/error.rs | 3 - crates/env/src/lib.rs | 8 - crates/ink/codegen/src/generator/dispatch.rs | 109 ------- crates/ink/src/env_access.rs | 208 ------------- 15 files changed, 993 deletions(-) delete mode 100644 crates/env/src/call/call_builder/call_v1.rs diff --git a/crates/engine/src/ext.rs b/crates/engine/src/ext.rs index 976f891dff..3184c5e152 100644 --- a/crates/engine/src/ext.rs +++ b/crates/engine/src/ext.rs @@ -31,9 +31,6 @@ use crate::{ BlockTimestamp, }, }; -#[cfg(not(feature = "revive"))] -pub use pallet_contracts_uapi::ReturnErrorCode as Error; -#[cfg(feature = "revive")] pub use pallet_revive_uapi::ReturnErrorCode as Error; use scale::Encode; use std::panic::panic_any; @@ -323,11 +320,6 @@ impl Engine { set_output(output, &block_timestamp[..]) } - #[cfg(not(feature = "revive"))] - pub fn gas_left(&self, _output: &mut &mut [u8]) { - unimplemented!("off-chain environment does not yet support `gas_left`"); - } - /// Returns the minimum balance that is required for creating an account /// (i.e. the chain's existential deposit). pub fn minimum_balance(&self, output: &mut &mut [u8]) { diff --git a/crates/env/src/api.rs b/crates/env/src/api.rs index dfd07fff13..f5bdb05697 100644 --- a/crates/env/src/api.rs +++ b/crates/env/src/api.rs @@ -14,11 +14,6 @@ //! The public raw interface towards the host Wasm engine. -#[cfg(not(feature = "revive"))] -use crate::call::{ - CallV1, - LimitParamsV1, -}; use crate::{ backend::{ EnvBackend, @@ -47,9 +42,6 @@ use crate::{ Result, }; use ink_storage_traits::Storable; -#[cfg(not(feature = "revive"))] -use pallet_contracts_uapi::ReturnFlags; -#[cfg(feature = "revive")] use pallet_revive_uapi::ReturnFlags; /// Returns the address of the caller of the executed contract. @@ -94,21 +86,6 @@ where }) } -/// Returns the amount of gas left for the contract execution. -/// -/// # Errors -/// -/// If the returned value cannot be properly decoded. -#[cfg(not(feature = "revive"))] -pub fn gas_left() -> Gas -where - E: Environment, -{ - ::on_instance(|instance| { - TypedEnvBackend::gas_left::(instance) - }) -} - /// Returns the current block timestamp. /// /// # Errors @@ -268,38 +245,6 @@ where }) } -/// Invokes a contract message and returns its result. -/// -/// # Note -/// -/// 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. -/// - 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 upon execution. -/// - If the returned value failed to decode properly. -#[cfg(not(feature = "revive"))] -pub fn invoke_contract_v1( - params: &CallParams, Args, R>, -) -> Result> -where - E: Environment, - Args: scale::Encode, - R: scale::Decode, -{ - ::on_instance(|instance| { - TypedEnvBackend::invoke_contract_v1::(instance, params) - }) -} - /// Invokes a contract message and returns its result. /// /// # Note @@ -395,45 +340,6 @@ where }) } -/// Instantiates another contract. -/// -/// # Note -/// -/// This is a low level way to instantiate another smart contract, calling the legacy -/// `instantiate_v1` host function. -/// -/// Prefer to use methods on a `ContractRef` or the -/// [`CreateBuilder`](`crate::call::CreateBuilder`) -/// through [`build_create`](`crate::call::build_create`) instead. -/// -/// # Errors -/// -/// - If the code hash is invalid. -/// - If the arguments passed to the instantiation process are invalid. -/// - If the instantiation process traps. -/// - If the instantiation process runs out of gas. -/// - If given insufficient endowment. -/// - If the returned account ID failed to decode properly. -#[cfg(not(feature = "revive"))] -pub fn instantiate_contract_v1( - params: &CreateParams, -) -> Result< - ink_primitives::ConstructorResult<>::Output>, -> -where - E: Environment, - ContractRef: FromAccountId, - Args: scale::Encode, - Salt: AsRef<[u8]>, - R: ConstructorReturnType, -{ - ::on_instance(|instance| { - TypedEnvBackend::instantiate_contract_v1::( - instance, params, - ) - }) -} - /// Terminates the existence of the currently executed smart contract. /// /// This removes the calling account and transfers all remaining balance diff --git a/crates/env/src/backend.rs b/crates/env/src/backend.rs index b3f09f6ff8..e1cfde3a45 100644 --- a/crates/env/src/backend.rs +++ b/crates/env/src/backend.rs @@ -12,11 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -#[cfg(not(feature = "revive"))] -use crate::call::{ - CallV1, - LimitParamsV1, -}; use crate::{ call::{ Call, @@ -36,9 +31,6 @@ use crate::{ Result, }; use ink_storage_traits::Storable; -#[cfg(not(feature = "revive"))] -pub use pallet_contracts_uapi::ReturnFlags; -#[cfg(feature = "revive")] pub use pallet_revive_uapi::ReturnFlags; /// Environmental contract functionality that does not require `Environment`. @@ -246,14 +238,6 @@ pub trait TypedEnvBackend: EnvBackend { /// For more details visit: [`weight_to_fee`][`crate::weight_to_fee`] fn weight_to_fee(&mut self, gas: u64) -> E::Balance; - /// Returns the amount of gas left for the contract execution. - /// - /// # Note - /// - /// For more details visit: [`gas_left`][`crate::gas_left`] - #[cfg(not(feature = "revive"))] - fn gas_left(&mut self) -> u64; - /// Returns the timestamp of the current block. /// /// # Note @@ -300,23 +284,6 @@ pub trait TypedEnvBackend: EnvBackend { E: Environment, Evt: Event; - /// Invokes a contract message and returns its result. - /// - /// # Note - /// - /// **This will call into the original `call` host function.** - /// - /// For more details visit: [`invoke_contract`][`crate::invoke_contract_v1`] - #[cfg(not(feature = "revive"))] - fn invoke_contract_v1( - &mut self, - call_data: &CallParams, Args, R>, - ) -> Result> - where - E: Environment, - Args: scale::Encode, - R: scale::Decode; - /// Invokes a contract message and returns its result. /// /// # Note @@ -368,22 +335,6 @@ pub trait TypedEnvBackend: EnvBackend { Salt: AsRef<[u8]>, R: ConstructorReturnType; - #[cfg(not(feature = "revive"))] - fn instantiate_contract_v1( - &mut self, - params: &CreateParams, - ) -> Result< - ink_primitives::ConstructorResult< - >::Output, - >, - > - where - E: Environment, - ContractRef: FromAccountId, - Args: scale::Encode, - Salt: AsRef<[u8]>, - R: ConstructorReturnType; - /// Terminates a smart contract. /// /// # Note diff --git a/crates/env/src/call/call_builder/call.rs b/crates/env/src/call/call_builder/call.rs index 1f69556972..45b0462b03 100644 --- a/crates/env/src/call/call_builder/call.rs +++ b/crates/env/src/call/call_builder/call.rs @@ -12,8 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -#[cfg(not(feature = "revive"))] -use crate::call::CallV1; use crate::{ call::{ common::{ @@ -31,9 +29,6 @@ use crate::{ Gas, }; use num_traits::Zero; -#[cfg(not(feature = "revive"))] -use pallet_contracts_uapi::CallFlags; -#[cfg(feature = "revive")] use pallet_revive_uapi::CallFlags; /// The default call type for cross-contract calls, for calling into the latest `call_v2` @@ -67,27 +62,6 @@ impl CallBuilder>, Args, RetType> where E: Environment, { - /// Switch to the original `call` host function API, which only allows the `gas_limit` - /// limit parameter (equivalent to the `ref_time_limit` in the latest `call_v2`). - /// - /// This method instance is used to allow usage of the generated call builder methods - /// for messages which initialize the builder with the new [`Call`] type. - #[cfg(not(feature = "revive"))] - pub fn call_v1(self) -> CallBuilder>, Args, RetType> { - let call_type = self.call_type.value(); - CallBuilder { - call_type: Set(CallV1 { - callee: call_type.callee, - gas_limit: call_type.ref_time_limit, - transferred_value: call_type.transferred_value, - call_flags: call_type.call_flags, - }), - exec_input: self.exec_input, - return_type: self.return_type, - _phantom: Default::default(), - } - } - /// Sets the `ref_time_limit` part of the weight limit for the current cross-contract /// call. /// diff --git a/crates/env/src/call/call_builder/call_v1.rs b/crates/env/src/call/call_builder/call_v1.rs deleted file mode 100644 index 484d31bd72..0000000000 --- a/crates/env/src/call/call_builder/call_v1.rs +++ /dev/null @@ -1,300 +0,0 @@ -// Copyright (C) Use Ink (UK) Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use super::CallParams; -use crate::{ - call::{ - common::{ - ReturnType, - Set, - Unset, - }, - execution::EmptyArgumentList, - CallBuilder, - ExecutionInput, - }, - Environment, - Error, - Gas, -}; -use num_traits::Zero; -#[cfg(not(feature = "revive"))] -use pallet_contracts_uapi::CallFlags; -#[cfg(feature = "revive")] -use pallet_revive_uapi::CallFlags; - -/// The legacy call type for cross-contract calls. Performs a cross-contract call to -/// `callee` with gas limit `gas_limit`, transferring `transferred_value` of currency. -/// -/// Calls into the original `call` host function. -#[derive(Clone)] -pub struct CallV1 { - pub(crate) callee: E::AccountId, - pub(crate) gas_limit: Gas, - pub(crate) transferred_value: E::Balance, - pub(crate) call_flags: CallFlags, -} - -impl CallV1 { - /// Returns a clean builder for [`CallV1`]. - pub fn new(callee: E::AccountId) -> Self { - Self { - callee, - gas_limit: Default::default(), - transferred_value: E::Balance::zero(), - call_flags: CallFlags::empty(), - } - } -} - -impl CallV1 -where - E: Environment, -{ - /// Sets the `gas_limit` for the current cross-contract call. - pub fn gas_limit(self, gas_limit: Gas) -> Self { - CallV1 { gas_limit, ..self } - } - - /// Sets the `transferred_value` for the current cross-contract call. - pub fn transferred_value(self, transferred_value: E::Balance) -> Self { - CallV1 { - transferred_value, - ..self - } - } -} - -impl CallBuilder>, Args, RetType> -where - E: Environment, -{ - /// Sets the `gas_limit` for the current cross-contract call. - pub fn gas_limit(self, gas_limit: Gas) -> Self { - let call_type = self.call_type.value(); - CallBuilder { - call_type: Set(CallV1 { - callee: call_type.callee, - gas_limit, - transferred_value: call_type.transferred_value, - call_flags: call_type.call_flags, - }), - exec_input: self.exec_input, - return_type: self.return_type, - _phantom: Default::default(), - } - } - - /// Sets the `transferred_value` for the current cross-contract call. - pub fn transferred_value(self, transferred_value: E::Balance) -> Self { - let call_type = self.call_type.value(); - CallBuilder { - call_type: Set(CallV1 { - callee: call_type.callee, - gas_limit: call_type.gas_limit, - transferred_value, - call_flags: call_type.call_flags, - }), - exec_input: self.exec_input, - return_type: self.return_type, - _phantom: Default::default(), - } - } - - /// Sets the flags used to change the behavior of the contract call. - #[inline] - #[must_use] - pub fn call_flags(self, call_flags: CallFlags) -> Self { - let call_type = self.call_type.value(); - CallBuilder { - call_type: Set(CallV1 { - callee: call_type.callee, - gas_limit: call_type.gas_limit, - transferred_value: call_type.transferred_value, - call_flags, - }), - exec_input: self.exec_input, - return_type: self.return_type, - _phantom: Default::default(), - } - } -} - -impl - CallBuilder>, Set>, Set>> -where - E: Environment, -{ - /// Finalizes the call builder to call a function. - pub fn params(self) -> CallParams, Args, RetType> { - CallParams { - call_type: self.call_type.value(), - _return_type: Default::default(), - exec_input: self.exec_input.value(), - _phantom: self._phantom, - } - } -} - -impl - CallBuilder< - E, - Set>, - Unset>, - Unset, - > -where - E: Environment, -{ - /// Finalizes the call builder to call a function. - pub fn params(self) -> CallParams, EmptyArgumentList, ()> { - CallParams { - call_type: self.call_type.value(), - _return_type: Default::default(), - exec_input: Default::default(), - _phantom: self._phantom, - } - } -} - -impl - CallBuilder< - E, - Set>, - Unset>, - Unset>, - > -where - E: Environment, -{ - /// Invokes the cross-chain function call. - /// - /// # Panics - /// - /// 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) { - self.params().invoke() - } - - /// Invokes the cross-chain function call. - /// - /// # Note - /// - /// On failure this returns an outer [`ink::env::Error`][`crate::Error`] or inner - /// [`ink::primitives::LangError`][`ink_primitives::LangError`], both of which can be - /// handled by the caller. - pub fn try_invoke(self) -> Result, Error> { - self.params().try_invoke() - } -} - -impl - CallBuilder>, Set>, Set>> -where - E: Environment, - Args: scale::Encode, - R: scale::Decode, -{ - /// Invokes the cross-chain function call and returns the result. - /// - /// # Panics - /// - /// 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 { - self.params().invoke() - } - - /// Invokes the cross-chain function call and returns the result. - /// - /// # Note - /// - /// On failure this returns an outer [`ink::env::Error`][`crate::Error`] or inner - /// [`ink::primitives::LangError`][`ink_primitives::LangError`], both of which can be - /// handled by the caller. - pub fn try_invoke(self) -> Result, Error> { - self.params().try_invoke() - } -} - -impl CallParams, Args, R> -where - E: Environment, -{ - /// Returns the account ID of the called contract instance. - #[inline] - pub fn callee(&self) -> &E::AccountId { - &self.call_type.callee - } - - /// Returns the chosen gas limit for the called contract execution. - #[inline] - pub fn gas_limit(&self) -> Gas { - self.call_type.gas_limit - } - - /// Returns the transferred value for the called contract. - #[inline] - pub fn transferred_value(&self) -> &E::Balance { - &self.call_type.transferred_value - } - - /// Returns the call flags. - #[inline] - pub fn call_flags(&self) -> &CallFlags { - &self.call_type.call_flags - } -} - -impl CallParams, Args, R> -where - E: Environment, - Args: scale::Encode, - R: scale::Decode, -{ - /// Invokes the contract with the given built-up call parameters. - /// - /// Returns the result of the contract execution. - /// - /// # Panics - /// - /// 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_v1(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. - /// - /// Returns the result of the contract execution. - /// - /// # Note - /// - /// On failure this returns an outer [`ink::env::Error`][`crate::Error`] or inner - /// [`ink::primitives::LangError`][`ink_primitives::LangError`], both of which can be - /// handled by the caller. - pub fn try_invoke(&self) -> Result, crate::Error> { - crate::invoke_contract_v1(self) - } -} diff --git a/crates/env/src/call/call_builder/delegate.rs b/crates/env/src/call/call_builder/delegate.rs index c78d5e8d8b..e4cbb19c17 100644 --- a/crates/env/src/call/call_builder/delegate.rs +++ b/crates/env/src/call/call_builder/delegate.rs @@ -27,9 +27,6 @@ use crate::{ Environment, Error, }; -#[cfg(not(feature = "revive"))] -use pallet_contracts_uapi::CallFlags; -#[cfg(feature = "revive")] use pallet_revive_uapi::CallFlags; /// The `delegatecall` call type. Performs a call with the given code hash. diff --git a/crates/env/src/call/call_builder/mod.rs b/crates/env/src/call/call_builder/mod.rs index 395239c2e0..bb0ac39888 100644 --- a/crates/env/src/call/call_builder/mod.rs +++ b/crates/env/src/call/call_builder/mod.rs @@ -13,13 +13,9 @@ // limitations under the License. mod call; -#[cfg(not(feature = "revive"))] -mod call_v1; mod delegate; pub use call::Call; -#[cfg(not(feature = "revive"))] -pub use call_v1::CallV1; pub use delegate::DelegateCall; use crate::{ @@ -316,21 +312,6 @@ impl CallBuilder, Args, RetType> where E: Environment, { - /// Prepares the `CallBuilder` for a cross-contract [`CallV1`], calling into the - /// original `call` host function. - #[cfg(not(feature = "revive"))] - pub fn call_v1( - self, - callee: E::AccountId, - ) -> CallBuilder>, Args, RetType> { - CallBuilder { - call_type: Set(CallV1::new(callee)), - exec_input: self.exec_input, - return_type: self.return_type, - _phantom: Default::default(), - } - } - /// Prepares the `CallBuilder` for a cross-contract [`Call`] to the latest `call_v2` /// host function. pub fn call( diff --git a/crates/env/src/call/create_builder.rs b/crates/env/src/call/create_builder.rs index 2b17eb577d..0ce459a651 100644 --- a/crates/env/src/call/create_builder.rs +++ b/crates/env/src/call/create_builder.rs @@ -337,55 +337,6 @@ where } } -#[cfg(not(feature = "revive"))] -impl - CreateParams -where - E: Environment, - ContractRef: FromAccountId, - Args: scale::Encode, - Salt: AsRef<[u8]>, - R: ConstructorReturnType, -{ - /// 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`] or an - /// [`ink::primitives::LangError`][`ink_primitives::LangError`]. If you want to handle - /// those use the [`try_instantiate`][`CreateParams::try_instantiate`] method - /// instead. - #[inline] - pub fn instantiate(&self) -> >::Output { - self.try_instantiate() - .unwrap_or_else(|env_error| { - panic!("Cross-contract instantiation failed with {env_error:?}") - }) - .unwrap_or_else(|lang_error| { - panic!("Received a `LangError` while instantiating: {lang_error:?}") - }) - } - - /// Instantiates the contract and returns its account ID back to the caller. - /// - /// # Note - /// - /// On failure this returns an outer [`ink::env::Error`][`crate::Error`] or inner - /// [`ink::primitives::LangError`][`ink_primitives::LangError`], both of which can be - /// handled by the caller. - #[inline] - pub fn try_instantiate( - &self, - ) -> Result< - ink_primitives::ConstructorResult< - >::Output, - >, - Error, - > { - crate::instantiate_contract_v1(self) - } -} - /// Builds up contract instantiations. #[derive(Clone)] pub struct CreateBuilder @@ -920,55 +871,3 @@ where self.params().try_instantiate() } } - -#[cfg(not(feature = "revive"))] -impl - CreateBuilder< - E, - ContractRef, - Set, - Set, - Set, - Set>, - Set, - Set>, - > -where - E: Environment, - ContractRef: FromAccountId, - Args: scale::Encode, - Salt: AsRef<[u8]>, - RetType: ConstructorReturnType, -{ - /// 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`] or an - /// [`ink::primitives::LangError`][`ink_primitives::LangError`]. If you want to handle - /// those use the [`try_instantiate`][`CreateBuilder::try_instantiate`] method - /// instead. - #[inline] - pub fn instantiate(self) -> >::Output { - self.params().instantiate() - } - - /// Instantiates the contract and returns its account ID back to the caller. - /// - /// # Note - /// - /// On failure this returns an outer [`ink::env::Error`][`crate::Error`] or inner - /// [`ink::primitives::LangError`][`ink_primitives::LangError`], both of which can be - /// handled by the caller. - #[inline] - pub fn try_instantiate( - self, - ) -> Result< - ink_primitives::ConstructorResult< - >::Output, - >, - Error, - > { - self.params().try_instantiate() - } -} diff --git a/crates/env/src/call/mod.rs b/crates/env/src/call/mod.rs index b3922cb837..9166af0636 100644 --- a/crates/env/src/call/mod.rs +++ b/crates/env/src/call/mod.rs @@ -39,11 +39,6 @@ pub mod utils { }; } -#[cfg(not(feature = "revive"))] -pub use self::{ - call_builder::CallV1, - create_builder::LimitParamsV1 -}; pub use self::{ call_builder::{ build_call, diff --git a/crates/env/src/engine/mod.rs b/crates/env/src/engine/mod.rs index 8cb83f551c..a4ec50608d 100644 --- a/crates/env/src/engine/mod.rs +++ b/crates/env/src/engine/mod.rs @@ -29,10 +29,6 @@ use ink_primitives::{ ConstructorResult, LangError, }; - -#[cfg(not(feature = "revive"))] -use pallet_contracts_uapi::ReturnErrorCode; -#[cfg(feature = "revive")] use pallet_revive_uapi::ReturnErrorCode; /// Convert a slice into an array reference. diff --git a/crates/env/src/engine/off_chain/impls.rs b/crates/env/src/engine/off_chain/impls.rs index 9f1e0718c9..82517dc352 100644 --- a/crates/env/src/engine/off_chain/impls.rs +++ b/crates/env/src/engine/off_chain/impls.rs @@ -13,11 +13,6 @@ // limitations under the License. use super::EnvInstance; -#[cfg(not(feature = "revive"))] -use crate::call::{ - CallV1, - LimitParamsV1, -}; use crate::{ call::{ Call, @@ -51,12 +46,6 @@ use ink_storage_traits::{ decode_all, Storable, }; -#[cfg(not(feature = "revive"))] -use pallet_contracts_uapi::{ - ReturnErrorCode, - ReturnFlags, -}; -#[cfg(feature = "revive")] use pallet_revive_uapi::{ ReturnErrorCode, ReturnFlags, @@ -395,14 +384,6 @@ impl TypedEnvBackend for EnvInstance { }) } - #[cfg(not(feature = "revive"))] - fn gas_left(&mut self) -> u64 { - self.get_property::(Engine::gas_left) - .unwrap_or_else(|error| { - panic!("could not read `gas_left` property: {error:?}") - }) - } - fn block_timestamp(&mut self) -> E::Timestamp { self.get_property::(Engine::block_timestamp) .unwrap_or_else(|error| { @@ -449,19 +430,6 @@ impl TypedEnvBackend for EnvInstance { self.engine.deposit_event(&enc_topics[..], enc_data); } - #[cfg(not(feature = "revive"))] - fn invoke_contract_v1( - &mut self, - _params: &CallParams, Args, R>, - ) -> Result> - where - E: Environment, - Args: scale::Encode, - R: scale::Decode, - { - unimplemented!("off-chain environment does not support contract invocation") - } - fn invoke_contract( &mut self, _params: &CallParams, Args, R>, @@ -514,30 +482,6 @@ impl TypedEnvBackend for EnvInstance { unimplemented!("off-chain environment does not support contract instantiation") } - #[cfg(not(feature = "revive"))] - fn instantiate_contract_v1( - &mut self, - params: &CreateParams, - ) -> Result< - ink_primitives::ConstructorResult< - >::Output, - >, - > - where - E: Environment, - ContractRef: FromAccountId, - Args: scale::Encode, - Salt: AsRef<[u8]>, - R: ConstructorReturnType, - { - let _code_hash = params.code_hash(); - let _ref_time_limit = params.gas_limit(); - let _endowment = params.endowment(); - let _input = params.exec_input(); - let _salt_bytes = params.salt_bytes(); - unimplemented!("off-chain environment does not support contract instantiation") - } - fn terminate_contract(&mut self, beneficiary: E::AccountId) -> ! where E: Environment, diff --git a/crates/env/src/error.rs b/crates/env/src/error.rs index 195e3978f0..27c0154f10 100644 --- a/crates/env/src/error.rs +++ b/crates/env/src/error.rs @@ -16,9 +16,6 @@ use derive_more::From; #[cfg(any(feature = "std", test, doc))] use crate::engine::off_chain::OffChainError; -#[cfg(not(feature = "revive"))] -use pallet_contracts_uapi::ReturnErrorCode; -#[cfg(feature = "revive")] use pallet_revive_uapi::ReturnErrorCode; /// Errors that can be encountered upon environmental interaction. diff --git a/crates/env/src/lib.rs b/crates/env/src/lib.rs index eff8fec1aa..79bd71a2ee 100644 --- a/crates/env/src/lib.rs +++ b/crates/env/src/lib.rs @@ -102,14 +102,6 @@ mod tests; #[doc(inline)] pub use self::engine::off_chain::test_api as test; -#[cfg(not(feature = "revive"))] -#[doc(inline)] -pub use pallet_contracts_uapi::{ - CallFlags, - ReturnErrorCode, - ReturnFlags, -}; -#[cfg(feature = "revive")] #[doc(inline)] pub use pallet_revive_uapi::{ CallFlags, diff --git a/crates/ink/codegen/src/generator/dispatch.rs b/crates/ink/codegen/src/generator/dispatch.rs index 22e7bef18b..21da1b1755 100644 --- a/crates/ink/codegen/src/generator/dispatch.rs +++ b/crates/ink/codegen/src/generator/dispatch.rs @@ -84,26 +84,6 @@ impl GenerateCode for Dispatch<'_> { let message_decoder_type = self.generate_message_decoder_type(&messages); let entry_points = self.generate_entry_points(&constructors, &messages); - #[cfg(not(feature = "revive"))] - return quote! { - #contract_dispatchable_constructor_infos - #contract_dispatchable_messages_infos - #constructor_decoder_type - #message_decoder_type - - #[cfg(not(any(test, feature = "std", feature = "ink-as-dependency")))] - /* - const _: () = { - #entry_points - } - */ - mod __do_not_access__ { - use super::*; - #entry_points - } - }; - - #[cfg(feature = "revive")] quote! { #contract_dispatchable_constructor_infos #contract_dispatchable_messages_infos @@ -373,93 +353,6 @@ impl Dispatch<'_> { self.any_constructor_accepts_payment(constructors); let any_message_accepts_payment = self.any_message_accepts_payment(messages); - #[cfg(not(feature = "revive"))] - return quote_spanned!(span=> - #[allow(clippy::nonminimal_bool)] - fn internal_deploy() { - if !#any_constructor_accept_payment { - ::ink::codegen::deny_payment::<<#storage_ident as ::ink::env::ContractEnv>::Env>() - .unwrap_or_else(|error| ::core::panic!("{}", error)) - } - - let dispatchable = match ::ink::env::decode_input::< - <#storage_ident as ::ink::reflect::ContractConstructorDecoder>::Type, - >() { - ::core::result::Result::Ok(decoded_dispatchable) => { - decoded_dispatchable - } - ::core::result::Result::Err(_decoding_error) => { - let error = ::ink::ConstructorResult::Err(::ink::LangError::CouldNotReadInput); - - // At this point we're unable to set the `Ok` variant to be the any "real" - // constructor output since we were unable to figure out what the caller wanted - // to dispatch in the first place, so we set it to `()`. - // - // This is okay since we're going to only be encoding the `Err` variant - // into the output buffer anyways. - ::ink::env::return_value::<::ink::ConstructorResult<()>>( - ::ink::env::ReturnFlags::REVERT, - &error, - ); - } - }; - - <<#storage_ident as ::ink::reflect::ContractConstructorDecoder>::Type - as ::ink::reflect::ExecuteDispatchable>::execute_dispatchable(dispatchable) - .unwrap_or_else(|error| { - ::core::panic!("dispatching ink! message failed: {}", error) - }) - } - - #[allow(clippy::nonminimal_bool)] - fn internal_call() { - if !#any_message_accepts_payment { - ::ink::codegen::deny_payment::<<#storage_ident as ::ink::env::ContractEnv>::Env>() - .unwrap_or_else(|error| ::core::panic!("{}", error)) - } - - let dispatchable = match ::ink::env::decode_input::< - <#storage_ident as ::ink::reflect::ContractMessageDecoder>::Type, - >() { - ::core::result::Result::Ok(decoded_dispatchable) => { - decoded_dispatchable - } - ::core::result::Result::Err(_decoding_error) => { - let error = ::ink::MessageResult::Err(::ink::LangError::CouldNotReadInput); - - // At this point we're unable to set the `Ok` variant to be the any "real" - // message output since we were unable to figure out what the caller wanted - // to dispatch in the first place, so we set it to `()`. - // - // This is okay since we're going to only be encoding the `Err` variant - // into the output buffer anyways. - ::ink::env::return_value::<::ink::MessageResult<()>>( - ::ink::env::ReturnFlags::REVERT, - &error, - ); - } - }; - - <<#storage_ident as ::ink::reflect::ContractMessageDecoder>::Type - as ::ink::reflect::ExecuteDispatchable>::execute_dispatchable(dispatchable) - .unwrap_or_else(|error| { - ::core::panic!("dispatching ink! message failed: {}", error) - }) - } - - #[cfg(target_arch = "wasm32")] - #[no_mangle] - pub extern "C" fn call() { - internal_call() - } - - #[cfg(target_arch = "wasm32")] - #[no_mangle] - pub extern "C" fn deploy() { - internal_deploy() - } - ); - #[cfg(feature = "revive")] let fn_call: syn::ItemFn = syn::parse_quote! { #[cfg(any(target_arch = "wasm32", target_arch = "riscv32"))] #[cfg_attr(target_arch = "wasm32", no_mangle)] @@ -468,7 +361,6 @@ impl Dispatch<'_> { internal_call() } }; - #[cfg(feature = "revive")] let fn_deploy: syn::ItemFn = syn::parse_quote! { #[cfg(any(target_arch = "wasm32", target_arch = "riscv32"))] #[cfg_attr(target_arch = "wasm32", no_mangle)] @@ -477,7 +369,6 @@ impl Dispatch<'_> { internal_deploy() } }; - #[cfg(feature = "revive")] quote_spanned!(span=> #[allow(clippy::nonminimal_bool)] fn internal_deploy() { diff --git a/crates/ink/src/env_access.rs b/crates/ink/src/env_access.rs index 60439d63e2..cd0e564dd0 100644 --- a/crates/ink/src/env_access.rs +++ b/crates/ink/src/env_access.rs @@ -14,11 +14,6 @@ use crate::ChainExtensionInstance; use core::marker::PhantomData; -#[cfg(not(feature = "revive"))] -use ink_env::call::{ - CallV1, - LimitParamsV1, -}; use ink_env::{ call::{ Call, @@ -36,9 +31,6 @@ use ink_env::{ Environment, Result, }; -#[cfg(not(feature = "revive"))] -use pallet_contracts_uapi::ReturnErrorCode; -#[cfg(feature = "revive")] use pallet_revive_uapi::ReturnErrorCode; /// The API behind the `self.env()` and `Self::env()` syntax in ink!. @@ -196,45 +188,6 @@ where ink_env::weight_to_fee::(gas) } - /// Returns the amount of gas left for the contract execution. - /// - /// # Example - /// - /// ``` - /// # #[ink::contract] - /// # pub mod my_contract { - /// # #[ink(storage)] - /// # pub struct MyContract { } - /// # - /// # impl MyContract { - /// # #[ink(constructor)] - /// # pub fn new() -> Self { - /// # Self {} - /// # } - /// # - /// /// Returns a tuple of - /// /// - the result of adding the `rhs` to the `lhs` and - /// /// - the gas used for this addition operation. - /// #[ink(message)] - /// pub fn addition_gas_cost(&self, rhs: i32, lhs: i32) -> (i32, u64) { - /// let before = self.env().gas_left(); - /// let result = rhs + lhs; - /// let after = self.env().gas_left(); - /// (result, after - before) - /// } - /// # - /// # } - /// # } - /// ``` - /// - /// # Note - /// - /// For more details visit: [`ink_env::gas_left`] - #[cfg(not(feature = "revive"))] - pub fn gas_left(self) -> u64 { - ink_env::gas_left::() - } - /// Returns the timestamp of the current block. /// /// # Example @@ -522,167 +475,6 @@ where ink_env::instantiate_contract::(params) } - /// Instantiates another contract using the supplied code hash. - /// - /// # Example - /// - /// ``` - /// # #[ink::contract] - /// # pub mod my_contract { - /// # // In order for this to actually work with another contract we'd need a way - /// # // to turn the `ink-as-dependency` crate feature on in doctests, which we - /// # // can't do. - /// # // - /// # // Instead we use our own contract's `Ref`, which is fine for this example - /// # // (just need something that implements the `ContractRef` trait). - /// # pub mod other_contract { - /// # pub use super::MyContractRef as OtherContractRef; - /// # } - /// use ink::env::{ - /// DefaultEnvironment, - /// call::{build_create, Selector, ExecutionInput} - /// }; - /// use other_contract::OtherContractRef; - /// # - /// # #[ink(storage)] - /// # pub struct MyContract { } - /// # - /// # impl MyContract { - /// # #[ink(constructor)] - /// # pub fn new() -> Self { - /// # Self {} - /// # } - /// # - /// - /// /// Instantiates another contract. - /// #[ink(message)] - /// pub fn instantiate_contract(&self) -> MyContractRef { - /// let create_params = build_create::() - /// .instantiate_v1() - /// .code_hash(Hash::from([0x42; 32])) - /// .gas_limit(500_000_000) - /// .endowment(25) - /// .exec_input( - /// ExecutionInput::new(Selector::new(ink::selector_bytes!("new"))) - /// .push_arg(42) - /// .push_arg(true) - /// .push_arg(&[0x10u8; 32]), - /// ) - /// .salt_bytes(&[0xCA, 0xFE, 0xBA, 0xBE]) - /// .returns::() - /// .params(); - /// self.env() - /// .instantiate_contract_v1(&create_params) - /// .unwrap_or_else(|error| { - /// panic!( - /// "Received an error from the Contracts pallet while instantiating: {:?}", - /// error - /// ) - /// }) - /// .unwrap_or_else(|error| panic!("Received a `LangError` while instatiating: {:?}", error)) - /// } - /// # - /// # } - /// # } - /// ``` - /// - /// See [our `delegator` example](https://github.com/use-ink/ink-examples/tree/main/upgradeable-contracts#delegator) - /// for a complete contract example. - /// - /// # Note - /// - /// For more details visit: [`ink_env::instantiate_contract_v1`] - - #[cfg(not(feature = "revive"))] - pub fn instantiate_contract_v1( - self, - params: &CreateParams, - ) -> Result< - ink_primitives::ConstructorResult< - >::Output, - >, - > - where - ContractRef: FromAccountId, - Args: scale::Encode, - Salt: AsRef<[u8]>, - R: ConstructorReturnType, - { - ink_env::instantiate_contract_v1::(params) - } - - /// Invokes a contract message and returns its result. - /// - /// # Example - /// - /// ``` - /// # #[ink::contract] - /// # pub mod my_contract { - /// use ink::env::{ - /// call::{ - /// build_call, - /// CallV1, - /// ExecutionInput, - /// Selector, - /// }, - /// DefaultEnvironment, - /// }; - /// - /// # - /// # #[ink(storage)] - /// # pub struct MyContract { } - /// # - /// # impl MyContract { - /// # #[ink(constructor)] - /// # pub fn new() -> Self { - /// # Self {} - /// # } - /// # - /// /// Invokes a contract message and fetches the result. - /// #[ink(message)] - /// pub fn invoke_contract(&self) -> i32 { - /// let call_params = build_call::() - /// .call_type( - /// CallV1::new(AccountId::from([0x42; 32])) - /// .gas_limit(5000) - /// .transferred_value(10), - /// ) - /// .exec_input( - /// ExecutionInput::new(Selector::new([0xCA, 0xFE, 0xBA, 0xBE])) - /// .push_arg(42u8) - /// .push_arg(true) - /// .push_arg(&[0x10u8; 32]), - /// ) - /// .returns::() - /// .params(); - /// - /// self.env() - /// .invoke_contract_v1(&call_params) - /// .unwrap_or_else(|env_err| { - /// panic!("Received an error from the Environment: {:?}", env_err) - /// }) - /// .unwrap_or_else(|lang_err| panic!("Received a `LangError`: {:?}", lang_err)) - /// } - /// # - /// # } - /// # } - /// ``` - /// - /// # Note - /// - /// For more details visit: [`ink_env::invoke_contract_v1`] - #[cfg(not(feature = "revive"))] - pub fn invoke_contract_v1( - self, - params: &CallParams, Args, R>, - ) -> Result> - where - Args: scale::Encode, - R: scale::Decode, - { - ink_env::invoke_contract_v1::(params) - } - /// Invokes a contract message and returns its result. /// /// # Example