(
program_id: &Pubkey,
ctx: Context<Remove>,
extension_type: ExtensionType,
)
| 26 | /// 3. `[writable]` recipient |
| 27 | #[inline(always)] |
| 28 | pub fn process_remove( |
| 29 | program_id: &Pubkey, |
| 30 | ctx: Context<Remove>, |
| 31 | extension_type: ExtensionType, |
| 32 | ) -> ProgramResult { |
| 33 | // account validation |
| 34 | |
| 35 | require!( |
| 36 | ctx.accounts.authority.is_signer(), |
| 37 | ProgramError::MissingRequiredSignature, |
| 38 | "authority" |
| 39 | ); |
| 40 | |
| 41 | require!( |
| 42 | ctx.accounts.asset.owner() == program_id, |
| 43 | ProgramError::IllegalOwner, |
| 44 | "asset" |
| 45 | ); |
| 46 | |
| 47 | let mut account_data = ctx.accounts.asset.try_borrow_mut_data()?; |
| 48 | |
| 49 | require!( |
| 50 | account_data.len() >= Asset::LEN && account_data[0] == Discriminator::Asset.into(), |
| 51 | AssetError::Uninitialized, |
| 52 | "asset" |
| 53 | ); |
| 54 | |
| 55 | let asset = Asset::load_mut(&mut account_data); |
| 56 | |
| 57 | require!( |
| 58 | asset.authority == *ctx.accounts.authority.key(), |
| 59 | AssetError::InvalidAuthority, |
| 60 | "authority" |
| 61 | ); |
| 62 | |
| 63 | require!( |
| 64 | <PodBool as Into<bool>>::into(asset.mutable), |
| 65 | AssetError::ImmutableAsset, |
| 66 | "asset" |
| 67 | ); |
| 68 | |
| 69 | // removes the extension |
| 70 | |
| 71 | let mut offset = Asset::LEN; |
| 72 | let mut boundary = None; |
| 73 | |
| 74 | while offset + Extension::LEN < account_data.len() { |
| 75 | let current = Extension::load(&account_data[offset..offset + Extension::LEN]); |
| 76 | |
| 77 | match current.try_extension_type() { |
| 78 | Ok(t) if t == extension_type => { |
| 79 | boundary = Some(current.boundary() as usize); |
| 80 | break; |
| 81 | } |
| 82 | Ok(ExtensionType::None) => break, |
| 83 | _ => offset = current.boundary() as usize, |
| 84 | } |
| 85 | } |
no test coverage detected