Skip to content

Commit

Permalink
add bump check while passing signer seeds
Browse files Browse the repository at this point in the history
  • Loading branch information
ShrinathNR committed Oct 28, 2024
1 parent 51f5946 commit dc9d2cb
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/rs_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ impl ProgramInstruction {
pub fn get_seeds(&mut self, seeds: &Vec<Option<ExprOrSpread>>, is_signer_seeds: bool) -> Result<Vec<TokenStream>> {
let mut seeds_token: Vec<TokenStream> = vec![];
let mut ix_attribute_token: Vec<TokenStream> = vec![];
let mut is_bump_passed : bool = false;
for (index, elem) in seeds.into_iter().flatten().enumerate() {
match *(elem.expr.clone()) {
Expr::Lit(Lit::Str(seedstr)) => {
Expand Down Expand Up @@ -329,6 +330,7 @@ impl ProgramInstruction {
seeds_token.push(quote!{
&[ctx.accounts.#seed_obj_ident.#seed_prop_ident]
});
is_bump_passed = true;
}

}
Expand Down Expand Up @@ -365,6 +367,7 @@ impl ProgramInstruction {
seeds_token.push(quote! {
&[ctx.bumps.#seed_obj_ident]
});
is_bump_passed = true;
}

for arg in self.args.iter() {
Expand Down Expand Up @@ -430,6 +433,9 @@ impl ProgramInstruction {
if !ix_attribute_token.is_empty() {
self.instruction_attributes = Some(ix_attribute_token);
}
if is_signer_seeds & !is_bump_passed {
panic!("Bump not passed in the signer seeds list, add it as the last element of the signer seeds list")
}
Ok(seeds_token)
}

Expand Down

0 comments on commit dc9d2cb

Please sign in to comment.