Allow specifying the subxt crate path for generated code (#664)

* Allow specifying the `subxt` crate path for generated code

* Make `clippy` happy

* Add documentation

* Improve optics

* Remove custom crate path test

* Implement comments

* Update comment

* Make `crate_path` property instead of argument

* Remove unnecessary derives

* Remove `Default` impls in favor of explicit constructors

* Remove unnecessary `into`

* Update codegen/src/types/mod.rs

Co-authored-by: Andrew Jones <ascjones@gmail.com>

Co-authored-by: Andrew Jones <ascjones@gmail.com>
This commit is contained in:
Michael Müller
2022-09-27 12:41:36 +02:00
committed by GitHub
parent 75e383dfcf
commit f115ff975c
15 changed files with 342 additions and 146 deletions
+11 -5
View File
@@ -2,9 +2,12 @@
// This file is dual-licensed as Apache-2.0 or GPL-3.0.
// see LICENSE for license details.
use crate::types::{
CompositeDefFields,
TypeGenerator,
use crate::{
types::{
CompositeDefFields,
TypeGenerator,
},
CratePath,
};
use frame_metadata::{
v14::RuntimeMetadataV14,
@@ -36,6 +39,7 @@ pub fn generate_calls(
type_gen: &TypeGenerator,
pallet: &PalletMetadata<PortableForm>,
types_mod_ident: &syn::Ident,
crate_path: &CratePath,
) -> TokenStream2 {
// Early return if the pallet has no calls.
let call = if let Some(ref calls) = pallet.calls {
@@ -49,6 +53,7 @@ pub fn generate_calls(
call.ty.id(),
|name| name.to_upper_camel_case().into(),
"Call",
crate_path,
);
let (call_structs, call_fns): (Vec<_>, Vec<_>) = struct_defs
.iter_mut()
@@ -98,13 +103,14 @@ pub fn generate_calls(
let call_struct = quote! {
#struct_def
};
let client_fn = quote! {
#docs
pub fn #fn_name(
&self,
#( #call_fn_args, )*
) -> ::subxt::tx::StaticTxPayload<#struct_name> {
::subxt::tx::StaticTxPayload::new(
) -> #crate_path::tx::StaticTxPayload<#struct_name> {
#crate_path::tx::StaticTxPayload::new(
#pallet_name,
#call_name,
#struct_name { #( #call_args, )* },