Skip to content
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

instantiate_v2 with additional limit parameters #2123

Merged
merged 22 commits into from
Feb 27, 2024
Merged
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 @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [Linter] Publish the linting crates on crates.io - [#2060](https://github.com/paritytech/ink/pull/2060)
- [E2E] Added `create_call_builder` for testing existing contracts - [#2075](https://github.com/paritytech/ink/pull/2075)
- `call_v2` cross-contract calls with additional limit parameters - [#2077](https://github.com/paritytech/ink/pull/2077)
- `instantiate_v2` with additional limit parameters - [#2123](https://github.com/paritytech/ink/pull/2123)
- `delegate_dependency` api calls - [#2076](https://github.com/paritytech/ink/pull/2076)

### Changed
Expand Down
3 changes: 2 additions & 1 deletion crates/e2e/src/builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use ink_env::{
},
CreateBuilder,
ExecutionInput,
LimitParamsV2,
},
Environment,
};
Expand All @@ -32,7 +33,7 @@ pub type CreateBuilderPartial<E, ContractRef, Args, R> = CreateBuilder<
E,
ContractRef,
Unset<<E as Environment>::Hash>,
Unset<u64>,
Set<LimitParamsV2<E>>,
Unset<<E as Environment>::Balance>,
Set<ExecutionInput<Args>>,
Unset<ink_env::call::state::Salt>,
Expand Down
45 changes: 43 additions & 2 deletions crates/env/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ use crate::{
CreateParams,
DelegateCall,
FromAccountId,
LimitParamsV1,
LimitParamsV2,
},
engine::{
EnvInstance,
Expand Down Expand Up @@ -351,7 +353,8 @@ where
///
/// # Note
///
/// This is a low level way to instantiate another smart contract.
/// This is a low level way to instantiate another smart contract, calling the latest
/// `instantiate_v2` host function.
///
/// Prefer to use methods on a `ContractRef` or the
/// [`CreateBuilder`](`crate::call::CreateBuilder`)
Expand All @@ -366,7 +369,7 @@ where
/// - If given insufficient endowment.
/// - If the returned account ID failed to decode properly.
pub fn instantiate_contract<E, ContractRef, Args, Salt, R>(
params: &CreateParams<E, ContractRef, Args, Salt, R>,
params: &CreateParams<E, ContractRef, LimitParamsV2<E>, Args, Salt, R>,
) -> Result<
ink_primitives::ConstructorResult<<R as ConstructorReturnType<ContractRef>>::Output>,
>
Expand All @@ -384,6 +387,44 @@ 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.
pub fn instantiate_contract_v1<E, ContractRef, Args, Salt, R>(
params: &CreateParams<E, ContractRef, LimitParamsV1, Args, Salt, R>,
) -> Result<
ink_primitives::ConstructorResult<<R as ConstructorReturnType<ContractRef>>::Output>,
>
where
E: Environment,
ContractRef: FromAccountId<E>,
Args: scale::Encode,
Salt: AsRef<[u8]>,
R: ConstructorReturnType<ContractRef>,
{
<EnvInstance as OnInstance>::on_instance(|instance| {
TypedEnvBackend::instantiate_contract_v1::<E, ContractRef, Args, Salt, R>(
instance, params,
)
})
}

/// Terminates the existence of the currently executed smart contract.
///
/// This removes the calling account and transfers all remaining balance
Expand Down
19 changes: 18 additions & 1 deletion crates/env/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ use crate::{
CreateParams,
DelegateCall,
FromAccountId,
LimitParamsV1,
LimitParamsV2,
},
event::Event,
hash::{
Expand Down Expand Up @@ -345,7 +347,22 @@ pub trait TypedEnvBackend: EnvBackend {
/// For more details visit: [`instantiate_contract`][`crate::instantiate_contract`]
fn instantiate_contract<E, ContractRef, Args, Salt, R>(
&mut self,
params: &CreateParams<E, ContractRef, Args, Salt, R>,
params: &CreateParams<E, ContractRef, LimitParamsV2<E>, Args, Salt, R>,
) -> Result<
ink_primitives::ConstructorResult<
<R as ConstructorReturnType<ContractRef>>::Output,
>,
>
where
E: Environment,
ContractRef: FromAccountId<E>,
Args: scale::Encode,
Salt: AsRef<[u8]>,
R: ConstructorReturnType<ContractRef>;

fn instantiate_contract_v1<E, ContractRef, Args, Salt, R>(
&mut self,
params: &CreateParams<E, ContractRef, LimitParamsV1, Args, Salt, R>,
) -> Result<
ink_primitives::ConstructorResult<
<R as ConstructorReturnType<ContractRef>>::Output,
Expand Down
2 changes: 1 addition & 1 deletion crates/env/src/call/call_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ where
/// 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 original [`CallV1`] type.
/// for messages which initialize the builder with the new [`Call`] type.
pub fn call_v1(self) -> CallBuilder<E, Set<CallV1<E>>, Args, RetType> {
let call_type = self.call_type.value();
CallBuilder {
Expand Down
Loading