-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathdelete.rs
More file actions
69 lines (56 loc) · 1.85 KB
/
delete.rs
File metadata and controls
69 lines (56 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
use crate::{
error::DoubleZeroError,
serializer::try_acc_close,
state::{globalstate::GlobalState, index::Index},
};
use borsh::BorshSerialize;
use borsh_incremental::BorshDeserializeIncremental;
use solana_program::{
account_info::{next_account_info, AccountInfo},
entrypoint::ProgramResult,
pubkey::Pubkey,
};
use std::fmt;
#[cfg(test)]
use solana_program::msg;
#[derive(BorshSerialize, BorshDeserializeIncremental, PartialEq, Clone, Default)]
pub struct IndexDeleteArgs {}
impl fmt::Debug for IndexDeleteArgs {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "IndexDeleteArgs")
}
}
pub fn process_delete_index(
program_id: &Pubkey,
accounts: &[AccountInfo],
_value: &IndexDeleteArgs,
) -> ProgramResult {
let accounts_iter = &mut accounts.iter();
let index_account = next_account_info(accounts_iter)?;
let globalstate_account = next_account_info(accounts_iter)?;
let payer_account = next_account_info(accounts_iter)?;
#[cfg(test)]
msg!("process_delete_index");
assert!(payer_account.is_signer, "Payer must be a signer");
// Validate accounts
assert_eq!(
index_account.owner, program_id,
"Invalid Index Account Owner"
);
assert_eq!(
globalstate_account.owner, program_id,
"Invalid GlobalState Account Owner"
);
assert!(index_account.is_writable, "Index Account is not writable");
// Check foundation allowlist
let globalstate = GlobalState::try_from(globalstate_account)?;
if !globalstate.foundation_allowlist.contains(payer_account.key) {
return Err(DoubleZeroError::NotAllowed.into());
}
// Verify it's actually an Index account
let _index = Index::try_from(index_account)?;
try_acc_close(index_account, payer_account)?;
#[cfg(test)]
msg!("Deleted Index account");
Ok(())
}