diff --git a/crates/env/src/call/call_builder.rs b/crates/env/src/call/call_builder.rs index 0afb7b9aed..f9149fe5ea 100644 --- a/crates/env/src/call/call_builder.rs +++ b/crates/env/src/call/call_builder.rs @@ -160,7 +160,11 @@ where /// # type AccountId = ::AccountId; /// # type Balance = ::Balance; /// build_call::() -/// .set_call_type(Call::new().callee(AccountId::from([0x42; 32])).gas_limit(5000).transferred_value(10)) +/// .call_type( +/// Call::new() +/// .callee(AccountId::from([0x42; 32])) +/// .gas_limit(5000) +/// .transferred_value(10)) /// .exec_input( /// ExecutionInput::new(Selector::new([0xDE, 0xAD, 0xBE, 0xEF])) /// .push_arg(42u8) @@ -193,10 +197,10 @@ where /// # }; /// # type AccountId = ::AccountId; /// let my_return_value: i32 = build_call::() -/// .set_call_type(Call::new() +/// .call_type(Call::new() /// .callee(AccountId::from([0x42; 32])) -/// .gas_limit(5000) -/// .transferred_value(10)) +/// .gas_limit(5000)) +/// .transferred_value(10) /// .exec_input( /// ExecutionInput::new(Selector::new([0xDE, 0xAD, 0xBE, 0xEF])) /// .push_arg(42u8) @@ -223,7 +227,7 @@ where /// # }; /// # type AccountId = ::AccountId; /// let my_return_value: i32 = build_call::() -/// .set_call_type(DelegateCall::new() +/// .call_type(DelegateCall::new() /// .code_hash(::Hash::clear())) /// .exec_input( /// ExecutionInput::new(Selector::new([0xDE, 0xAD, 0xBE, 0xEF])) @@ -358,7 +362,7 @@ where /// The type of the call. #[inline] #[must_use] - pub fn set_call_type( + pub fn call_type( self, call_type: NewCallType, ) -> CallBuilder, Args, RetType> { @@ -435,6 +439,75 @@ where } } +impl CallBuilder>, Args, RetType> +where + E: Environment, +{ + /// Sets the `callee` for the current cross-contract call. + pub fn callee(self, callee: E::AccountId) -> Self { + let call_type = self.call_type.value(); + CallBuilder { + call_type: Set(Call { + callee, + gas_limit: call_type.gas_limit, + transferred_value: call_type.transferred_value, + }), + call_flags: self.call_flags, + exec_input: self.exec_input, + return_type: self.return_type, + _phantom: Default::default(), + } + } + + /// 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(Call { + callee: call_type.callee, + gas_limit, + transferred_value: call_type.transferred_value, + }), + call_flags: self.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(Call { + callee: call_type.callee, + gas_limit: call_type.gas_limit, + transferred_value, + }), + call_flags: self.call_flags, + exec_input: self.exec_input, + return_type: self.return_type, + _phantom: Default::default(), + } + } +} + +impl CallBuilder>, Args, RetType> +where + E: Environment, +{ + /// Sets the `code_hash` to perform a delegate call with. + pub fn code_hash(self, code_hash: E::Hash) -> Self { + CallBuilder { + call_type: Set(DelegateCall { code_hash }), + call_flags: self.call_flags, + exec_input: self.exec_input, + return_type: self.return_type, + _phantom: Default::default(), + } + } +} + impl CallBuilder>, Set>, Set>> where diff --git a/crates/lang/codegen/src/generator/as_dependency/call_builder.rs b/crates/lang/codegen/src/generator/as_dependency/call_builder.rs index 2795b819f6..074b7c6684 100644 --- a/crates/lang/codegen/src/generator/as_dependency/call_builder.rs +++ b/crates/lang/codegen/src/generator/as_dependency/call_builder.rs @@ -392,7 +392,7 @@ impl CallBuilder<'_> { #( , #input_bindings : #input_types )* ) -> #output_type { ::ink_env::call::build_call::() - .set_call_type(::ink_env::call::Call::new().callee(::ink_lang::ToAccountId::to_account_id(self))) + .call_type(::ink_env::call::Call::new().callee(::ink_lang::ToAccountId::to_account_id(self))) .exec_input( ::ink_env::call::ExecutionInput::new( ::ink_env::call::Selector::new([ #( #selector_bytes ),* ]) diff --git a/crates/lang/codegen/src/generator/trait_def/call_builder.rs b/crates/lang/codegen/src/generator/trait_def/call_builder.rs index 3da29dd370..29d8b86917 100644 --- a/crates/lang/codegen/src/generator/trait_def/call_builder.rs +++ b/crates/lang/codegen/src/generator/trait_def/call_builder.rs @@ -388,7 +388,7 @@ impl CallBuilder<'_> { #( , #input_bindings : #input_types )* ) -> Self::#output_ident { ::ink_env::call::build_call::() - .set_call_type(::ink_env::call::Call::new().callee(::ink_lang::ToAccountId::to_account_id(self))) + .call_type(::ink_env::call::Call::new().callee(::ink_lang::ToAccountId::to_account_id(self))) .exec_input( ::ink_env::call::ExecutionInput::new( ::ink_env::call::Selector::new([ #( #selector_bytes ),* ]) diff --git a/crates/lang/src/env_access.rs b/crates/lang/src/env_access.rs index 8fb6be6a2e..62236bb252 100644 --- a/crates/lang/src/env_access.rs +++ b/crates/lang/src/env_access.rs @@ -532,7 +532,7 @@ where /// #[ink(message)] /// pub fn invoke_contract(&self) -> i32 { /// let call_params = build_call::() - /// .set_call_type( + /// .call_type( /// Call::new() /// .callee(AccountId::from([0x42; 32])) /// .gas_limit(5000) @@ -594,7 +594,7 @@ where /// #[ink(message)] /// pub fn invoke_contract_delegate(&self) -> i32 { /// let call_params = build_call::() - /// .set_call_type( + /// .call_type( /// DelegateCall::new() /// .code_hash(::Hash::clear())) /// .exec_input( diff --git a/examples/erc1155/lib.rs b/examples/erc1155/lib.rs index b539de8e38..3bc9d1d062 100644 --- a/examples/erc1155/lib.rs +++ b/examples/erc1155/lib.rs @@ -395,7 +395,7 @@ mod erc1155 { // If our recipient is a smart contract we need to see if they accept or // reject this transfer. If they reject it we need to revert the call. let params = build_call::() - .set_call_type(Call::new().callee(to).gas_limit(5000)) + .call_type(Call::new().callee(to).gas_limit(5000)) .exec_input( ExecutionInput::new(Selector::new(ON_ERC_1155_RECEIVED_SELECTOR)) .push_arg(caller) diff --git a/examples/multisig/lib.rs b/examples/multisig/lib.rs index dacade479c..665280ccb8 100755 --- a/examples/multisig/lib.rs +++ b/examples/multisig/lib.rs @@ -516,7 +516,7 @@ mod multisig { let t = self.take_transaction(trans_id).expect(WRONG_TRANSACTION_ID); assert!(self.env().transferred_value() == t.transferred_value); let result = build_call::<::Env>() - .set_call_type( + .call_type( Call::new() .callee(t.callee) .gas_limit(t.gas_limit) @@ -548,7 +548,7 @@ mod multisig { self.ensure_confirmed(trans_id); let t = self.take_transaction(trans_id).expect(WRONG_TRANSACTION_ID); let result = build_call::<::Env>() - .set_call_type( + .call_type( Call::new() .callee(t.callee) .gas_limit(t.gas_limit) diff --git a/examples/proxy/lib.rs b/examples/proxy/lib.rs index 34917ab5fe..cb2cfcddb0 100644 --- a/examples/proxy/lib.rs +++ b/examples/proxy/lib.rs @@ -72,7 +72,7 @@ pub mod proxy { #[ink(message, payable, selector = _)] pub fn forward(&self) -> u32 { ink_env::call::build_call::() - .set_call_type( + .call_type( Call::new() .callee(self.forward_to) .transferred_value(self.env().transferred_value()) diff --git a/examples/upgradeable-contract/lib.rs b/examples/upgradeable-contract/lib.rs index cb08940565..d4eb29d686 100644 --- a/examples/upgradeable-contract/lib.rs +++ b/examples/upgradeable-contract/lib.rs @@ -123,7 +123,7 @@ pub mod upgradeable_contract { #[ink(message, payable, selector = _)] pub fn forward(&self) -> u32 { ink_env::call::build_call::() - .set_call_type(DelegateCall::new().code_hash(self.proxy.forward_to)) + .call_type(DelegateCall::new().code_hash(self.proxy.forward_to)) .call_flags( ink_env::CallFlags::default() // We don't plan to use the input data after the delegated call, so the