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

Function process_transfer

programs/proxy/src/processor/transfer.rs:17–103  ·  view source on GitHub ↗
(
    _program_id: &Pubkey,
    ctx: nifty_asset_interface::accounts::Context<'a, TransferAccounts<'a>>,
)

Source from the content-addressed store, hash-verified

15use crate::processor::{CONTENT_TYPE, IMAGE};
16
17pub fn process_transfer<'a>(
18 _program_id: &Pubkey,
19 ctx: nifty_asset_interface::accounts::Context<'a, TransferAccounts<'a>>,
20) -> ProgramResult {
21 // account validation happends on the CPI
22
23 let data = (*ctx.accounts.asset.data).borrow();
24 fetch_proxy_data!(
25 &data,
26 signer,
27 _authority,
28 nifty_asset_program,
29 ctx.remaining_accounts
30 );
31
32 // update the transfers "counter"
33
34 let attributes = Asset::get::<Attributes>(&data).unwrap();
35 let current: i64 = attributes
36 .get("transfers")
37 .unwrap_or("0")
38 .trim()
39 .parse()
40 .map_err(|error| {
41 msg!("[ERROR] {:?}", error);
42 ProgramError::InvalidAccountData
43 })?;
44
45 drop(data);
46
47 let data = AttributesBuilder::with_capacity(25)
48 .add("transfers", &format!("{:>12}", current + 1))
49 .data();
50
51 UpdateCpiBuilder::new(nifty_asset_program)
52 .asset(ctx.accounts.asset)
53 .authority(ctx.accounts.asset)
54 .extension(ExtensionInput {
55 extension_type: ExtensionType::Attributes,
56 length: data.len() as u32,
57 data: Some(data),
58 })
59 .invoke_signed(&[&signer])?;
60
61 // updates the blob (image)
62
63 let timestamp = Clock::get()?.unix_timestamp;
64 let mut buffer: [u8; 3] = [0; 3];
65 buffer.copy_from_slice(
66 &hashv(&[
67 &ctx.accounts.asset.key.to_bytes(),
68 &timestamp.to_le_bytes(),
69 &current.to_le_bytes(),
70 ])
71 .as_ref()[..3],
72 );
73
74 let data = BlobBuilder::with_capacity(2000)

Callers 1

process_instructionFunction · 0.70

Calls 11

getMethod · 0.45
dataMethod · 0.45
addMethod · 0.45
invoke_signedMethod · 0.45
extensionMethod · 0.45
authorityMethod · 0.45
assetMethod · 0.45
set_dataMethod · 0.45
as_bytesMethod · 0.45
recipientMethod · 0.45
signerMethod · 0.45

Tested by

no test coverage detected