Skip to content

Support Solidity ABI encoded constructor dispatch #2525

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Support ABI `cfg` flag in codegen - [#2501](https://github.com/use-ink/ink/pull/2501)
- Generate Solidity ABI compatibility metadata - [#2510](https://github.com/use-ink/ink/pull/2510)
- Improve Solidity ABI support in `codegen`, `ink_env` and `ink_e2e` - [#2517](https://github.com/use-ink/ink/pull/2517)
- Support Solidity ABI encoded constructor dispatch - [#2525](https://github.com/use-ink/ink/pull/2525)

### Changed
- Use marker trait for finding ink! storage `struct` during code analysis - [2499](https://github.com/use-ink/ink/pull/2499)
Expand Down
18 changes: 10 additions & 8 deletions crates/e2e/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use ink_primitives::{
abi::{
AbiDecodeWith,
AbiEncodeWith,
Ink,
},
DepositLimit,
};
Expand Down Expand Up @@ -135,14 +134,15 @@ pub trait ContractsBackend<E: Environment> {
fn instantiate<
'a,
Contract: Clone,
Args: Send + Clone + AbiEncodeWith<Ink> + Sync,
Args: Send + Clone + AbiEncodeWith<Abi> + Sync,
R,
Abi: Send + Sync + Clone,
>(
&'a mut self,
contract_name: &'a str,
caller: &'a Keypair,
constructor: &'a mut CreateBuilderPartial<E, Contract, Args, R>,
) -> InstantiateBuilder<'a, E, Contract, Args, R, Self>
constructor: &'a mut CreateBuilderPartial<E, Contract, Args, R, Abi>,
) -> InstantiateBuilder<'a, E, Contract, Args, R, Self, Abi>
where
Self: Sized + BuilderClient<E>,
{
Expand Down Expand Up @@ -312,13 +312,14 @@ pub trait BuilderClient<E: Environment>: ContractsBackend<E> {
/// instance is reused!
async fn bare_instantiate<
Contract: Clone,
Args: Send + Sync + AbiEncodeWith<Ink> + Clone,
Args: Send + Sync + AbiEncodeWith<Abi> + Clone,
R,
Abi: Send + Sync + Clone,
>(
&mut self,
contract_name: &str,
caller: &Keypair,
constructor: &mut CreateBuilderPartial<E, Contract, Args, R>,
constructor: &mut CreateBuilderPartial<E, Contract, Args, R, Abi>,
value: E::Balance,
gas_limit: Weight,
storage_deposit_limit: DepositLimit<E::Balance>,
Expand All @@ -327,13 +328,14 @@ pub trait BuilderClient<E: Environment>: ContractsBackend<E> {
/// Dry run contract instantiation.
async fn bare_instantiate_dry_run<
Contract: Clone,
Args: Send + Sync + AbiEncodeWith<Ink> + Clone,
Args: Send + Sync + AbiEncodeWith<Abi> + Clone,
R,
Abi: Send + Sync + Clone,
>(
&mut self,
contract_name: &str,
caller: &Keypair,
constructor: &mut CreateBuilderPartial<E, Contract, Args, R>,
constructor: &mut CreateBuilderPartial<E, Contract, Args, R, Abi>,
value: E::Balance,
storage_deposit_limit: DepositLimit<E::Balance>,
) -> Result<InstantiateDryRunResult<E>, Self::Error>;
Expand Down
19 changes: 9 additions & 10 deletions crates/e2e/src/backend_calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use ink_primitives::{
abi::{
AbiDecodeWith,
AbiEncodeWith,
Ink,
},
DepositLimit,
};
Expand Down Expand Up @@ -65,7 +64,6 @@ where
E: Environment,
Args: Sync + AbiEncodeWith<Abi> + Clone,
RetType: Send + AbiDecodeWith<Abi>,

B: BuilderClient<E>,
Abi: Sync + Clone,
{
Expand Down Expand Up @@ -201,38 +199,39 @@ where
}

/// Allows to build an end-to-end instantiation call using a builder pattern.
pub struct InstantiateBuilder<'a, E, Contract, Args, R, B>
pub struct InstantiateBuilder<'a, E, Contract, Args, R, B, Abi>
where
E: Environment,
Args: AbiEncodeWith<Ink> + Clone,
Args: AbiEncodeWith<Abi> + Clone,
Contract: Clone,

B: ContractsBackend<E>,
{
client: &'a mut B,
caller: &'a Keypair,
contract_name: &'a str,
constructor: &'a mut CreateBuilderPartial<E, Contract, Args, R>,
constructor: &'a mut CreateBuilderPartial<E, Contract, Args, R, Abi>,
value: E::Balance,
extra_gas_portion: Option<u64>,
gas_limit: Option<Weight>,
storage_deposit_limit: DepositLimit<E::Balance>,
}

impl<'a, E, Contract, Args, R, B> InstantiateBuilder<'a, E, Contract, Args, R, B>
impl<'a, E, Contract, Args, R, B, Abi>
InstantiateBuilder<'a, E, Contract, Args, R, B, Abi>
where
E: Environment,
Args: AbiEncodeWith<Ink> + Clone + Send + Sync,
Args: AbiEncodeWith<Abi> + Clone + Send + Sync,
Contract: Clone,
B: BuilderClient<E>,
Abi: Send + Sync + Clone,
{
/// Initialize a call builder with essential values.
pub fn new(
client: &'a mut B,
caller: &'a Keypair,
contract_name: &'a str,
constructor: &'a mut CreateBuilderPartial<E, Contract, Args, R>,
) -> InstantiateBuilder<'a, E, Contract, Args, R, B>
constructor: &'a mut CreateBuilderPartial<E, Contract, Args, R, Abi>,
) -> InstantiateBuilder<'a, E, Contract, Args, R, B, Abi>
where
E::Balance: From<u32>,
{
Expand Down
13 changes: 5 additions & 8 deletions crates/e2e/src/builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,23 @@ use ink_env::{
},
Environment,
};
use ink_primitives::abi::{
AbiEncodeWith,
Ink,
};
use ink_primitives::abi::AbiEncodeWith;

use crate::H256;

/// The type returned from `ContractRef` constructors, partially initialized with the
/// execution input arguments.
pub type CreateBuilderPartial<E, ContractRef, Args, R> = CreateBuilder<
pub type CreateBuilderPartial<E, ContractRef, Args, R, Abi> = CreateBuilder<
E,
ContractRef,
Set<LimitParamsV2>,
Set<ExecutionInput<Args, Ink>>,
Set<ExecutionInput<Args, Abi>>,
Set<ReturnType<R>>,
>;

/// Get the encoded constructor arguments from the partially initialized `CreateBuilder`
pub fn constructor_exec_input<E, ContractRef, Args: AbiEncodeWith<Ink>, R>(
builder: CreateBuilderPartial<E, ContractRef, Args, R>,
pub fn constructor_exec_input<E, ContractRef, Args: AbiEncodeWith<Abi>, R, Abi>(
builder: CreateBuilderPartial<E, ContractRef, Args, R, Abi>,
) -> Vec<u8>
where
E: Environment,
Expand Down
11 changes: 6 additions & 5 deletions crates/e2e/src/sandbox_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ use ink_primitives::{
abi::{
AbiDecodeWith,
AbiEncodeWith,
Ink,
},
DepositLimit,
};
Expand Down Expand Up @@ -249,13 +248,14 @@ where
{
async fn bare_instantiate<
Contract: Clone,
Args: Send + Sync + AbiEncodeWith<Ink> + Clone,
Args: Send + Sync + AbiEncodeWith<Abi> + Clone,
R,
Abi: Send + Sync + Clone,
>(
&mut self,
contract_name: &str,
caller: &Keypair,
constructor: &mut CreateBuilderPartial<E, Contract, Args, R>,
constructor: &mut CreateBuilderPartial<E, Contract, Args, R, Abi>,
value: E::Balance,
gas_limit: Weight,
storage_deposit_limit: DepositLimit<E::Balance>,
Expand Down Expand Up @@ -308,13 +308,14 @@ where

async fn bare_instantiate_dry_run<
Contract: Clone,
Args: Send + Sync + AbiEncodeWith<Ink> + Clone,
Args: Send + Sync + AbiEncodeWith<Abi> + Clone,
R,
Abi: Send + Sync + Clone,
>(
&mut self,
contract_name: &str,
caller: &Keypair,
constructor: &mut CreateBuilderPartial<E, Contract, Args, R>,
constructor: &mut CreateBuilderPartial<E, Contract, Args, R, Abi>,
value: E::Balance,
storage_deposit_limit: DepositLimit<E::Balance>,
) -> Result<InstantiateDryRunResult<E>, Self::Error> {
Expand Down
11 changes: 6 additions & 5 deletions crates/e2e/src/subxt_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ use ink_primitives::{
abi::{
AbiDecodeWith,
AbiEncodeWith,
Ink,
},
types::AccountIdMapper,
DepositLimit,
Expand Down Expand Up @@ -536,13 +535,14 @@ where
{
async fn bare_instantiate<
Contract: Clone,
Args: Send + Sync + AbiEncodeWith<Ink> + Clone,
Args: Send + Sync + AbiEncodeWith<Abi> + Clone,
R,
Abi: Send + Sync + Clone,
>(
&mut self,
contract_name: &str,
caller: &Keypair,
constructor: &mut CreateBuilderPartial<E, Contract, Args, R>,
constructor: &mut CreateBuilderPartial<E, Contract, Args, R, Abi>,
value: E::Balance,
gas_limit: Weight,
storage_deposit_limit: DepositLimit<E::Balance>,
Expand All @@ -559,13 +559,14 @@ where

async fn bare_instantiate_dry_run<
Contract: Clone,
Args: Send + Sync + AbiEncodeWith<Ink> + Clone,
Args: Send + Sync + AbiEncodeWith<Abi> + Clone,
R,
Abi: Send + Sync + Clone,
>(
&mut self,
contract_name: &str,
caller: &Keypair,
constructor: &mut CreateBuilderPartial<E, Contract, Args, R>,
constructor: &mut CreateBuilderPartial<E, Contract, Args, R, Abi>,
value: E::Balance,
storage_deposit_limit: DepositLimit<E::Balance>,
) -> Result<InstantiateDryRunResult<E>, Self::Error> {
Expand Down
12 changes: 6 additions & 6 deletions crates/env/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

//! The public raw interface towards the host engine.

#[cfg(feature = "unstable-hostfn")]
use ink_primitives::abi::Ink;
use ink_primitives::{
abi::{
AbiDecodeWith,
Expand Down Expand Up @@ -350,8 +348,8 @@ where
/// - If given insufficient endowment.
/// - If the returned account ID failed to decode properly.
#[cfg(feature = "unstable-hostfn")]
pub fn instantiate_contract<E, ContractRef, Args, R>(
params: &CreateParams<E, ContractRef, LimitParamsV2, Args, R>,
pub fn instantiate_contract<E, ContractRef, Args, R, Abi>(
params: &CreateParams<E, ContractRef, LimitParamsV2, Args, R, Abi>,
) -> Result<
ink_primitives::ConstructorResult<<R as ConstructorReturnType<ContractRef>>::Output>,
>
Expand All @@ -361,11 +359,13 @@ where
<ContractRef as crate::ContractReverseReference>::Type:
crate::reflect::ContractConstructorDecoder,

Args: AbiEncodeWith<Ink>,
Args: AbiEncodeWith<Abi>,
R: ConstructorReturnType<ContractRef>,
{
<EnvInstance as OnInstance>::on_instance(|instance| {
TypedEnvBackend::instantiate_contract::<E, ContractRef, Args, R>(instance, params)
TypedEnvBackend::instantiate_contract::<E, ContractRef, Args, R, Abi>(
instance, params,
)
})
}

Expand Down
8 changes: 3 additions & 5 deletions crates/env/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#[cfg(feature = "unstable-hostfn")]
use ink_primitives::abi::Ink;
use ink_primitives::{
abi::{
AbiDecodeWith,
Expand Down Expand Up @@ -368,9 +366,9 @@ pub trait TypedEnvBackend: EnvBackend {
///
/// For more details visit: [`instantiate_contract`][`crate::instantiate_contract`]
#[cfg(feature = "unstable-hostfn")]
fn instantiate_contract<E, ContractRef, Args, R>(
fn instantiate_contract<E, ContractRef, Args, R, Abi>(
&mut self,
params: &CreateParams<E, ContractRef, LimitParamsV2, Args, R>,
params: &CreateParams<E, ContractRef, LimitParamsV2, Args, R, Abi>,
) -> Result<
ink_primitives::ConstructorResult<
<R as ConstructorReturnType<ContractRef>>::Output,
Expand All @@ -381,7 +379,7 @@ pub trait TypedEnvBackend: EnvBackend {
ContractRef: FromAddr + crate::ContractReverseReference,
<ContractRef as crate::ContractReverseReference>::Type:
crate::reflect::ContractConstructorDecoder,
Args: AbiEncodeWith<Ink>,
Args: AbiEncodeWith<Abi>,
R: ConstructorReturnType<ContractRef>;

/// Terminates a smart contract.
Expand Down
Loading
Loading