(
program_id: &Pubkey,
ctx: Context<Update>,
args: UpdateInput,
)
| 39 | /// 3. `[optional]` system_program |
| 40 | #[inline(always)] |
| 41 | pub fn process_update( |
| 42 | program_id: &Pubkey, |
| 43 | ctx: Context<Update>, |
| 44 | args: UpdateInput, |
| 45 | ) -> ProgramResult { |
| 46 | // account validation |
| 47 | |
| 48 | require!( |
| 49 | ctx.accounts.authority.is_signer(), |
| 50 | ProgramError::MissingRequiredSignature, |
| 51 | "authority" |
| 52 | ); |
| 53 | |
| 54 | require!( |
| 55 | ctx.accounts.asset.owner() == program_id, |
| 56 | ProgramError::IllegalOwner, |
| 57 | "asset" |
| 58 | ); |
| 59 | |
| 60 | let mut account_data = ctx.accounts.asset.try_borrow_mut_data()?; |
| 61 | |
| 62 | require!( |
| 63 | account_data.len() >= Asset::LEN && account_data[0] == Discriminator::Asset.into(), |
| 64 | AssetError::Uninitialized, |
| 65 | "asset" |
| 66 | ); |
| 67 | |
| 68 | let asset = Asset::load_mut(&mut account_data); |
| 69 | |
| 70 | require!( |
| 71 | asset.authority == *ctx.accounts.authority.key(), |
| 72 | AssetError::InvalidAuthority, |
| 73 | "authority" |
| 74 | ); |
| 75 | |
| 76 | require!( |
| 77 | <PodBool as Into<bool>>::into(asset.mutable), |
| 78 | AssetError::ImmutableAsset, |
| 79 | "asset" |
| 80 | ); |
| 81 | |
| 82 | // updates the asset: |
| 83 | // |
| 84 | // 1. name |
| 85 | // 2. mutable flag |
| 86 | // 3. extension |
| 87 | |
| 88 | if let Some(name) = args.name { |
| 89 | asset.name = name.into(); |
| 90 | } |
| 91 | |
| 92 | if let Some(mutable) = args.mutable { |
| 93 | asset.mutable = mutable.into(); |
| 94 | } |
| 95 | |
| 96 | // creating/updating an extension is a multi-step process: |
| 97 | // |
| 98 | // 1. find the extension to update or determine that it is a new one |
no test coverage detected