-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I'm tired of computing treasury seeds in almost every glam method. Created a macro for it.
- Loading branch information
Showing
19 changed files
with
148 additions
and
341 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
name = "glam_macros" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[lib] | ||
proc-macro = true | ||
|
||
[dependencies] | ||
syn = { version = "2.0", features = ["full"] } | ||
quote = "1.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use proc_macro::TokenStream; | ||
use quote::quote; | ||
use syn::{parse_macro_input, ItemFn}; | ||
|
||
#[proc_macro_attribute] | ||
pub fn treasury_signer_seeds(_attr: TokenStream, item: TokenStream) -> TokenStream { | ||
// Parse the input as a function | ||
let input = parse_macro_input!(item as ItemFn); | ||
let func_attrs = &input.attrs; | ||
let func_vis = &input.vis; | ||
let func_sig = &input.sig; | ||
let func_block = &input.block; | ||
|
||
// Generate the modified function with `treasury_signer_seeds` added at the start of the body | ||
let expanded = quote! { | ||
#(#func_attrs)* | ||
#func_vis #func_sig { | ||
// We assume the fund account and the treasury bump seed are available in the context | ||
let fund_key = ctx.accounts.fund.key(); | ||
let seeds = [ | ||
b"treasury".as_ref(), | ||
fund_key.as_ref(), | ||
&[ctx.bumps.treasury], | ||
]; | ||
let treasury_signer_seeds = &[&seeds[..]]; | ||
|
||
// Original function body follows | ||
#func_block | ||
} | ||
}; | ||
|
||
TokenStream::from(expanded) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.