fn create_method_decl(&mut self, mut method: TraitItemMethod, context: TokenStream) -> TraitItemMethod {
		let params = match extract_parameter_names_types_and_borrows(&method.sig.decl) {
			Ok(res) => res.into_iter().map(|v| v.0).collect::<Vec<_>>(),
			Err(e) => {
				self.errors.push(e.to_compile_error());
				Vec::new()
			}
		};
		let params2 = params.clone();
		let ret_type = return_type_extract_type(&method.sig.decl.output);

		method.sig.decl = fold_fn_decl_for_client_side(
			method.sig.decl.clone(),
			&self.block_id,
			&self.crate_
		);
		let name_impl = generate_method_runtime_api_impl_name(&self.trait_, &method.sig.ident);
		let crate_ = self.crate_;

		let found_attributes = remove_supported_attributes(&mut method.attrs);
		// If the method has a `changed_in` attribute, we need to alter the method name to
		// `method_before_version_VERSION`.
		let (native_handling, param_tuple) = match get_changed_in(&found_attributes) {
			Ok(Some(version)) => {
				// Make sure that the `changed_in` version is at least the current `api_version`.
				if get_api_version(&self.found_attributes).ok() < Some(version) {
					self.errors.push(
						Error::new(
							method.span(),
							"`changed_in` version can not be greater than the `api_version`",
						).to_compile_error()
					);
				}

				let ident = Ident::new(
					&format!("{}_before_version_{}", method.sig.ident, version),
					method.sig.ident.span()
				);
				method.sig.ident = ident;
				method.attrs.push(parse_quote!( #[deprecated] ));

				let panic = format!("Calling `{}` should not return a native value!", method.sig.ident);
				(quote!( panic!(#panic) ), quote!( None ))
			},
			Ok(None) => (quote!( Ok(n) ), quote!( Some(( #( #params2 ),* )) )),
			Err(e) => {
				self.errors.push(e.to_compile_error());
				(quote!( unimplemented!() ), quote!( None ))
			}
		};

		let function_name = method.sig.ident.to_string();

		// Generate the default implementation that calls the `method_runtime_api_impl` method.
		method.default = Some(
			parse_quote! {
				{
					let runtime_api_impl_params_encoded =
						#crate_::runtime_api::Encode::encode(&( #( &#params ),* ));

					self.#name_impl(at, #context, #param_tuple, runtime_api_impl_params_encoded)
						.and_then(|r|
							match r {
								#crate_::runtime_api::NativeOrEncoded::Native(n) => {
									#native_handling
								},
								#crate_::runtime_api::NativeOrEncoded::Encoded(r) => {
									<#ret_type as #crate_::runtime_api::Decode>::decode(&mut &r[..])
										.ok_or_else(||
											#crate_::error::ErrorKind::CallResultDecode(
												#function_name
											).into()
										)
								}
							}
						)
				}
			}
		);

		method
	}
/// Takes the method declared by the user and creates the declaration we require for the runtime
/// api client side. This method will call by default the `method_runtime_api_impl` for doing
/// the actual call into the runtime.
Takes the method declared by the user and creates the declaration we require for the runtime
api client side. This method will call by default the `method_runtime_api_impl` for doing
the actual call into the runtime.
Takes the method declared by the user and creates the declaration we require for the runtime api client side . This method will call by default the ` method_runtime_api_impl ` for doing the actual call into the runtime .
fn create_method_decl(&mut self, mut method: TraitItemMethod, context: TokenStream) -> TraitItemMethod {
		let params = match extract_parameter_names_types_and_borrows(&method.sig.decl) {
			Ok(res) => res.into_iter().map(|v| v.0).collect::<Vec<_>>(),
			Err(e) => {
				self.errors.push(e.to_compile_error());
				Vec::new()
			}
		};
		let params2 = params.clone();
		let ret_type = return_type_extract_type(&method.sig.decl.output);
		method.sig.decl = fold_fn_decl_for_client_side(
			method.sig.decl.clone(),
			&self.block_id,
			&self.crate_
		);
		let name_impl = generate_method_runtime_api_impl_name(&self.trait_, &method.sig.ident);
		let crate_ = self.crate_;
		let found_attributes = remove_supported_attributes(&mut method.attrs);
		// If the method has a `changed_in` attribute, we need to alter the method name to
		// `method_before_version_VERSION`.
		let (native_handling, param_tuple) = match get_changed_in(&found_attributes) {
			Ok(Some(version)) => {
				// Make sure that the `changed_in` version is at least the current `api_version`.
				if get_api_version(&self.found_attributes).ok() < Some(version) {
					self.errors.push(
						Error::new(
							method.span(),
							"`changed_in` version can not be greater than the `api_version`",
						).to_compile_error()
					);
				}
				let ident = Ident::new(
					&format!("{}_before_version_{}", method.sig.ident, version),
					method.sig.ident.span()
				);
				method.sig.ident = ident;
				method.attrs.push(parse_quote!( #[deprecated] ));
				let panic = format!("Calling `{}` should not return a native value!", method.sig.ident);
				(quote!( panic!(#panic) ), quote!( None ))
			},
			Ok(None) => (quote!( Ok(n) ), quote!( Some(( #( #params2 ),* )) )),
			Err(e) => {
				self.errors.push(e.to_compile_error());
				(quote!( unimplemented!() ), quote!( None ))
			}
		};
		let function_name = method.sig.ident.to_string();
		// Generate the default implementation that calls the `method_runtime_api_impl` method.
		method.default = Some(
			parse_quote! {
				{
					let runtime_api_impl_params_encoded =
						#crate_::runtime_api::Encode::encode(&( #( &#params ),* ));
					self.#name_impl(at, #context, #param_tuple, runtime_api_impl_params_encoded)
						.and_then(|r|
							match r {
								#crate_::runtime_api::NativeOrEncoded::Native(n) => {
									#native_handling
								},
								#crate_::runtime_api::NativeOrEncoded::Encoded(r) => {
									<#ret_type as #crate_::runtime_api::Decode>::decode(&mut &r[..])
										.ok_or_else(||
											#crate_::error::ErrorKind::CallResultDecode(
												#function_name
											).into()
										)
								}
							}
						)
				}
			}
		);
		method
	}
fn create_method_decl ( & mut self , mut method : TraitItemMethod , context : TokenStream ) -> TraitItemMethod { let params = match extract_parameter_names_types_and_borrows ( & method . sig . decl ) { Ok ( res ) => res . into_iter ( ) . map ( | v | v . 0 ) . collect :: < Vec < _ > > ( ) , Err ( e ) => { self . errors . push ( e . to_compile_error ( ) ) ; Vec :: new ( ) } } ; let params2 = params . clone ( ) ; let ret_type = return_type_extract_type ( & method . sig . decl . output ) ; method . sig . decl = fold_fn_decl_for_client_side ( method . sig . decl . clone ( ) , & self . block_id , & self . crate_ ) ; let name_impl = generate_method_runtime_api_impl_name ( & self . trait_ , & method . sig . ident ) ; let crate_ = self . crate_ ; let found_attributes = remove_supported_attributes ( & mut method . attrs ) ; // If the method has a `changed_in` attribute, we need to alter the method name to // `method_before_version_VERSION`. let ( native_handling , param_tuple ) = match get_changed_in ( & found_attributes ) { Ok ( Some ( version ) ) => { // Make sure that the `changed_in` version is at least the current `api_version`. if get_api_version ( & self . found_attributes ) . ok ( ) < Some ( version ) { self . errors . push ( Error :: new ( method . span ( ) , " " , ) . to_compile_error ( ) ) ; } let ident = Ident :: new ( & format ! ( " " method sig ident version ) , method . sig . ident . span ( ) ) ; method . sig . ident = ident ; method . attrs . push ( parse_quote ! ( [ deprecated ] ) ) ; let panic = format ! ( " " method sig ident ) ; ( quote ! ( panic ( panic ) ) , quote ! ( None ) ) } , Ok ( None ) => ( quote ! ( Ok ( n ) ) , quote ! ( Some ( ( ( params2 ) ) ) ) ) , Err ( e ) => { self . errors . push ( e . to_compile_error ( ) ) ; ( quote ! ( unimplemented ( ) ) , quote ! ( None ) ) } } ; let function_name = method . sig . ident . to_string ( ) ; // Generate the default implementation that calls the `method_runtime_api_impl` method. method . default = Some ( parse_quote ! { { let runtime_api_impl_params_encoded crate_ runtime_api Encode encode ( ( ( params ) ) ) self name_impl ( at context param_tuple runtime_api_impl_params_encoded ) and_then ( r match r { crate_ runtime_api NativeOrEncoded Native ( n ) { native_handling } crate_ runtime_api NativeOrEncoded Encoded ( r ) { ret_type as crate_ runtime_api Decode decode ( mut r [ ] ) ok_or_else ( crate_ error ErrorKind CallResultDecode ( function_name ) into ( ) ) } } ) } } ) ; method }
Takes the method declared by the user and creates the declaration we require for the runtime
api client side.
Takes the method declared by the user and creates the declaration we require for the runtime api client side .
&mut self
method
TraitItemMethod
context
TokenStream
&mut self
method
TraitItemMethod
context
TokenStream