From 1415b6edaa2e48d76ade844ca0b21f36fc70c562 Mon Sep 17 00:00:00 2001 From: Jacob Lindahl Date: Thu, 21 Sep 2023 18:50:45 +0900 Subject: [PATCH] feat: extension hooks --- macros/src/standard/fungible_token.rs | 1 + macros/src/standard/nep141.rs | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/macros/src/standard/fungible_token.rs b/macros/src/standard/fungible_token.rs index b3e695b..888f54a 100644 --- a/macros/src/standard/fungible_token.rs +++ b/macros/src/standard/fungible_token.rs @@ -42,6 +42,7 @@ pub fn expand(meta: FungibleTokenMeta) -> Result { let expand_nep141 = nep141::expand(nep141::Nep141Meta { storage_key: core_storage_key, no_hooks, + extension_hooks: None, generics: generics.clone(), ident: ident.clone(), diff --git a/macros/src/standard/nep141.rs b/macros/src/standard/nep141.rs index f651c6b..718dc32 100644 --- a/macros/src/standard/nep141.rs +++ b/macros/src/standard/nep141.rs @@ -8,6 +8,7 @@ use syn::Expr; pub struct Nep141Meta { pub storage_key: Option, pub no_hooks: Flag, + pub extension_hooks: Option, pub generics: syn::Generics, pub ident: syn::Ident, @@ -22,6 +23,7 @@ pub fn expand(meta: Nep141Meta) -> Result { let Nep141Meta { storage_key, no_hooks, + extension_hooks, generics, ident, @@ -39,12 +41,18 @@ pub fn expand(meta: Nep141Meta) -> Result { } }); - let hook = if no_hooks.is_present() { + let self_hook = if no_hooks.is_present() { quote! { () } } else { quote! { Self } }; + let hook = if let Some(extension_hooks) = extension_hooks { + quote! { (#self_hook, #extension_hooks) } + } else { + self_hook + }; + Ok(quote! { impl #imp #me::standard::nep141::Nep141ControllerInternal for #ident #ty #wher { type Hook = #hook;