(
_program_id: &Pubkey,
ctx: nifty_asset_interface::accounts::Context<'a, UpdateAccounts<'a>>,
input: UpdateInput,
)
| 6 | use crate::require; |
| 7 | |
| 8 | pub fn process_update<'a>( |
| 9 | _program_id: &Pubkey, |
| 10 | ctx: nifty_asset_interface::accounts::Context<'a, UpdateAccounts<'a>>, |
| 11 | input: UpdateInput, |
| 12 | ) -> ProgramResult { |
| 13 | // account validation happends on the CPI, we only need to make sure we |
| 14 | // have the authority to perform the update |
| 15 | |
| 16 | let data = (*ctx.accounts.asset.data).borrow(); |
| 17 | fetch_proxy_data!( |
| 18 | &data, |
| 19 | signer, |
| 20 | authority, |
| 21 | nifty_asset_program, |
| 22 | ctx.remaining_accounts |
| 23 | ); |
| 24 | |
| 25 | require!( |
| 26 | ctx.accounts.authority.is_signer, |
| 27 | ProgramError::MissingRequiredSignature, |
| 28 | "authority" |
| 29 | ); |
| 30 | |
| 31 | // we need to validate the authority against the "proxy" authority |
| 32 | // since the asset itself is the authority for the update |
| 33 | if let Some(authority) = authority { |
| 34 | require!( |
| 35 | *ctx.accounts.authority.key == *authority, |
| 36 | ProgramError::InvalidArgument, |
| 37 | "authority mismatch" |
| 38 | ); |
| 39 | } else { |
| 40 | msg!("[ERROR] Authority not found"); |
| 41 | return Err(ProgramError::InvalidArgument); |
| 42 | } |
| 43 | |
| 44 | drop(data); |
| 45 | |
| 46 | // cpi into the Nifty Asset program to perform the update |
| 47 | // (ignores any request to update extension update) |
| 48 | |
| 49 | let mut builder = UpdateCpiBuilder::new(nifty_asset_program); |
| 50 | |
| 51 | builder |
| 52 | .asset(ctx.accounts.asset) |
| 53 | .authority(ctx.accounts.asset); |
| 54 | |
| 55 | if let Some(name) = input.name { |
| 56 | builder.name(name); |
| 57 | } |
| 58 | |
| 59 | if let Some(mutable) = input.mutable { |
| 60 | builder.mutable(mutable); |
| 61 | } |
| 62 | |
| 63 | if let Some(extension) = input.extension { |
| 64 | msg!( |
| 65 | "Ignoring [{:?}] extension update request", |
no test coverage detected