-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstate.rs
53 lines (41 loc) · 1.29 KB
/
state.rs
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
use crate::{
helpers::{get_bytes32_from_string, SerializeAndWriteToSolanaAccount},
instruction::{CreateMyAccountIx, CreateMyPdaAccountIx},
};
use borsh::{BorshDeserialize, BorshSerialize};
use shank::ShankAccount;
use solana_program::{account_info::AccountInfo, entrypoint::ProgramResult};
#[derive(BorshSerialize, BorshDeserialize, Debug, ShankAccount)]
pub struct MyAccount {
pub data: [u8; 32],
}
#[derive(BorshSerialize, BorshDeserialize, Debug, ShankAccount)]
pub struct MyPdaAccount {
pub data: [u8; 32],
}
impl SerializeAndWriteToSolanaAccount for MyAccount {}
impl SerializeAndWriteToSolanaAccount for MyPdaAccount {}
impl MyAccount {
pub fn size() -> u64 {
32
}
pub fn new(data: CreateMyAccountIx, new_acc: &AccountInfo) -> ProgramResult {
let my_account = MyAccount {
data: get_bytes32_from_string(data.data)?,
};
my_account.serialize_and_write_to_sol_acc(new_acc)?;
Ok(())
}
}
impl MyPdaAccount {
pub fn size() -> u64 {
32
}
pub fn new(data: CreateMyPdaAccountIx, new_acc: &AccountInfo) -> ProgramResult {
let my_account = MyPdaAccount {
data: get_bytes32_from_string(data.data)?,
};
my_account.serialize_and_write_to_sol_acc(new_acc)?;
Ok(())
}
}