pub fn expand_function(
    function: &Function,
    abi_parser: &ABIParser,
    custom_enums: &HashMap<String, Property>,
    custom_structs: &HashMap<String, Property>,
) -> Result<TokenStream, Error> {
    let name = safe_ident(&function.name);
    let fn_signature = abi_parser.build_fn_selector(&function.name, &function.inputs);

    let encoded = ABIEncoder::encode_function_selector(fn_signature?.as_bytes());

    let tokenized_signature = expand_selector(encoded);
    let tokenized_output = expand_fn_outputs(&function.outputs)?;
    let result = quote! { ContractCall<#tokenized_output> };

    let (input, arg) = expand_function_arguments(function, custom_enums, custom_structs)?;

    let doc = expand_doc(&format!(
        "Calls the contract's `{}` (0x{}) function",
        function.name,
        hex::encode(encoded)
    ));

    // Here we turn `ParamType`s into a custom stringified version that's identical
    // to how we would declare a `ParamType` in Rust code. Which will then
    // be used to be tokenized and passed onto `method_hash()`.
    let mut output_params = vec![];
    for output in &function.outputs {
        let mut param_type_str: String = "ParamType::".to_owned();
        let p = parse_param(output).unwrap();
        param_type_str.push_str(&p.to_string());

        let tok: proc_macro2::TokenStream = param_type_str.parse().unwrap();

        output_params.push(tok);
    }

    let output_params_token = quote! { &[#( #output_params ),*] };

    Ok(quote! {
        #doc
        pub fn #name(&self #input) -> #result {
            Contract::method_hash(&self.fuel_client, &self.compiled,
                #tokenized_signature, #output_params_token, #arg).expect("method not found (this should never happen)")
        }
    })
}
/// Transforms a function defined in [`Function`] into a [`TokenStream`]
/// that represents that same function signature as a Rust-native function
/// declaration.
/// The actual logic inside the function is the function `method_hash` under
/// [`Contract`], which is responsible for encoding the function selector
/// and the function parameters that will be used in the actual contract call.
///
/// [`Contract`]: crate::contract::Contract
Transforms a function defined in [`Function`] into a [`TokenStream`]
that represents that same function signature as a Rust-native function
declaration.
The actual logic inside the function is the function `method_hash` under
[`Contract`], which is responsible for encoding the function selector
and the function parameters that will be used in the actual contract call.


Transforms a function defined in [ ` Function ` ] into a [ ` TokenStream ` ] that represents that same function signature as a Rust - native function declaration . The actual logic inside the function is the function ` method_hash ` under [ ` Contract ` ] which is responsible for encoding the function selector and the function parameters that will be used in the actual contract call .
pub fn expand_function(
    function: &Function,
    abi_parser: &ABIParser,
    custom_enums: &HashMap<String, Property>,
    custom_structs: &HashMap<String, Property>,
) -> Result<TokenStream, Error> {
    let name = safe_ident(&function.name);
    let fn_signature = abi_parser.build_fn_selector(&function.name, &function.inputs);
    let encoded = ABIEncoder::encode_function_selector(fn_signature?.as_bytes());
    let tokenized_signature = expand_selector(encoded);
    let tokenized_output = expand_fn_outputs(&function.outputs)?;
    let result = quote! { ContractCall<#tokenized_output> };
    let (input, arg) = expand_function_arguments(function, custom_enums, custom_structs)?;
    let doc = expand_doc(&format!(
        "Calls the contract's `{}` (0x{}) function",
        function.name,
        hex::encode(encoded)
    ));
    // Here we turn `ParamType`s into a custom stringified version that's identical
    // to how we would declare a `ParamType` in Rust code. Which will then
    // be used to be tokenized and passed onto `method_hash()`.
    let mut output_params = vec![];
    for output in &function.outputs {
        let mut param_type_str: String = "ParamType::".to_owned();
        let p = parse_param(output).unwrap();
        param_type_str.push_str(&p.to_string());
        let tok: proc_macro2::TokenStream = param_type_str.parse().unwrap();
        output_params.push(tok);
    }
    let output_params_token = quote! { &[#( #output_params ),*] };
    Ok(quote! {
        #doc
        pub fn #name(&self #input) -> #result {
            Contract::method_hash(&self.fuel_client, &self.compiled,
                #tokenized_signature, #output_params_token, #arg).expect("method not found (this should never happen)")
        }
    })
}
pub fn expand_function ( function : & Function , abi_parser : & ABIParser , custom_enums : & HashMap < String , Property > , custom_structs : & HashMap < String , Property > , ) -> Result < TokenStream , Error > { let name = safe_ident ( & function . name ) ; let fn_signature = abi_parser . build_fn_selector ( & function . name , & function . inputs ) ; let encoded = ABIEncoder :: encode_function_selector ( fn_signature ? . as_bytes ( ) ) ; let tokenized_signature = expand_selector ( encoded ) ; let tokenized_output = expand_fn_outputs ( & function . outputs ) ? ; let result = quote ! { ContractCall tokenized_output } ; let ( input , arg ) = expand_function_arguments ( function , custom_enums , custom_structs ) ? ; let doc = expand_doc ( & format ! ( " " function name hex encode ( encoded ) ) ) ; // Here we turn `ParamType`s into a custom stringified version that's identical // to how we would declare a `ParamType` in Rust code. Which will then // be used to be tokenized and passed onto `method_hash()`. let mut output_params = vec ! [ ] ; for output in & function . outputs { let mut param_type_str : String = " " . to_owned ( ) ; let p = parse_param ( output ) . unwrap ( ) ; param_type_str . push_str ( & p . to_string ( ) ) ; let tok : proc_macro2 :: TokenStream = param_type_str . parse ( ) . unwrap ( ) ; output_params . push ( tok ) ; } let output_params_token = quote ! { [ ( output_params ) ] } ; Ok ( quote ! { doc pub fn name ( self input ) result { Contract method_hash ( self fuel_client self compiled tokenized_signature output_params_token arg ) expect ( " " ) } } ) }
Transforms a function defined in [`Function`] into a [`TokenStream`]
that represents that same function signature as a Rust-native function
declaration.
Transforms a function defined in [ ` Function ` ] into a [ ` TokenStream ` ] that represents that same function signature as a Rust - native function declaration .
function
&Function
abi_parser
&ABIParser
custom_enums
&HashMap<String, Property>
custom_structs
&HashMap<String, Property>