MCPcopy Create free account
hub / github.com/nifty-oss/asset / process_close

Function process_close

programs/asset/program/src/processor/close.rs:17–48  ·  view source on GitHub ↗

Closes an uninitialized asset buffer account. ### Accounts: 0. `[writable, signer]` buffer 1. `[writable]` recipient

(program_id: &Pubkey, ctx: Context<Close>)

Source from the content-addressed store, hash-verified

15/// 0. `[writable, signer]` buffer
16/// 1. `[writable]` recipient
17pub fn process_close(program_id: &Pubkey, ctx: Context<Close>) -> ProgramResult {
18 // account validation
19
20 require!(
21 ctx.accounts.buffer.is_signer(),
22 ProgramError::MissingRequiredSignature,
23 "buffer"
24 );
25
26 require!(
27 ctx.accounts.buffer.owner() == program_id,
28 ProgramError::IllegalOwner,
29 "buffer"
30 );
31
32 let data = ctx.accounts.buffer.try_borrow_data()?;
33
34 if !data.is_empty() {
35 // make sure that the asset is uninitialized
36 require!(
37 data[0] == Discriminator::Uninitialized.into(),
38 AssetError::AlreadyInitialized,
39 "buffer"
40 );
41 }
42
43 drop(data);
44
45 // close the buffer account
46
47 close_program_account(ctx.accounts.buffer, ctx.accounts.recipient)
48}

Callers 1

process_instructionFunction · 0.85

Calls 2

close_program_accountFunction · 0.85
is_emptyMethod · 0.80

Tested by

no test coverage detected