Skip to content

Instantly share code, notes, and snippets.

@cqfd
Created October 10, 2021 00:04
Show Gist options
  • Save cqfd/1420d600b4d714ca21a113e9bb249b6c to your computer and use it in GitHub Desktop.
Save cqfd/1420d600b4d714ca21a113e9bb249b6c to your computer and use it in GitHub Desktop.
Pubkey solana/anchor macro
#[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