Creates a new asset. ### Accounts: 0. `[writable, signer]` asset 1. `[optional_signer]` authority 2. `[]` owner 3. `[writable, optional]` group 4. `[signer, optional]` group_authority 5. `[writable, signer, optional]` payer 6. `[optional]` system_program
(
program_id: &Pubkey,
ctx: Context<Create>,
args: MetadataInput,
)
| 31 | /// 5. `[writable, signer, optional]` payer |
| 32 | /// 6. `[optional]` system_program |
| 33 | pub fn process_create( |
| 34 | program_id: &Pubkey, |
| 35 | ctx: Context<Create>, |
| 36 | args: MetadataInput, |
| 37 | ) -> ProgramResult { |
| 38 | // account validation |
| 39 | |
| 40 | require!( |
| 41 | ctx.accounts.asset.is_signer(), |
| 42 | ProgramError::MissingRequiredSignature, |
| 43 | "asset" |
| 44 | ); |
| 45 | |
| 46 | if ctx.accounts.asset.data_is_empty() { |
| 47 | let payer = { |
| 48 | require!( |
| 49 | ctx.accounts.payer.is_some(), |
| 50 | ProgramError::NotEnoughAccountKeys, |
| 51 | "payer" |
| 52 | ); |
| 53 | |
| 54 | ctx.accounts.payer.unwrap() |
| 55 | }; |
| 56 | |
| 57 | require!( |
| 58 | payer.is_signer(), |
| 59 | ProgramError::MissingRequiredSignature, |
| 60 | "payer" |
| 61 | ); |
| 62 | |
| 63 | let system_program = { |
| 64 | require!( |
| 65 | ctx.accounts.system_program.is_some(), |
| 66 | ProgramError::NotEnoughAccountKeys, |
| 67 | "system_program" |
| 68 | ); |
| 69 | |
| 70 | ctx.accounts.system_program.unwrap() |
| 71 | }; |
| 72 | |
| 73 | require!( |
| 74 | system_program.key() == &system_program::ID, |
| 75 | ProgramError::IncorrectProgramId, |
| 76 | "system_program" |
| 77 | ); |
| 78 | |
| 79 | let space = Asset::LEN |
| 80 | + if let Some(extensions) = &args.extensions { |
| 81 | let mut total = 0; |
| 82 | |
| 83 | for extension in extensions { |
| 84 | total += std::alloc::Layout::from_size_align( |
| 85 | extension.length as usize + Extension::LEN, |
| 86 | std::mem::size_of::<u64>(), |
| 87 | ) |
| 88 | .map_err(|_| AssetError::InvalidAlignment)? |
| 89 | .pad_to_align() |
| 90 | .size(); |
no test coverage detected