Skip to content

Commit

Permalink
token 2022: make IncorrectMintAuthority a TokenError
Browse files Browse the repository at this point in the history
  • Loading branch information
buffalojoec committed Oct 18, 2023
1 parent 58ac7c2 commit 2776f2e
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 12 deletions.
4 changes: 2 additions & 2 deletions token-metadata/example/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use {
pubkey::Pubkey,
},
spl_pod::optional_keys::OptionalNonZeroPubkey,
spl_token_2022::{extension::StateWithExtensions, state::Mint},
spl_token_2022::{error::TokenError, extension::StateWithExtensions, state::Mint},
spl_token_metadata_interface::{
error::TokenMetadataError,
instruction::{
Expand Down Expand Up @@ -65,7 +65,7 @@ pub fn process_initialize(
return Err(ProgramError::MissingRequiredSignature);
}
if mint.base.mint_authority.as_ref() != COption::Some(mint_authority_info.key) {
return Err(TokenMetadataError::IncorrectMintAuthority.into());
return Err(TokenError::IncorrectMintAuthority.into());
}
}

Expand Down
7 changes: 3 additions & 4 deletions token-metadata/example/tests/initialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ use {
system_instruction,
transaction::{Transaction, TransactionError},
},
spl_token_metadata_interface::{
error::TokenMetadataError, instruction::initialize, state::TokenMetadata,
},
spl_token_2022::error::TokenError,
spl_token_metadata_interface::{instruction::initialize, state::TokenMetadata},
spl_type_length_value::{
error::TlvError,
state::{TlvState, TlvStateBorrowed},
Expand Down Expand Up @@ -265,7 +264,7 @@ async fn fail_incorrect_authority() {
error,
TransactionError::InstructionError(
1,
InstructionError::Custom(TokenMetadataError::IncorrectMintAuthority as u32)
InstructionError::Custom(TokenError::IncorrectMintAuthority as u32)
)
);
}
3 changes: 0 additions & 3 deletions token-metadata/interface/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ pub enum TokenMetadataError {
/// Mint has no mint authority
#[error("Mint has no mint authority")]
MintHasNoMintAuthority,
/// Incorrect mint authority has signed the instruction
#[error("Incorrect mint authority has signed the instruction")]
IncorrectMintAuthority,
/// Incorrect metadata update authority has signed the instruction
#[error("Incorrect metadata update authority has signed the instruction")]
IncorrectUpdateAuthority,
Expand Down
4 changes: 2 additions & 2 deletions token/program-2022-test/tests/token_metadata_initialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use {
},
spl_token_2022::{error::TokenError, extension::BaseStateWithExtensions, processor::Processor},
spl_token_client::token::{ExtensionInitializationParams, TokenError as TokenClientError},
spl_token_metadata_interface::{error::TokenMetadataError, state::TokenMetadata},
spl_token_metadata_interface::state::TokenMetadata,
std::{convert::TryInto, sync::Arc},
};

Expand Down Expand Up @@ -110,7 +110,7 @@ async fn success_initialize() {
TokenClientError::Client(Box::new(TransportError::TransactionError(
TransactionError::InstructionError(
1,
InstructionError::Custom(TokenMetadataError::IncorrectMintAuthority as u32)
InstructionError::Custom(TokenError::IncorrectMintAuthority as u32)
)
)))
);
Expand Down
6 changes: 6 additions & 0 deletions token/program-2022/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ pub enum TokenError {
/// Ciphertext arithmetic failed
#[error("Ciphertext arithmetic failed")]
CiphertextArithmeticFailed,
/// Incorrect mint authority has signed the instruction
#[error("Incorrect mint authority has signed the instruction")]
IncorrectMintAuthority,
}
impl From<TokenError> for ProgramError {
fn from(e: TokenError) -> Self {
Expand Down Expand Up @@ -407,6 +410,9 @@ impl PrintProgramError for TokenError {
TokenError::CiphertextArithmeticFailed => {
msg!("Ciphertext arithmetic failed")
}
TokenError::IncorrectMintAuthority => {
msg!("Incorrect mint authority has signed the instruction")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub fn process_initialize(
return Err(ProgramError::MissingRequiredSignature);
}
if mint.base.mint_authority.as_ref() != COption::Some(mint_authority_info.key) {
return Err(TokenMetadataError::IncorrectMintAuthority.into());
return Err(TokenError::IncorrectMintAuthority.into());
}

if mint.get_extension::<MetadataPointer>().is_err() {
Expand Down

0 comments on commit 2776f2e

Please sign in to comment.