Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
3758e09
Remove fallible create_builder.rs methods
ascjones Jan 13, 2023
cdcc502
WIP experiment
ascjones Jan 14, 2023
6f59077
InstantiateResult blanket impl for T and Result
ascjones Jan 14, 2023
baecba9
Introduce ContractRef type parameter
ascjones Jan 14, 2023
af69cd5
Fix up env access
ascjones Jan 14, 2023
e134a8c
WIP...
ascjones Jan 14, 2023
115dd9f
Make it compile
ascjones Jan 15, 2023
718d475
Add ContractStorage parameter
ascjones Jan 16, 2023
bb5042e
Remove commented out instantiate_fallible_contract
ascjones Jan 16, 2023
528cfe0
Convert to env Error in helper
ascjones Jan 16, 2023
7b4c5e9
Return Decode errors in case of invalid Result first byte
ascjones Jan 16, 2023
4de38f5
Fix impls::instantiate_contract
ascjones Jan 16, 2023
09545fe
Remove ContractStorage generic parameter
ascjones Jan 17, 2023
2ef624d
Fix env access
ascjones Jan 17, 2023
02f97b1
Use generated constructor ref, introduces update_selector
ascjones Jan 17, 2023
39b45b0
Fix e2e
ascjones Jan 17, 2023
dc2f7bb
Remove commented out code
ascjones Jan 17, 2023
39ab13f
Typos
ascjones Jan 18, 2023
60e7e90
Clippy
ascjones Jan 18, 2023
43c2fe0
Rename some instantiate_fallible
ascjones Jan 18, 2023
bf3055c
Restore `returns` method
ascjones Jan 18, 2023
322ab26
Remove ContractReference Result impl
ascjones Jan 19, 2023
e61a12b
WIP implementing ConstructorReturnType
ascjones Jan 19, 2023
62052a6
Reorder ContractRef parameter, move ContractRef and ContractEnv trait…
ascjones Jan 19, 2023
2ed5093
Fmt and fix
ascjones Jan 19, 2023
df4a067
Remove E param from build_create
ascjones Jan 19, 2023
0e69431
Fix up build_create
ascjones Jan 20, 2023
e8feae9
Fix up e2e creat builder
ascjones Jan 20, 2023
2265258
Implement ContstructorReturnType for the storage_ident
ascjones Jan 20, 2023
10d7268
Fmt
ascjones Jan 20, 2023
ea65c47
Fix envaccess test
ascjones Jan 20, 2023
258c27b
Fully qualify Result in macro
ascjones Jan 20, 2023
08dc991
More fully qualify Result in macro
ascjones Jan 20, 2023
4be979d
Fix up build_create examples
ascjones Jan 20, 2023
0994c67
Add test for different combos of Self and struct name
ascjones Jan 20, 2023
f1f4930
Fix ui test
ascjones Jan 20, 2023
12f51dc
Fmt
ascjones Jan 20, 2023
1bceab3
Remove unused assoc type
ascjones Jan 20, 2023
8e0a9ef
Change error fn to return Option<Result>
ascjones Jan 20, 2023
aea1238
Remove commented out code
ascjones Jan 20, 2023
163fa6b
Fmt
ascjones Jan 20, 2023
1dd00d6
ConstructorReturnType comments
ascjones Jan 20, 2023
327967d
Fix `contract-ref` E2E test compilation
HCastano Jan 20, 2023
0bb7a8d
Fix up return types after merge
ascjones Jan 20, 2023
75ab4e6
Fmt
ascjones Jan 20, 2023
77a5bab
Clippy
ascjones Jan 20, 2023
7d03708
Fix create_builder tests
ascjones Jan 20, 2023
ca47caf
Fix cross-contract compile test
HCastano Jan 21, 2023
2cc8a22
Clean up some comments
HCastano Jan 21, 2023
fa0436a
Remove outdated doc
HCastano Jan 21, 2023
016b102
Update comment
HCastano Jan 21, 2023
9655072
Another comment fix
HCastano Jan 21, 2023
7aecb5f
Wrap long line
HCastano Jan 21, 2023
6f92033
Remove TODO
HCastano Jan 21, 2023
498c640
Bump `contract-metadata`
HCastano Jan 21, 2023
8e60ec2
Fix `CreateBuilder` compilation
HCastano Jan 24, 2023
a9c0223
Fix one of the doc tests
HCastano Jan 24, 2023
db1a808
Clean up doc tests a bit
HCastano Jan 24, 2023
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
2 changes: 1 addition & 1 deletion crates/e2e/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ ink = { version = "4.0.0-beta", path = "../ink" }
ink_env = { version = "4.0.0-beta", path = "../env" }
ink_primitives = { version = "4.0.0-beta", path = "../primitives" }

