2026-06-06 03:15:30 +05:30
|
|
|
use lez_authority::Ownable;
|
2026-05-27 15:04:28 +05:30
|
|
|
use nssa_core::{
|
2026-06-06 03:15:30 +05:30
|
|
|
account::{AccountId, AccountWithMetadata, Data},
|
2026-05-27 15:04:28 +05:30
|
|
|
program::AccountPostState,
|
|
|
|
|
};
|
|
|
|
|
use token_core::TokenDefinition;
|
|
|
|
|
|
|
|
|
|
pub fn set_authority(
|
|
|
|
|
definition_account: AccountWithMetadata,
|
2026-06-06 03:15:30 +05:30
|
|
|
new_authority: Option<AccountId>,
|
2026-05-27 15:04:28 +05:30
|
|
|
) -> Vec<AccountPostState> {
|
|
|
|
|
let mut definition = TokenDefinition::try_from(&definition_account.account.data)
|
|
|
|
|
.expect("Token Definition account must be valid");
|
|
|
|
|
|
|
|
|
|
match &mut definition {
|
2026-06-06 03:15:30 +05:30
|
|
|
TokenDefinition::Fungible { .. } => {
|
|
|
|
|
// The current mint authority must authorize this transaction: the
|
|
|
|
|
// definition account must be authorized and its id must match the
|
|
|
|
|
// stored authority.
|
2026-06-03 01:10:08 +05:30
|
|
|
assert!(
|
2026-06-06 03:15:30 +05:30
|
|
|
definition_account.is_authorized,
|
|
|
|
|
"Mint authority must authorize the transaction"
|
2026-06-03 01:10:08 +05:30
|
|
|
);
|
2026-06-06 03:15:30 +05:30
|
|
|
let signer: [u8; 32] = definition_account
|
2026-06-03 01:10:08 +05:30
|
|
|
.account_id
|
|
|
|
|
.as_ref()
|
|
|
|
|
.try_into()
|
|
|
|
|
.expect("AccountId is always 32 bytes");
|
2026-06-06 03:15:30 +05:30
|
|
|
|
|
|
|
|
match new_authority {
|
|
|
|
|
Some(new) => {
|
|
|
|
|
let new_key: [u8; 32] = new
|
|
|
|
|
.as_ref()
|
|
|
|
|
.try_into()
|
|
|
|
|
.expect("AccountId is always 32 bytes");
|
|
|
|
|
assert!(
|
|
|
|
|
new_key != [0u8; 32],
|
|
|
|
|
"New mint authority must be a valid non-zero account ID"
|
|
|
|
|
);
|
|
|
|
|
definition
|
|
|
|
|
.transfer_ownership(signer, new_key)
|
|
|
|
|
.expect("SetAuthority failed");
|
|
|
|
|
}
|
|
|
|
|
None => {
|
|
|
|
|
definition
|
|
|
|
|
.renounce_ownership(signer)
|
|
|
|
|
.expect("SetAuthority failed");
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-05-27 15:04:28 +05:30
|
|
|
}
|
|
|
|
|
TokenDefinition::NonFungible { .. } => {
|
|
|
|
|
panic!("SetAuthority is not supported for Non-Fungible Tokens");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let mut definition_post = definition_account.account;
|
|
|
|
|
definition_post.data = Data::from(&definition);
|
|
|
|
|
|
2026-06-06 03:15:30 +05:30
|
|
|
vec![AccountPostState::new(definition_post)]
|
2026-06-02 02:36:51 +05:30
|
|
|
}
|