Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Remove commented code #1094

Merged
merged 1 commit into from
Aug 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
272 changes: 0 additions & 272 deletions macros/light/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,278 +154,6 @@ pub fn light_traits_derive(input: TokenStream) -> TokenStream {
}
}

// #[proc_macro_derive(
// LightTraits,
// attributes(self_program, fee_payer, authority, cpi_context)
// )]
// pub fn light_traits_derive(input: TokenStream) -> TokenStream {
// let input = parse_macro_input!(input as DeriveInput);
// let name = &input.ident;

// let trait_impls = match input.data {
// Data::Struct(data_struct) => {
// match data_struct.fields {
// Fields::Named(fields) => {
// let mut self_program_field = None;
// let mut fee_payer_field = None;
// let mut authority_field = None;
// let mut light_system_program_field = None;
// let mut cpi_context_account_field = None;

// // base impl
// let mut registered_program_pda_field = None;
// let mut noop_program_field = None;
// let mut account_compression_authority_field = None;
// let mut account_compression_program_field = None;
// let mut system_program_field = None;

// let compressed_sol_pda_field = fields
// .named
// .iter()
// .find_map(|f| {
// if f.ident
// .as_ref()
// .map(|id| id == "compressed_sol_pda")
// .unwrap_or(false)
// {
// Some(quote! { self.#f.ident.as_ref() })
// } else {
// None
// }
// })
// .unwrap_or(quote! { None });

// let compression_recipient_field = fields
// .named
// .iter()
// .find_map(|f| {
// if f.ident
// .as_ref()
// .map(|id| id == "compression_recipient")
// .unwrap_or(false)
// {
// Some(quote! { self.#f.ident.as_ref() })
// } else {
// None
// }
// })
// .unwrap_or(quote! { None });

// for f in fields.named.iter() {
// for attr in &f.attrs {
// if attr.path.is_ident("self_program") {
// self_program_field = Some(f.ident.as_ref().unwrap());
// }
// if attr.path.is_ident("fee_payer") {
// fee_payer_field = Some(f.ident.as_ref().unwrap());
// }
// if attr.path.is_ident("authority") {
// authority_field = Some(f.ident.as_ref().unwrap());
// }
// if attr.path.is_ident("cpi_context") {
// cpi_context_account_field = Some(f.ident.as_ref().unwrap());
// }
// }
// if f.ident
// .as_ref()
// .map(|id| id == "light_system_program")
// .unwrap_or(false)
// {
// light_system_program_field = Some(f.ident.as_ref().unwrap());
// }
// if f.ident
// .as_ref()
// .map(|id| id == "registered_program_pda")
// .unwrap_or(false)
// {
// registered_program_pda_field = Some(f.ident.as_ref().unwrap());
// }
// if f.ident
// .as_ref()
// .map(|id| id == "noop_program")
// .unwrap_or(false)
// {
// noop_program_field = Some(f.ident.as_ref().unwrap());
// }
// if f.ident
// .as_ref()
// .map(|id| id == "account_compression_authority")
// .unwrap_or(false)
// {
// account_compression_authority_field = Some(f.ident.as_ref().unwrap());
// }
// if f.ident
// .as_ref()
// .map(|id| id == "account_compression_program")
// .unwrap_or(false)
// {
// account_compression_program_field = Some(f.ident.as_ref().unwrap());
// }
// if f.ident
// .as_ref()
// .map(|id| id == "system_program")
// .unwrap_or(false)
// {
// system_program_field = Some(f.ident.as_ref().unwrap());
// }
// }

