Skip to content

Commit

Permalink
fix(authority): check that type is Default or Custom
Browse files Browse the repository at this point in the history
  • Loading branch information
ogmedia committed Sep 28, 2022
1 parent 4b2e774 commit 6568df3
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions programs/mesh/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,18 @@ pub mod mesh {
// authority specified during the transaction creation
pub fn add_instruction(ctx: Context<AddInstruction>, incoming_instruction: IncomingInstruction, authority_index: Option<u32>, authority_bump: Option<u8>, authority_type: MsAuthorityType) -> Result<()> {
let tx = &mut ctx.accounts.transaction;

let mut ix_authority_index = authority_index;
let mut ix_authority_bump = authority_bump;
let mut ix_authority_type = authority_type;

// check the proper authority level option is set
if ix_authority_type != MsAuthorityType::Default && ix_authority_type != MsAuthorityType::Custom{
return err!(GraphsError::InvalidAuthorityType);
}

// if no authority values are passed in, regardless of what the authority type is,
// we will use the authority specified in the transaction
// we will use the authority specified in the transaction and set the type to Default
if authority_index.is_none() && authority_bump.is_none() {
ix_authority_index = Some(tx.authority_index);
ix_authority_bump = Some(tx.authority_bump);
Expand All @@ -238,10 +243,6 @@ pub mod mesh {
return err!(GraphsError::InvalidAuthorityIndex);
}

if ix_authority_type != MsAuthorityType::Default && ix_authority_type != MsAuthorityType::Custom{
return err!(GraphsError::InvalidAuthorityType);
}

tx.instruction_index = tx.instruction_index.checked_add(1).unwrap();
ctx.accounts.instruction.init(
tx.instruction_index,
Expand Down

0 comments on commit 6568df3

Please sign in to comment.