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
+7 -2
View File
@@ -2,7 +2,10 @@
// This file is dual-licensed as Apache-2.0 or GPL-3.0.
// see LICENSE for license details.
use crate::types::TypeGenerator;
use crate::{
types::TypeGenerator,
CratePath,
};
use frame_metadata::PalletMetadata;
use proc_macro2::TokenStream as TokenStream2;
use quote::quote;
@@ -41,6 +44,7 @@ pub fn generate_events(
type_gen: &TypeGenerator,
pallet: &PalletMetadata<PortableForm>,
types_mod_ident: &syn::Ident,
crate_path: &CratePath,
) -> TokenStream2 {
// Early return if the pallet has no events.
let event = if let Some(ref event) = pallet.event {
@@ -54,6 +58,7 @@ pub fn generate_events(
event.ty.id(),
|name| name.into(),
"Event",
crate_path,
);
let event_structs = struct_defs.iter().map(|(variant_name, struct_def)| {
let pallet_name = &pallet.name;
@@ -63,7 +68,7 @@ pub fn generate_events(
quote! {
#struct_def
impl ::subxt::events::StaticEvent for #event_struct {
impl #crate_path::events::StaticEvent for #event_struct {
const PALLET: &'static str = #pallet_name;
const EVENT: &'static str = #event_name;
}