Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
de543ed
init call_v2 methods and types
ascjones Jan 29, 2024
8339352
add e2e tests to basic-contract-caller example
ascjones Jan 30, 2024
7fb24b9
Merge branch 'master' into aj/call-v2
ascjones Jan 30, 2024
a84fe4f
Add storage_deposit
ascjones Jan 30, 2024
b7ad4b0
Fix basic-contract-caller e2e tests
ascjones Jan 30, 2024
99a9c03
Remove `basic_contract_caller` integration test, moved to #1909
ascjones Jan 30, 2024
cc52b41
WIP adding cross_contract_calls test
ascjones Jan 31, 2024
a0813f9
Add `integration-test` for possible migration pattern (#1909)
ascjones Jan 31, 2024
bab2e0a
Add `basic-contract-caller` E2E test (#2085)
ascjones Jan 31, 2024
b2a2cf9
Only need one .gitignore
ascjones Jan 31, 2024
bd83e18
WIP adding create v2 API
ascjones Jan 31, 2024
ae6330a
Merge branch 'master' into aj/call-v2
ascjones Feb 1, 2024
ab251c2
Revert "WIP adding create v2 API"
ascjones Feb 1, 2024
16d1479
WIP e2e tests
ascjones Feb 1, 2024
85e7e9c
Add CallV2 builder methods
ascjones Feb 2, 2024
eb7ca99
Pass weight limit as params
ascjones Feb 2, 2024
2c0a632
Allow deprecated
ascjones Feb 2, 2024
8b6ce3f
Add storage_deposit_limit
ascjones Feb 2, 2024
982089d
Clippy
ascjones Feb 2, 2024
1d8cd75
Use struct update syntax
ascjones Feb 2, 2024
9393e42
Remove space
ascjones Feb 2, 2024
ab62c5b
CHANGELOG
ascjones Feb 2, 2024
818358e
fmt
ascjones Feb 2, 2024
b648bfc
Import OtherContract directly instead of reexporting
ascjones Feb 5, 2024
2c91364
Make other_contract pub
ascjones Feb 5, 2024
649bc69
Revert prev
ascjones Feb 5, 2024
58f5104
docs
ascjones Feb 5, 2024
7c9c85c
top level gitignore for integration-tests
ascjones Feb 5, 2024
e909ecd
Remove unused setters
ascjones Feb 5, 2024
6e75a0e
Use ContractRef
ascjones Feb 5, 2024
f6e77dc
integration-test comments
ascjones Feb 5, 2024
7b0b5b1
Rename to `call_v2`
ascjones Feb 5, 2024
b176da9
Comments and builder method
ascjones Feb 5, 2024
a3dd520
SP
ascjones Feb 5, 2024
1d400ad
comments
ascjones Feb 5, 2024
dab7ab0
fix doc test
ascjones Feb 6, 2024
d29152c
merge `basic-contract-caller` into `cross-contract-calls`
ascjones Feb 6, 2024
fab7a54
Make `call_v2` the default for cross contract calls
ascjones Feb 6, 2024
2fdb9ab
Complete switch to make `call_v2` default
ascjones Feb 6, 2024
fc409f1
Fix doc test
ascjones Feb 6, 2024
dbd4d87
Update crates/env/src/call/call_builder.rs
ascjones Feb 6, 2024
35b0907
Update crates/env/src/call/call_builder.rs
ascjones Feb 6, 2024
e766fae
Update crates/env/src/call/call_builder.rs
ascjones Feb 6, 2024
75ebea3
Update crates/env/src/call/call_builder.rs
ascjones Feb 6, 2024
b777fbf
Review suggestion
ascjones Feb 6, 2024
4d3a1d5
Fmt
ascjones Feb 6, 2024
6a5008e
Review suggestion and spellcheck
ascjones Feb 6, 2024
845c8cd
Use call_v2 in other examples
ascjones Feb 6, 2024
85edec2
Docs
ascjones Feb 6, 2024
183772b
Merge branch 'master' into aj/call-v2
ascjones Feb 8, 2024
3abc574
Merge branch 'master' into aj/call-v2
ascjones Feb 8, 2024
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
Prev Previous commit
Next Next commit
Add CallV2 builder methods
  • Loading branch information
ascjones committed Feb 2, 2024
commit 85e7e9c4704a389756eced6e69c3ab9ebe836c8c
108 changes: 104 additions & 4 deletions crates/env/src/call/call_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -648,17 +648,15 @@ where
E: Environment,
{
/// todo: [AJ] docs
pub fn v2(
self,
) -> CallBuilder<E, Set<CallV2<E>>, Args, RetType> {
pub fn v2(self) -> CallBuilder<E, Set<CallV2<E>>, Args, RetType> {
let call_type = self.call_type.value();
CallBuilder {
call_type: Set(CallV2 {
callee: call_type.callee,
ref_time_limit: call_type.gas_limit,
proof_time_limit: Default::default(),
transferred_value: call_type.transferred_value,
} ),
}),
call_flags: self.call_flags,
exec_input: self.exec_input,
return_type: self.return_type,
Expand Down Expand Up @@ -772,6 +770,23 @@ where
}
}

impl<E, Args, RetType>
CallBuilder<E, Set<CallV2<E>>, Set<ExecutionInput<Args>>, Set<ReturnType<RetType>>>
where
E: Environment,
{
/// Finalizes the call builder to call a function.
pub fn params(self) -> CallParams<E, CallV2<E>, Args, RetType> {
CallParams {
call_type: self.call_type.value(),
call_flags: self.call_flags,
_return_type: Default::default(),
exec_input: self.exec_input.value(),
_phantom: self._phantom,
}
}
}

impl<E, Args, RetType>
CallBuilder<
E,
Expand Down Expand Up @@ -811,6 +826,28 @@ where
}
}

