common/
account.rs

1use pubkey::Pubkey;
2
3/// An Account with userdata that is stored on chain
4#[derive(Serialize, Deserialize, Debug, Clone, Default)]
5pub struct Account {
6    /// tokens in the account
7    pub tokens: i64,
8    /// user data
9    /// A transaction can write to its userdata
10    pub userdata: Vec<u8>,
11    /// contract id this contract belongs to
12    pub program_id: Pubkey,
13}
14
15impl Account {
16    pub fn new(tokens: i64, space: usize, program_id: Pubkey) -> Account {
17        Account {
18            tokens,
19            userdata: vec![0u8; space],
20            program_id,
21        }
22    }
23}
24
25#[derive(Debug)]
26pub struct KeyedAccount<'a> {
27    pub key: &'a Pubkey,
28    pub account: &'a mut Account,
29}