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
use pubkey::Pubkey;
#[repr(C)]
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct Account {
pub tokens: i64,
pub userdata: Vec<u8>,
pub program_id: Pubkey,
pub executable: bool,
pub loader_program_id: Pubkey,
}
impl Account {
pub fn new(tokens: i64, space: usize, program_id: Pubkey) -> Account {
Account {
tokens,
userdata: vec![0u8; space],
program_id,
executable: false,
loader_program_id: Pubkey::default(),
}
}
}
#[repr(C)]
#[derive(Debug)]
pub struct KeyedAccount<'a> {
pub key: &'a Pubkey,
pub account: &'a mut Account,
}
impl<'a> From<(&'a Pubkey, &'a mut Account)> for KeyedAccount<'a> {
fn from((key, account): (&'a Pubkey, &'a mut Account)) -> Self {
KeyedAccount { key, account }
}
}
impl<'a> From<&'a mut (Pubkey, Account)> for KeyedAccount<'a> {
fn from((key, account): &'a mut (Pubkey, Account)) -> Self {
KeyedAccount { key, account }
}
}
pub fn create_keyed_accounts(accounts: &mut [(Pubkey, Account)]) -> Vec<KeyedAccount> {
accounts.iter_mut().map(Into::into).collect()
}