rathe_storage_program/
instruction.rs

1use borsh::{BorshDeserialize, BorshSerialize};
2use solana_program::{
3    instruction::{AccountMeta, Instruction},
4    pubkey::Pubkey,
5    sysvar,
6};
7
8#[derive(BorshSerialize, BorshDeserialize)]
9pub enum StorageInstruction {
10    InitializeStorage { value: i32 },
11    UpdateStorage { value: i32 },
12    SpoilStorage,
13    DestroyStorage,
14}
15
16impl StorageInstruction {
17    pub fn initialize_storage(payer: &Pubkey, storage: &Pubkey, value: i32) -> Instruction {
18        let accounts = vec![
19            AccountMeta::new_readonly(*payer, true),
20            AccountMeta::new(*storage, false),
21            AccountMeta::new_readonly(sysvar::rent::id(), false),
22        ];
23        let initialize_storage = StorageInstruction::InitializeStorage { value };
24        Instruction::new_with_borsh(crate::id(), &initialize_storage, accounts)
25    }
26
27    pub fn update_storage(owner: &Pubkey, storage: &Pubkey, value: i32) -> Instruction {
28        let accounts = vec![
29            AccountMeta::new_readonly(*owner, true),
30            AccountMeta::new(*storage, false),
31        ];
32        let update_storage = StorageInstruction::UpdateStorage { value };
33        Instruction::new_with_borsh(crate::id(), &update_storage, accounts)
34    }
35
36    pub fn spoil_storage(owner: &Pubkey, storage: &Pubkey) -> Instruction {
37        let accounts = vec![
38            AccountMeta::new_readonly(*owner, true),
39            AccountMeta::new(*storage, false),
40        ];
41        let spoil_storage = StorageInstruction::SpoilStorage;
42        Instruction::new_with_borsh(crate::id(), &spoil_storage, accounts)
43    }
44
45    pub fn destroy_storage(owner: &Pubkey, storage: &Pubkey) -> Instruction {
46        let accounts = vec![
47            AccountMeta::new_readonly(*owner, true),
48            AccountMeta::new(*storage, false),
49        ];
50        let destroy_storage = StorageInstruction::DestroyStorage;
51        Instruction::new_with_borsh(crate::id(), &destroy_storage, accounts)
52    }
53}