mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 19:47:59 +00:00
Composite accounts (#4820)
* Basic account composition. * Add try_mutate_exists * De-duplicate * Refactor away the UpdateBalanceOutcome * Expunge final UpdateBalanceOutcome refs * Refactor transfer * Refactor reservable currency stuff. * Test with the alternative setup. * Fixes * Test with both setups. * Fixes * Fix * Fix macros * Make indices opt-in * Remove CreationFee, and make indices opt-in. * Fix construct_runtime * Fix last few bits * Fix tests * Update trait impls * Don't hardcode the system event * Make tests build and fix some stuff. * Pointlessly bump runtime version * Fix benchmark * Another fix * Whitespace * Make indices module economically safe * Migrations for indices. * Fix * Whilespace * Trim defunct migrations * Remove unused storage item * More contains_key fixes * Docs. * Bump runtime * Remove unneeded code * Fix test * Fix test * Update frame/balances/src/lib.rs Co-Authored-By: Shawn Tabrizi <shawntabrizi@gmail.com> * Fix ED logic * Repatriate reserved logic * Typo * Fix typo * Update frame/system/src/lib.rs Co-Authored-By: Shawn Tabrizi <shawntabrizi@gmail.com> * Update frame/system/src/lib.rs Co-Authored-By: Shawn Tabrizi <shawntabrizi@gmail.com> * Last few fixes * Another fix * Build fix Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> Co-authored-by: Jaco Greeff <jacogr@gmail.com> Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
@@ -20,7 +20,7 @@ use frame_support_procedural_tools::syn_ext as ext;
|
||||
use frame_support_procedural_tools::{generate_crate_access, generate_hidden_includes};
|
||||
use parse::{ModuleDeclaration, RuntimeDefinition, WhereSection};
|
||||
use proc_macro::TokenStream;
|
||||
use proc_macro2::{Span, TokenStream as TokenStream2};
|
||||
use proc_macro2::TokenStream as TokenStream2;
|
||||
use quote::quote;
|
||||
use syn::{Ident, Result, TypePath};
|
||||
|
||||
@@ -58,7 +58,7 @@ fn construct_runtime_parsed(definition: RuntimeDefinition) -> Result<TokenStream
|
||||
return Err(syn::Error::new(
|
||||
modules_token.span,
|
||||
"`System` module declaration is missing. \
|
||||
Please add this line: `System: system::{Module, Call, Storage, Config, Event},`",
|
||||
Please add this line: `System: system::{Module, Call, Storage, Config, Event<T>},`",
|
||||
))
|
||||
}
|
||||
};
|
||||
@@ -68,19 +68,17 @@ fn construct_runtime_parsed(definition: RuntimeDefinition) -> Result<TokenStream
|
||||
|
||||
let all_but_system_modules = modules.iter().filter(|module| module.name != SYSTEM_MODULE_NAME);
|
||||
|
||||
let outer_event = decl_outer_event_or_origin(
|
||||
let outer_event = decl_outer_event(
|
||||
&name,
|
||||
all_but_system_modules.clone(),
|
||||
&system_module,
|
||||
modules.iter(),
|
||||
&scrate,
|
||||
DeclOuterKind::Event,
|
||||
)?;
|
||||
let outer_origin = decl_outer_event_or_origin(
|
||||
|
||||
let outer_origin = decl_outer_origin(
|
||||
&name,
|
||||
all_but_system_modules.clone(),
|
||||
&system_module,
|
||||
&scrate,
|
||||
DeclOuterKind::Origin,
|
||||
)?;
|
||||
let all_modules = decl_all_modules(&name, modules.iter());
|
||||
let module_to_index = decl_module_to_index(modules.iter(), modules.len(), &scrate);
|
||||
@@ -264,32 +262,24 @@ fn decl_outer_dispatch<'a>(
|
||||
)
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
||||
enum DeclOuterKind {
|
||||
Event,
|
||||
Origin,
|
||||
}
|
||||
|
||||
fn decl_outer_event_or_origin<'a>(
|
||||
fn decl_outer_origin<'a>(
|
||||
runtime_name: &'a Ident,
|
||||
module_declarations: impl Iterator<Item = &'a ModuleDeclaration>,
|
||||
system_name: &'a Ident,
|
||||
scrate: &'a TokenStream2,
|
||||
kind: DeclOuterKind,
|
||||
) -> syn::Result<TokenStream2> {
|
||||
let mut modules_tokens = TokenStream2::new();
|
||||
let kind_str = format!("{:?}", kind);
|
||||
for module_declaration in module_declarations {
|
||||
match module_declaration.find_part(&kind_str) {
|
||||
match module_declaration.find_part("Origin") {
|
||||
Some(module_entry) => {
|
||||
let module = &module_declaration.module;
|
||||
let instance = module_declaration.instance.as_ref();
|
||||
let generics = &module_entry.generics;
|
||||
if instance.is_some() && generics.params.len() == 0 {
|
||||
let msg = format!(
|
||||
"Instantiable module with no generic `{}` cannot \
|
||||
be constructed: module `{}` must have generic `{}`",
|
||||
kind_str, module_declaration.name, kind_str
|
||||
"Instantiable module with no generic `Origin` cannot \
|
||||
be constructed: module `{}` must have generic `Origin`",
|
||||
module_declaration.name
|
||||
);
|
||||
return Err(syn::Error::new(module_declaration.name.span(), msg));
|
||||
}
|
||||
@@ -299,14 +289,46 @@ fn decl_outer_event_or_origin<'a>(
|
||||
None => {}
|
||||
}
|
||||
}
|
||||
let macro_call = match kind {
|
||||
DeclOuterKind::Event => quote!(#scrate::impl_outer_event!),
|
||||
DeclOuterKind::Origin => quote!(#scrate::impl_outer_origin!),
|
||||
};
|
||||
let enum_name = Ident::new(kind_str.as_str(), Span::call_site());
|
||||
|
||||
Ok(quote!(
|
||||
#macro_call {
|
||||
pub enum #enum_name for #runtime_name where system = #system_name {
|
||||
#scrate::impl_outer_origin! {
|
||||
pub enum Origin for #runtime_name where system = #system_name {
|
||||
#modules_tokens
|
||||
}
|
||||
}
|
||||
))
|
||||
}
|
||||
|
||||
fn decl_outer_event<'a>(
|
||||
runtime_name: &'a Ident,
|
||||
module_declarations: impl Iterator<Item = &'a ModuleDeclaration>,
|
||||
scrate: &'a TokenStream2,
|
||||
) -> syn::Result<TokenStream2> {
|
||||
let mut modules_tokens = TokenStream2::new();
|
||||
for module_declaration in module_declarations {
|
||||
match module_declaration.find_part("Event") {
|
||||
Some(module_entry) => {
|
||||
let module = &module_declaration.module;
|
||||
let instance = module_declaration.instance.as_ref();
|
||||
let generics = &module_entry.generics;
|
||||
if instance.is_some() && generics.params.len() == 0 {
|
||||
let msg = format!(
|
||||
"Instantiable module with no generic `Event` cannot \
|
||||
be constructed: module `{}` must have generic `Event`",
|
||||
module_declaration.name,
|
||||
);
|
||||
return Err(syn::Error::new(module_declaration.name.span(), msg));
|
||||
}
|
||||
let tokens = quote!(#module #instance #generics ,);
|
||||
modules_tokens.extend(tokens);
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(quote!(
|
||||
#scrate::impl_outer_event! {
|
||||
pub enum Event for #runtime_name {
|
||||
#modules_tokens
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user