@@ -21,6 +21,7 @@ use ir::{
21
21
use itertools:: Itertools ;
22
22
use proc_macro2:: TokenStream as TokenStream2 ;
23
23
use quote:: {
24
+ format_ident,
24
25
quote,
25
26
quote_spanned,
26
27
} ;
@@ -65,9 +66,14 @@ impl GenerateCode for ContractRef<'_> {
65
66
}
66
67
67
68
impl ContractRef < ' _ > {
69
+ /// Generates the identifier of the contract reference struct.
70
+ fn generate_contract_ref_base_ident ( & self ) -> syn:: Ident {
71
+ format_ident ! ( "{}Ref" , self . contract. module( ) . storage( ) . ident( ) )
72
+ }
73
+
68
74
/// Generates the identifier of the contract reference struct.
69
75
fn generate_contract_ref_ident ( & self ) -> syn:: Ident {
70
- quote :: format_ident!( "{}Ref " , self . contract . module ( ) . storage ( ) . ident ( ) )
76
+ format_ident ! ( "{}For " , self . generate_contract_ref_base_ident ( ) )
71
77
}
72
78
73
79
/// Generates the code for the struct representing the contract reference.
@@ -89,6 +95,18 @@ impl ContractRef<'_> {
89
95
let storage_ident = self . contract . module ( ) . storage ( ) . ident ( ) ;
90
96
let ref_ident = self . generate_contract_ref_ident ( ) ;
91
97
let abi = default_abi ! ( ) ;
98
+ let ref_ident_default_abi = self . generate_contract_ref_base_ident ( ) ;
99
+ let ref_ident_abi_aliases = generate_abi_impls ! ( @type |abi| {
100
+ let ( abi_ty, suffix) = match abi {
101
+ Abi :: Ink => ( quote!( :: ink:: abi:: Ink ) , "Ink" ) ,
102
+ Abi :: Sol => ( quote!( :: ink:: abi:: Sol ) , "Sol" ) ,
103
+ } ;
104
+ let ref_ident_abi_alias = format_ident!( "{ref_ident_default_abi}{suffix}" ) ;
105
+ quote! {
106
+ #[ allow( dead_code) ]
107
+ pub type #ref_ident_abi_alias = #ref_ident:: <#abi_ty>;
108
+ }
109
+ } ) ;
92
110
let sol_codec = if cfg ! ( any( ink_abi = "sol" , ink_abi = "all" ) ) {
93
111
// These manual implementations are a bit more efficient than the derived
94
112
// equivalents.
@@ -132,6 +150,12 @@ impl ContractRef<'_> {
132
150
_marker: core:: marker:: PhantomData <Abi >,
133
151
}
134
152
153
+ // Default type alias (i.e. `ContractRef` for a contract named `Contract`).
154
+ #[ allow( dead_code) ]
155
+ pub type #ref_ident_default_abi = #ref_ident:: <#abi>;
156
+ // ABI specific type aliases (i.e. `ContractRefInk` and `ContractRefSol`) as appropriate.
157
+ #ref_ident_abi_aliases
158
+
135
159
const _: ( ) = {
136
160
impl :: ink:: env:: ContractReference for #storage_ident {
137
161
type Type = #ref_ident;
@@ -585,7 +609,7 @@ impl ContractRef<'_> {
585
609
. map ( quote:: ToTokens :: to_token_stream)
586
610
. unwrap_or_else ( || quote:: quote! { Self } ) ;
587
611
588
- let ( abi_ty, exec_input_init) = match abi {
612
+ let ( abi_ty, exec_input_init, build_create_fn ) = match abi {
589
613
Abi :: Ink => {
590
614
let selector_bytes = constructor. composed_selector ( ) . hex_lits ( ) ;
591
615
(
@@ -595,6 +619,7 @@ impl ContractRef<'_> {
595
619
:: ink:: env:: call:: Selector :: new( [ #( #selector_bytes ) , * ] )
596
620
)
597
621
} ,
622
+ quote ! ( build_create_ink) ,
598
623
)
599
624
}
600
625
Abi :: Sol => {
@@ -603,6 +628,7 @@ impl ContractRef<'_> {
603
628
quote ! {
604
629
:: ink:: env:: call:: ExecutionInput :: no_selector( )
605
630
} ,
631
+ quote ! ( build_create_sol) ,
606
632
)
607
633
}
608
634
} ;
@@ -625,7 +651,7 @@ impl ContractRef<'_> {
625
651
:: ink:: env:: call:: utils:: Set <:: ink:: env:: call:: utils:: ReturnType <#ret_type>>,
626
652
#abi_ty
627
653
> {
628
- :: ink:: env:: call:: build_create_abi :: <Self , #abi_ty >( )
654
+ :: ink:: env:: call:: #build_create_fn :: <Self >( )
629
655
. exec_input(
630
656
#exec_input_init
631
657
#(
0 commit comments