@@ -28,7 +28,6 @@ use crate::{
2828 Error ,
2929} ;
3030use core:: marker:: PhantomData ;
31- use ink_primitives:: Clear ;
3231use num_traits:: Zero ;
3332
3433/// The final parameters to the cross-contract call.
7170 E : Environment ,
7271{
7372 /// Returns the account ID of the called contract instance.
74- ///
75- /// Returns `None` if no account ID has been set for the call.
7673 #[ inline]
77- pub fn callee ( & self ) -> & Option < E :: AccountId > {
74+ pub fn callee ( & self ) -> & E :: AccountId {
7875 & self . call_type . callee
7976 }
8077
@@ -205,11 +202,9 @@ where
205202/// # type AccountId = <DefaultEnvironment as Environment>::AccountId;
206203/// # type Balance = <DefaultEnvironment as Environment>::Balance;
207204/// build_call::<DefaultEnvironment>()
208- /// .call_type(
209- /// Call::new()
210- /// .callee(AccountId::from([0x42; 32]))
211- /// .gas_limit(5000)
212- /// .transferred_value(10))
205+ /// .call(AccountId::from([0x42; 32]))
206+ /// .gas_limit(5000)
207+ /// .transferred_value(10)
213208/// .exec_input(
214209/// ExecutionInput::new(Selector::new([0xDE, 0xAD, 0xBE, 0xEF]))
215210/// .push_arg(42u8)
@@ -241,9 +236,8 @@ where
241236/// # };
242237/// # type AccountId = <DefaultEnvironment as Environment>::AccountId;
243238/// let my_return_value: i32 = build_call::<DefaultEnvironment>()
244- /// .call_type(Call::new()
245- /// .callee(AccountId::from([0x42; 32]))
246- /// .gas_limit(5000))
239+ /// .call_type(Call::new(AccountId::from([0x42; 32])))
240+ /// .gas_limit(5000)
247241/// .transferred_value(10)
248242/// .exec_input(
249243/// ExecutionInput::new(Selector::new([0xDE, 0xAD, 0xBE, 0xEF]))
@@ -270,8 +264,7 @@ where
270264/// # use ink_primitives::Clear;
271265/// # type AccountId = <DefaultEnvironment as Environment>::AccountId;
272266/// let my_return_value: i32 = build_call::<DefaultEnvironment>()
273- /// .call_type(DelegateCall::new()
274- /// .code_hash(<DefaultEnvironment as Environment>::Hash::CLEAR_HASH))
267+ /// .delegate(<DefaultEnvironment as Environment>::Hash::CLEAR_HASH)
275268/// .exec_input(
276269/// ExecutionInput::new(Selector::new([0xDE, 0xAD, 0xBE, 0xEF]))
277270/// .push_arg(42u8)
@@ -306,12 +299,9 @@ where
306299/// # type AccountId = <DefaultEnvironment as Environment>::AccountId;
307300/// # type Balance = <DefaultEnvironment as Environment>::Balance;
308301/// let call_result = build_call::<DefaultEnvironment>()
309- /// .call_type(
310- /// Call::new()
311- /// .callee(AccountId::from([0x42; 32]))
312- /// .gas_limit(5000)
313- /// .transferred_value(10),
314- /// )
302+ /// .call(AccountId::from([0x42; 32]))
303+ /// .gas_limit(5000)
304+ /// .transferred_value(10)
315305/// .try_invoke()
316306/// .expect("Got an error from the Contract's pallet.");
317307///
@@ -343,41 +333,26 @@ where
343333/// The default call type for cross-contract calls. Performs a cross-contract call to `callee`
344334/// with gas limit `gas_limit`, transferring `transferred_value` of currency.
345335pub struct Call < E : Environment > {
346- callee : Option < E :: AccountId > ,
336+ callee : E :: AccountId ,
347337 gas_limit : Gas ,
348338 transferred_value : E :: Balance ,
349339}
350340
351- impl < E : Environment > Default for Call < E > {
352- fn default ( ) -> Self {
353- Call {
354- callee : Default :: default ( ) ,
341+ impl < E : Environment > Call < E > {
342+ /// Returns a clean builder for [`Call`].
343+ pub fn new ( callee : E :: AccountId ) -> Self {
344+ Self {
345+ callee,
355346 gas_limit : Default :: default ( ) ,
356347 transferred_value : E :: Balance :: zero ( ) ,
357348 }
358349 }
359350}
360351
361- impl < E : Environment > Call < E > {
362- /// Returns a clean builder for [`Call`].
363- pub fn new ( ) -> Self {
364- Default :: default ( )
365- }
366- }
367-
368352impl < E > Call < E >
369353where
370354 E : Environment ,
371355{
372- /// Sets the `callee` for the current cross-contract call.
373- pub fn callee ( self , callee : E :: AccountId ) -> Self {
374- Call {
375- callee : Some ( callee) ,
376- gas_limit : self . gas_limit ,
377- transferred_value : self . transferred_value ,
378- }
379- }
380-
381356 /// Sets the `gas_limit` for the current cross-contract call.
382357 pub fn gas_limit ( self , gas_limit : Gas ) -> Self {
383358 Call {
@@ -404,16 +379,8 @@ pub struct DelegateCall<E: Environment> {
404379
405380impl < E : Environment > DelegateCall < E > {
406381 /// Returns a clean builder for [`DelegateCall`]
407- pub const fn new ( ) -> Self {
408- DelegateCall {
409- code_hash : E :: Hash :: CLEAR_HASH ,
410- }
411- }
412- }
413-
414- impl < E : Environment > Default for DelegateCall < E > {
415- fn default ( ) -> Self {
416- Self :: new ( )
382+ pub const fn new ( code_hash : E :: Hash ) -> Self {
383+ DelegateCall { code_hash }
417384 }
418385}
419386
@@ -521,26 +488,43 @@ where
521488 }
522489}
523490
524- impl < E , Args , RetType > CallBuilder < E , Set < Call < E > > , Args , RetType >
491+ impl < E , CallType , Args , RetType > CallBuilder < E , Unset < CallType > , Args , RetType >
525492where
526493 E : Environment ,
527494{
528- /// Sets the `callee` for the current cross-contract call.
529- pub fn callee ( self , callee : E :: AccountId ) -> Self {
530- let call_type = self . call_type . value ( ) ;
495+ /// Prepares the `CallBuilder` for a cross-contract [`Call`].
496+ pub fn call (
497+ self ,
498+ callee : E :: AccountId ,
499+ ) -> CallBuilder < E , Set < Call < E > > , Args , RetType > {
531500 CallBuilder {
532- call_type : Set ( Call {
533- callee : Some ( callee) ,
534- gas_limit : call_type. gas_limit ,
535- transferred_value : call_type. transferred_value ,
536- } ) ,
501+ call_type : Set ( Call :: new ( callee) ) ,
502+ call_flags : self . call_flags ,
503+ exec_input : self . exec_input ,
504+ return_type : self . return_type ,
505+ _phantom : Default :: default ( ) ,
506+ }
507+ }
508+
509+ /// Prepares the `CallBuilder` for a cross-contract [`DelegateCall`].
510+ pub fn delegate (
511+ self ,
512+ code_hash : E :: Hash ,
513+ ) -> CallBuilder < E , Set < DelegateCall < E > > , Args , RetType > {
514+ CallBuilder {
515+ call_type : Set ( DelegateCall :: new ( code_hash) ) ,
537516 call_flags : self . call_flags ,
538517 exec_input : self . exec_input ,
539518 return_type : self . return_type ,
540519 _phantom : Default :: default ( ) ,
541520 }
542521 }
522+ }
543523
524+ impl < E , Args , RetType > CallBuilder < E , Set < Call < E > > , Args , RetType >
525+ where
526+ E : Environment ,
527+ {
544528 /// Sets the `gas_limit` for the current cross-contract call.
545529 pub fn gas_limit ( self , gas_limit : Gas ) -> Self {
546530 let call_type = self . call_type . value ( ) ;
0 commit comments