contract-metadata = { version = "2.0.0-beta.1" }
contract-metadata = { version = "2.0.0-rc" }
impl-serde = { version = "0.3.1", default-features = false }
jsonrpsee = { version = "0.16.0", features = ["ws-client"] }
serde = { version = "1.0.137", default-features = false, features = ["derive"] }
Expand Down
12 changes: 8 additions & 4 deletions crates/e2e/src/builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ use scale::Encode;

/// The type returned from `ContractRef` constructors, partially initialized with the execution
/// input arguments.
pub type CreateBuilderPartial<E, Args, R> = CreateBuilder<
pub type CreateBuilderPartial<E, ContractRef, Args, R> = CreateBuilder<
E,
ContractRef,
Unset<<E as Environment>::Hash>,
Unset<u64>,
Unset<<E as Environment>::Balance>,
Expand All @@ -43,9 +44,12 @@ pub type CreateBuilderPartial<E, Args, R> = CreateBuilder<
>;

/// Get the encoded constructor arguments from the partially initialized `CreateBuilder`
pub fn constructor_exec_input<E: Environment, Args: Encode, R>(
builder: CreateBuilderPartial<E, Args, R>,
) -> Vec<u8> {
pub fn constructor_exec_input<E, ContractRef, Args: Encode, R>(
builder: CreateBuilderPartial<E, ContractRef, Args, R>,
) -> Vec<u8>
where
E: Environment,
{
// set all the other properties to default values, we only require the `exec_input`.
builder
.endowment(0u32.into())
Expand Down
12 changes: 6 additions & 6 deletions crates/e2e/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,11 +350,11 @@ where
/// Calling this function multiple times is idempotent, the contract is
/// newly instantiated each time using a unique salt. No existing contract
/// instance is reused!
pub async fn instantiate<Args, R>(
pub async fn instantiate<ContractRef, Args, R>(
&mut self,
contract_name: &str,
signer: &Signer<C>,
constructor: CreateBuilderPartial<E, Args, R>,
constructor: CreateBuilderPartial<E, ContractRef, Args, R>,
value: E::Balance,
storage_deposit_limit: Option<E::Balance>,
) -> Result<InstantiationResult<C, E>, Error<C, E>>
Expand All @@ -374,11 +374,11 @@ where
}

/// Dry run contract instantiation using the given constructor.
pub async fn instantiate_dry_run<Args, R>(
pub async fn instantiate_dry_run<ContractRef, Args, R>(
&mut self,
contract_name: &str,
signer: &Signer<C>,
constructor: CreateBuilderPartial<E, Args, R>,
constructor: CreateBuilderPartial<E, ContractRef, Args, R>,
value: E::Balance,
storage_deposit_limit: Option<E::Balance>,
) -> ContractInstantiateResult<C::AccountId, E::Balance>
Expand Down Expand Up @@ -406,11 +406,11 @@ where
}

/// Executes an `instantiate_with_code` call and captures the resulting events.
async fn exec_instantiate<Args, R>(
async fn exec_instantiate<ContractRef, Args, R>(
&mut self,
signer: &Signer<C>,
code: Vec<u8>,
constructor: CreateBuilderPartial<E, Args, R>,
constructor: CreateBuilderPartial<E, ContractRef, Args, R>,
value: E::Balance,
storage_deposit_limit: Option<E::Balance>,
) -> Result<InstantiationResult<C, E>, Error<C, E>>
Expand Down
3 changes: 3 additions & 0 deletions crates/env/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ secp256k1 = { version = "0.26.0", features = ["recovery", "global-context"], opt
# Never use this crate outside the off-chain environment!
scale-info = { version = "2.3", default-features = false, features = ["derive"], optional = true }

[dev-dependencies]
ink = { path = "../ink" }

[features]
default = ["std"]
std = [
Expand Down
44 changes: 8 additions & 36 deletions crates/env/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ use crate::{
call::{
Call,
CallParams,
ConstructorReturnType,
CreateParams,
DelegateCall,
FromAccountId,
},
engine::{
EnvInstance,
Expand Down Expand Up @@ -323,50 +325,20 @@ where
/// - 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<E, Args, Salt, R>(
params: &CreateParams<E, Args, Salt, R>,
) -> Result<ink_primitives::ConstructorResult<E::AccountId>>
where
E: Environment,
Args: scale::Encode,
Salt: AsRef<[u8]>,
{
<EnvInstance as OnInstance>::on_instance(|instance| {
TypedEnvBackend::instantiate_contract::<E, Args, Salt, R>(instance, params)
})
}

/// Attempts to instantiate another contract, returning the instantiation result back to the
/// caller.
///
/// # Note
///
/// This is a low level way to instantiate another smart contract.
///
/// 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_fallible_contract<E, Args, Salt, R, ContractError>(
params: &CreateParams<E, Args, Salt, R>,
pub fn instantiate_contract<E, ContractRef, Args, Salt, R>(
params: &CreateParams<E, ContractRef, Args, Salt, R>,
) -> Result<
ink_primitives::ConstructorResult<core::result::Result<E::AccountId, ContractError>>,
ink_primitives::ConstructorResult<<R as ConstructorReturnType<ContractRef>>::Output>,
>
where
E: Environment,
ContractRef: FromAccountId<E>,
Args: scale::Encode,
Salt: AsRef<[u8]>,
ContractError: scale::Decode,
R: ConstructorReturnType<ContractRef>,
{
<EnvInstance as OnInstance>::on_instance(|instance| {
TypedEnvBackend::instantiate_fallible_contract::<E, Args, Salt, R, ContractError>(
TypedEnvBackend::instantiate_contract::<E, ContractRef, Args, Salt, R>(
instance, params,
)
})
Expand Down
26 changes: 7 additions & 19 deletions crates/env/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ use crate::{
call::{
Call,
CallParams,
ConstructorReturnType,
CreateParams,
DelegateCall,
FromAccountId,
},
hash::{
CryptoHash,
Expand Down Expand Up @@ -439,34 +441,20 @@ pub trait TypedEnvBackend: EnvBackend {
/// # Note
///
/// For more details visit: [`instantiate_contract`][`crate::instantiate_contract`]
fn instantiate_contract<E, Args, Salt, R>(
fn instantiate_contract<E, ContractRef, Args, Salt, R>(
&mut self,
params: &CreateParams<E, Args, Salt, R>,
) -> Result<ink_primitives::ConstructorResult<E::AccountId>>
where
E: Environment,
Args: scale::Encode,
Salt: AsRef<[u8]>;

/// Attempts to instantiate another contract, returning the instantiation result back to the
/// caller.
///
/// # Note
///
/// For more details visit: [`instantiate_fallible_contract`][`crate::instantiate_fallible_contract`]
fn instantiate_fallible_contract<E, Args, Salt, R, ContractError>(
&mut self,
params: &CreateParams<E, Args, Salt, R>,
params: &CreateParams<E, ContractRef, Args, Salt, R>,
) -> Result<
ink_primitives::ConstructorResult<
core::result::Result<E::AccountId, ContractError>,
<R as ConstructorReturnType<ContractRef>>::Output,
>,
>
where
E: Environment,
ContractRef: FromAccountId<E>,
Args: scale::Encode,
Salt: AsRef<[u8]>,
ContractError: scale::Decode;
R: ConstructorReturnType<ContractRef>;

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