bokken_runtime/
debug_env.rs1use std::collections::HashMap;
2
3use borsh::{BorshSerialize, BorshDeserialize};
4use solana_program::{pubkey::Pubkey, instruction::AccountMeta, program_error::ProgramError};
5
6#[derive(PartialEq, Eq, Debug, Clone, BorshSerialize, BorshDeserialize, Default)]
8pub struct BokkenAccountData {
9 pub lamports: u64,
11 pub data: Vec<u8>,
12 pub owner: Pubkey,
13 pub executable: bool,
14 pub rent_epoch: u64
15}
16impl BokkenAccountData {
17 pub fn move_lamports<'a>(&'a mut self, to: &'a mut Self, amount: u64) -> Result<(), ProgramError> {
18 if self.lamports < amount {
19 return Err(ProgramError::InsufficientFunds)
20 }
21 self.lamports -= amount;
22 to.lamports += amount;
23 Ok(())
24 }
25}
26
27#[derive(Debug, Default, PartialEq, Clone, BorshSerialize, BorshDeserialize)]
29pub struct BorshAccountMeta {
30 pub pubkey: Pubkey,
32 pub is_signer: bool,
34 pub is_writable: bool,
36}
37impl From<&AccountMeta> for BorshAccountMeta {
38 fn from(meta: &AccountMeta) -> Self {
39 Self {
40 pubkey: meta.pubkey,
41 is_signer: meta.is_signer,
42 is_writable: meta.is_writable
43 }
44 }
45}
46impl From<AccountMeta> for BorshAccountMeta {
47 fn from(meta: AccountMeta) -> Self {
48 Self {
49 pubkey: meta.pubkey,
50 is_signer: meta.is_signer,
51 is_writable: meta.is_writable
52 }
53 }
54}
55impl From<BorshAccountMeta> for AccountMeta {
56 fn from(meta: BorshAccountMeta) -> Self {
57 Self {
58 pubkey: meta.pubkey,
59 is_signer: meta.is_signer,
60 is_writable: meta.is_writable
61 }
62 }
63}
64
65
66#[derive(Debug, BorshSerialize, BorshDeserialize)]
68pub enum BokkenRuntimeMessage {
69 Log {
70 nonce: u64,
71 message: String
72 },
73 Executed {
74 nonce: u64,
75 return_code: u64,
76 account_datas: HashMap<Pubkey, BokkenAccountData>
77 },
78 CrossProgramInvoke {
79 nonce: u64,
80 program_id: Pubkey,
81 instruction: Vec<u8>,
82 account_metas: Vec<BorshAccountMeta>,
83 account_datas: HashMap<Pubkey, BokkenAccountData>,
84 call_depth: u8
85 }
86}
87
88#[derive(Debug, BorshSerialize, BorshDeserialize)]
90pub enum BokkenValidatorMessage {
91 Invoke {
92 nonce: u64,
93 program_id: Pubkey,
94 instruction: Vec<u8>,
95 account_metas: Vec<BorshAccountMeta>,
96 account_datas: HashMap<Pubkey, BokkenAccountData>,
97 call_depth: u8
98 },
99 CrossProgramInvokeResult {
100 nonce: u64,
101 return_code: u64,
102 account_datas: HashMap<Pubkey, BokkenAccountData>
103 }
104}