// // optional: compressed_sol_pda, compression_recipient,
// // cpi_context_account
// let missing_required_fields = [
// if light_system_program_field.is_none() {
// "light_system_program"
// } else {
// ""
// },
// if registered_program_pda_field.is_none() {
// "registered_program_pda"
// } else {
// ""
// },
// if noop_program_field.is_none() {
// "noop_program"
// } else {
// ""
// },
// if account_compression_authority_field.is_none() {
// "account_compression_authority"
// } else {
// ""
// },
// if account_compression_program_field.is_none() {
// "account_compression_program"
// } else {
// ""
// },
// if system_program_field.is_none() {
// "system_program"
// } else {
// ""
// },
// ]
// .iter()
// .filter(|&field| !field.is_empty())
// .cloned()
// .collect::<Vec<_>>();

// let missing_required_attributes = [
// if self_program_field.is_none() {
// "self_program"
// } else {
// ""
// },
// if fee_payer_field.is_none() {
// "fee_payer"
// } else {
// ""
// },
// if authority_field.is_none() {
// "authority"
// } else {
// ""
// },
// ]
// .iter()
// .filter(|&attr| !attr.is_empty())
// .cloned()
// .collect::<Vec<_>>();

// if !missing_required_fields.is_empty()
// || !missing_required_attributes.is_empty()
// {
// let error_message = format!(
// "Error: Missing required fields: [{}], Missing required attributes: [{}]",
// missing_required_fields.join(", "),
// missing_required_attributes.join(", ")
// );
// quote! {
// compile_error!(#error_message);
// }
// } else {
// let base_impls = quote! {
// impl<'info> InvokeCpiAccounts<'info> for #name<'info> {
// fn get_invoking_program(&self) -> &AccountInfo<'info> {
// &self.#self_program_field
// }
// }
// impl<'info> SignerAccounts<'info> for #name<'info> {
// fn get_fee_payer(&self) -> &Signer<'info> {
// &self.#fee_payer_field
// }
// fn get_authority(&self) -> &AccountInfo<'info> {
// &self.#authority_field
// }
// }
// impl<'info> LightSystemAccount<'info> for #name<'info> {
// fn get_light_system_program(&self) -> &Program<'info, LightSystemProgram> {
// &self.#light_system_program_field
// }
// }
// };
// let invoke_accounts_impl = quote! {
// impl<'info> InvokeAccounts<'info> for #name<'info> {
// fn get_registered_program_pda(&self) -> &Account<'info, RegisteredProgram> {
// &self.#registered_program_pda_field
// }
// fn get_noop_program(&self) -> &AccountInfo<'info> {
// &self.#noop_program_field
// }
// fn get_account_compression_authority(&self) -> &AccountInfo<'info> {
// &self.#account_compression_authority_field
// }
// fn get_account_compression_program(&self) -> &Program<'info, AccountCompression> {
// &self.#account_compression_program_field
// }
// fn get_system_program(&self) -> &Program<'info, System> {
// &self.#system_program_field
// }
// fn get_compressed_sol_pda(&self) -> Option<&UncheckedAccount<'info>> {
// #compressed_sol_pda_field
// }
// fn get_compression_recipient(&self) -> Option<&UncheckedAccount<'info>> {
// #compression_recipient_field
// }
// }
// };
// if cpi_context_account_field.is_none() {
// quote! {
// #base_impls
// #invoke_accounts_impl
// impl<'info> InvokeCpiContextAccount<'info> for #name<'info> {
// fn get_cpi_context_account(&self) -> Option<&Account<'info, CpiContextAccount>> {
// None
// }
// }
// }
// } else {
// quote! {
// #base_impls
// #invoke_accounts_impl
// impl<'info> InvokeCpiContextAccount<'info> for #name<'info> {
// fn get_cpi_context_account(&self) -> Option<&Account<'info, CpiContextAccount>> {
// Some(&self.#cpi_context_account_field)
// }
// }
// }
// }
// }
// }
// _ => quote! {
// compile_error!("Error: Expected named fields but found unnamed or no fields.");
// },
// }
// }
// _ => quote! {},
// };

// let expanded = quote! {
// #trait_impls
// };

// TokenStream::from(expanded)
// }

#[proc_macro_derive(LightDiscriminator)]
pub fn light_discriminator(input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as ItemStruct);
Expand Down