Skip to content

Commit

Permalink
feat: extension hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
encody committed Sep 21, 2023
1 parent 9ddd0d1 commit 1415b6e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions macros/src/standard/fungible_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ pub fn expand(meta: FungibleTokenMeta) -> Result<TokenStream, darling::Error> {
let expand_nep141 = nep141::expand(nep141::Nep141Meta {
storage_key: core_storage_key,
no_hooks,
extension_hooks: None,

generics: generics.clone(),
ident: ident.clone(),
Expand Down
10 changes: 9 additions & 1 deletion macros/src/standard/nep141.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use syn::Expr;
pub struct Nep141Meta {
pub storage_key: Option<Expr>,
pub no_hooks: Flag,
pub extension_hooks: Option<syn::Type>,
pub generics: syn::Generics,
pub ident: syn::Ident,

Expand All @@ -22,6 +23,7 @@ pub fn expand(meta: Nep141Meta) -> Result<TokenStream, darling::Error> {
let Nep141Meta {
storage_key,
no_hooks,
extension_hooks,
generics,
ident,

Expand All @@ -39,12 +41,18 @@ pub fn expand(meta: Nep141Meta) -> Result<TokenStream, darling::Error> {
}
});

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;
Expand Down

0 comments on commit 1415b6e

Please sign in to comment.