@@ -28,7 +28,10 @@ use quote::{
2828 quote,
2929 quote_spanned,
3030} ;
31- use syn:: spanned:: Spanned as _;
31+ use syn:: {
32+ parse_quote,
33+ spanned:: Spanned as _,
34+ } ;
3235
3336/// Generates code to generate the metadata of the contract.
3437#[ derive( From ) ]
@@ -96,6 +99,7 @@ impl Metadata<'_> {
9699 :: ink:: LangError
97100 } ;
98101 let error = Self :: generate_type_spec ( & error_ty) ;
102+ let environment = self . generate_environment ( ) ;
99103 quote ! {
100104 :: ink:: metadata:: ContractSpec :: new( )
101105 . constructors( [
@@ -113,6 +117,9 @@ impl Metadata<'_> {
113117 . lang_error(
114118 #error
115119 )
120+ . environment(
121+ #environment
122+ )
116123 . done( )
117124 }
118125 }
@@ -407,6 +414,35 @@ impl Metadata<'_> {
407414 )
408415 } )
409416 }
417+
418+ fn generate_environment ( & self ) -> TokenStream2 {
419+ let span = self . contract . module ( ) . span ( ) ;
420+
421+ let account_id: syn:: Type = parse_quote ! ( AccountId ) ;
422+ let balance: syn:: Type = parse_quote ! ( Balance ) ;
423+ let hash: syn:: Type = parse_quote ! ( Hash ) ;
424+ let timestamp: syn:: Type = parse_quote ! ( Timestamp ) ;
425+ let block_number: syn:: Type = parse_quote ! ( BlockNumber ) ;
426+ let chain_extension: syn:: Type = parse_quote ! ( ChainExtension ) ;
427+
428+ let account_id = Self :: generate_type_spec ( & account_id) ;
429+ let balance = Self :: generate_type_spec ( & balance) ;
430+ let hash = Self :: generate_type_spec ( & hash) ;
431+ let timestamp = Self :: generate_type_spec ( & timestamp) ;
432+ let block_number = Self :: generate_type_spec ( & block_number) ;
433+ let chain_extension = Self :: generate_type_spec ( & chain_extension) ;
434+ quote_spanned ! ( span=>
435+ :: ink:: metadata:: EnvironmentSpec :: new( )
436+ . account_id( #account_id)
437+ . balance( #balance)
438+ . hash( #hash)
439+ . timestamp( #timestamp)
440+ . block_number( #block_number)
441+ . chain_extension( #chain_extension)
442+ . max_event_topics( MAX_EVENT_TOPICS )
443+ . done( )
444+ )
445+ }
410446}
411447
412448#[ cfg( test) ]
0 commit comments