Created
October 10, 2021 00:04
-
-
Save cqfd/1420d600b4d714ca21a113e9bb249b6c to your computer and use it in GitHub Desktop.
Pubkey solana/anchor macro
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
#[proc_macro] | |
pub fn pubkey(input: proc_macro::TokenStream) -> proc_macro::TokenStream { | |
let s = parse_macro_input!(input as LitStr); | |
let pk: Pubkey = s.value().parse().unwrap(); | |
let bytes = pk.to_bytes().map(|b| LitByte::new(b, Span::call_site())); | |
let output = quote! { | |
anchor_lang::solana_program::pubkey::Pubkey::new_from_array([#(#bytes,)*]) | |
}; | |
output.into() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment