Skip to content

Commit

Permalink
add mut constraint for Mint Account & payer arg for initIfNeeded
Browse files Browse the repository at this point in the history
  • Loading branch information
ShrinathNR committed Oct 29, 2024
1 parent 361b505 commit 2e38d10
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/rs_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,13 @@ impl InstructionAccount {
let name = Ident::new(&self.name, proc_macro2::Span::call_site());
let of_type = &self.of_type;
let constraints: TokenStream;
if self.seeds.is_none() & (self.is_close | self.is_init | self.is_initifneeded) {
// this is evaluated this way coz, ta might not have seeds
if (self.seeds.is_none() & self.ta.is_none()) & (self.is_close | self.is_init | self.is_initifneeded) {
panic!(r##"use derive or deriveWithBump while using "init" or "initIfNeeded" or "close" "##);
}
let payer = match &self.payer {
Some(s) => {
let payer = Ident::new(s, proc_macro2::Span::call_site());
let payer = Ident::new(&s.to_case(Case::Snake), proc_macro2::Span::call_site());
quote!(
payer = #payer
)
Expand Down Expand Up @@ -544,6 +545,8 @@ impl ProgramInstruction {
),
);
program_mod.add_import("anchor_spl", "token", "Mint");
let cur_ix_acc = ix_accounts.get_mut(&name.clone()).unwrap();
cur_ix_acc.is_mut = true;
} else if of_type == "TokenAccount" {
ix_accounts.insert(
name.clone(),
Expand Down Expand Up @@ -723,9 +726,7 @@ impl ProgramInstruction {
else if chaincall1prop == "initIfNeeded" {
ix.uses_system_program = true;
cur_ix_acc.is_initifneeded = true;
if let Some(payer) = &ix.signer {
cur_ix_acc.payer = Some(payer.clone());
}
cur_ix_acc.payer = Some(c.args[0].expr.as_ident().ok_or(PoseidonError::IdentNotFound)?.sym.as_ref().to_case(Case::Snake));
}
if chaincall1prop == "close" {
cur_ix_acc.close = Some(c.args[0].expr.as_ident().ok_or(PoseidonError::IdentNotFound)?.sym.as_ref().to_case(Case::Snake));
Expand All @@ -740,16 +741,14 @@ impl ProgramInstruction {
cur_ix_acc.has_one = has_one;

}
} else if prop.contains("init") {
} else if prop == "init" {
ix.uses_system_program = true;
cur_ix_acc.is_init = true;
cur_ix_acc.payer = Some(c.args[0].expr.as_ident().ok_or(PoseidonError::IdentNotFound)?.sym.as_ref().to_case(Case::Snake));
} else if prop.contains("initIfNeeded") {
ix.uses_system_program = true;
cur_ix_acc.is_initifneeded = true;
if let Some(payer) = &ix.signer {
cur_ix_acc.payer = Some(payer.clone());
}
cur_ix_acc.payer = Some(c.args[0].expr.as_ident().ok_or(PoseidonError::IdentNotFound)?.sym.as_ref().to_case(Case::Snake));
} else if prop.contains("close") {
cur_ix_acc.close = Some(c.args[0].expr.as_ident().ok_or(PoseidonError::IdentNotFound)?.sym.as_ref().to_case(Case::Snake));
cur_ix_acc.is_mut = true;
Expand Down

0 comments on commit 2e38d10

Please sign in to comment.