Skip to content

Commit

Permalink
[wip]: Fix use of Pubkey::try_from
Browse files Browse the repository at this point in the history
  • Loading branch information
lorisleiva committed Jan 10, 2025
1 parent a0ce5a8 commit b102f60
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 8 deletions.
4 changes: 2 additions & 2 deletions program/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ pub enum ProgramMetadataInstruction {
/// Withdraws excess lamports from a metadata account.
///
/// ### Accounts
/// 0. `[ w ]` Account to close.
/// 1. `[ s ]` Metadata authority or buffer account.
/// 0. `[ w ]` Metadata account.
/// 1. `[ s ]` Metadata authority account.
/// 2. `[ o ]` (optional) Program account.
/// 3. `[ o ]` (optional) Program data account.
/// 5. `[ w ]` Destination account.
Expand Down
4 changes: 3 additions & 1 deletion program/src/processor/close.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use super::validate_authority;
///
/// ## Validation
/// The following validation checks are performed:
///
/// - [implicit] The `account` to close is owned by the Program Metadata program. Implicitly checked by closing to the account.
pub fn close(accounts: &[AccountInfo]) -> ProgramResult {
let [account, authority, program, program_data, destination] = accounts else {
return Err(ProgramError::NotEnoughAccountKeys);
Expand All @@ -32,7 +34,7 @@ pub fn close(accounts: &[AccountInfo]) -> ProgramResult {
}
}
AccountDiscriminator::Metadata => {
// Metadata and authority validation is done in the `validate_update`.
// Metadata and authority validation is done in the `validate_authority`.
validate_authority(account, authority, program, program_data)?
}
_ => return Err(ProgramError::InvalidAccountData),
Expand Down
4 changes: 2 additions & 2 deletions program/src/processor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn is_program_authority(
match (data.first(), program.executable()) {
(Some(2 /* program discriminator */), true) => {
let offset: usize = 4 /* discriminator */;
Pubkey::try_from(data[offset..]).map_err(|_| ProgramError::InvalidAccountData)?
Pubkey::try_from(&data[offset..]).map_err(|_| ProgramError::InvalidAccountData)?
}
_ => {
// TODO: use custom error (invalid program state)
Expand All @@ -56,7 +56,7 @@ fn is_program_authority(
let option_offset: usize = 4 /* discriminator */ + 8 /* slot */;
if data[option_offset] == 1 {
let pubkey_offset: usize = option_offset + 1 /* option */;
let authority_key = Pubkey::try_from(data[pubkey_offset..])
let authority_key = Pubkey::try_from(&data[pubkey_offset..])
.map_err(|_| ProgramError::InvalidAccountData)?;
authority == &authority_key
} else {
Expand Down
2 changes: 1 addition & 1 deletion program/src/processor/set_authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub fn set_authority(accounts: &[AccountInfo], instruction_data: &[u8]) -> Progr
.split_first()
.ok_or(ProgramError::InvalidInstructionData)?;

// Accounts validation is done in the `validate_update` function.
// Accounts validation is done in the `validate_authority` function.
// - metadata: program owned is implicitly checked since we are writing to
// the account
validate_authority(metadata, authority, program, program_data)?;
Expand Down
2 changes: 1 addition & 1 deletion program/src/processor/set_immutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub fn set_immutable(accounts: &[AccountInfo]) -> ProgramResult {
return Err(ProgramError::NotEnoughAccountKeys);
};

// Accounts validation is done in the `validate_update` function.
// Accounts validation is done in the `validate_authority` function.
validate_authority(metadata, authority, program, program_data)?;

// Make the metadata account immutable.
Expand Down
2 changes: 1 addition & 1 deletion program/src/processor/withdraw_excess_lamports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub fn withdraw_excess_lamports(accounts: &[AccountInfo]) -> ProgramResult {
return Err(ProgramError::NotEnoughAccountKeys);
};

// Accounts validation is done in the `validate_update` function.
// Accounts validation is done in the `validate_authority` function.
validate_authority(metadata, authority, program, program_data)?;

// Withdraw the excess lamports in the account.
Expand Down

0 comments on commit b102f60

Please sign in to comment.