impl<E, RetType>
CallBuilder<
E,
Set<CallV2<E>>,
Unset<ExecutionInput<EmptyArgumentList>>,
Unset<RetType>,
>
where
E: Environment,
{
/// Finalizes the call builder to call a function.
pub fn params(self) -> CallParams<E, CallV2<E>, EmptyArgumentList, ()> {
CallParams {
call_type: self.call_type.value(),
call_flags: self.call_flags,
_return_type: Default::default(),
exec_input: Default::default(),
_phantom: self._phantom,
}
}
}

impl<E, RetType>
CallBuilder<
E,
Expand Down Expand Up @@ -866,6 +903,39 @@ where
}
}

impl<E>
CallBuilder<
E,
Set<CallV2<E>>,
Unset<ExecutionInput<EmptyArgumentList>>,
Unset<ReturnType<()>>,
>
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<ink_primitives::MessageResult<()>, Error> {
self.params().try_invoke()
}
}

impl<E>
CallBuilder<
E,
Expand Down Expand Up @@ -928,6 +998,36 @@ where
}
}

impl<E, Args, R>
CallBuilder<E, Set<CallV2<E>>, Set<ExecutionInput<Args>>, Set<ReturnType<R>>>
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<ink_primitives::MessageResult<R>, Error> {
self.params().try_invoke()
}
}

impl<E, Args, R>
CallBuilder<E, Set<DelegateCall<E>>, Set<ExecutionInput<Args>>, Set<ReturnType<R>>>
where
Expand Down
2 changes: 1 addition & 1 deletion crates/env/src/call/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ pub use self::{
call_builder::{
build_call,
Call,
CallV2,
CallBuilder,
CallParams,
CallV2,
DelegateCall,
},
create_builder::{
Expand Down
27 changes: 15 additions & 12 deletions integration-tests/cross-contract-calls/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ mod cross_contract_calls {
use ink::{
codegen::ContractCallBuilder,
env::{
call::FromAccountId,
ContractEnv,
call::FromAccountId
},
};
use other_contract::{OtherContract, OtherContractRef};
use other_contract::{
OtherContract,
OtherContractRef,
};

type Env = <CrossContractCalls as ContractEnv>::Env;
type OtherContractCallBuilder = <OtherContract as ContractCallBuilder>::Type;
Expand All @@ -31,11 +34,14 @@ mod cross_contract_calls {
.salt_bytes([0xDE, 0xAD, 0xBE, 0xEF])
.instantiate();

let other_contract_call_builder = <OtherContractCallBuilder as FromAccountId<Env>>::from_account_id(
*other_contract.as_ref(),
);
let other_contract_call_builder =
<OtherContractCallBuilder as FromAccountId<Env>>::from_account_id(
*other_contract.as_ref(),
);

Self { other_contract_call_builder }
Self {
other_contract_call_builder,
}
}

/// Using the `ContractRef` we can call all the messages of the `OtherContract` as
Expand All @@ -45,14 +51,11 @@ mod cross_contract_calls {
pub fn flip_and_get(&mut self) -> bool {
self.other_contract_call_builder
.flip()
// .v2()
// .weight_limit(0, 0)
.v2()
.weight_limit(0, 0)
.invoke();

self.other_contract_call_builder
.get()
// .v2()
.invoke()
self.other_contract_call_builder.get().v2().invoke()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#![cfg_attr(not(feature = "std"), no_std, no_main)]

pub use self::other_contract::{OtherContract, OtherContractRef};
pub use self::other_contract::{
OtherContract,
OtherContractRef,
};

#[ink::contract]
mod other_contract {
Expand Down