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

Function process_unlock

programs/asset/program/src/processor/unlock.rs:21–70  ·  view source on GitHub ↗

Unlocks an asset. ### Accounts: 0. `[writable]` asset 1. `[signer]` signer

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

Source from the content-addressed store, hash-verified

19/// 0. `[writable]` asset
20/// 1. `[signer]` signer
21pub fn process_unlock(program_id: &Pubkey, ctx: Context<Unlock>) -> ProgramResult {
22 // account validation
23
24 require!(
25 ctx.accounts.signer.is_signer(),
26 ProgramError::MissingRequiredSignature,
27 "signer"
28 );
29
30 require!(
31 ctx.accounts.asset.owner() == program_id,
32 ProgramError::IllegalOwner,
33 "asset"
34 );
35
36 let mut data = ctx.accounts.asset.try_borrow_mut_data()?;
37
38 require!(
39 data.len() >= Asset::LEN && data[0] == Discriminator::Asset.into(),
40 AssetError::Uninitialized,
41 "asset"
42 );
43
44 // unlocks the asset
45
46 let (asset, extensions) = data.split_at_mut(Asset::LEN);
47 let asset = Asset::load_mut(asset);
48 let manager = Extension::get::<Manager>(extensions).map(|s| s.delegate);
49
50 // Validate whether signer is the owner or a lock delegate.
51 //
52 // if the asset has a delegate, the signer must be the delegate or the manager
53 // delegate (if there is one)
54 if asset.delegate.value().is_some() {
55 assert_delegate(
56 &[asset.delegate.value(), manager],
57 ctx.accounts.signer.key(),
58 DelegateRole::Lock,
59 )?;
60 }
61 // otherwise, if the signer is not the owner, the signer must be the
62 // manager delegate
63 else if asset.owner != *ctx.accounts.signer.key() {
64 assert_delegate(&[manager], ctx.accounts.signer.key(), DelegateRole::Lock)?;
65 }
66
67 asset.state = State::Unlocked;
68
69 Ok(())
70}

Callers 1

process_instructionFunction · 0.85

Calls 3

assert_delegateFunction · 0.85
keyMethod · 0.80
is_someMethod · 0.45

Tested by

no test coverage detected