-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
token 2022: move update authority check to shared file
- Loading branch information
1 parent
acabef3
commit f103552
Showing
4 changed files
with
28 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//! Utility function for checking an update authority | ||
|
||
use { | ||
solana_program::{account_info::AccountInfo, program_error::ProgramError, pubkey::Pubkey}, | ||
spl_pod::optional_keys::OptionalNonZeroPubkey, | ||
spl_token_metadata_interface::error::TokenMetadataError, | ||
}; | ||
|
||
/// Checks that the update authority is correct | ||
pub fn check_update_authority( | ||
update_authority_info: &AccountInfo, | ||
expected_update_authority: &OptionalNonZeroPubkey, | ||
) -> Result<(), ProgramError> { | ||
if !update_authority_info.is_signer { | ||
return Err(ProgramError::MissingRequiredSignature); | ||
} | ||
let update_authority = Option::<Pubkey>::from(*expected_update_authority) | ||
.ok_or(TokenMetadataError::ImmutableMetadata)?; | ||
if update_authority != *update_authority_info.key { | ||
return Err(TokenMetadataError::IncorrectUpdateAuthority.into()); | ||
} | ||
Ok(()) | ||
} |