magicblock_magic_program_api/
args.rs1use serde::{Deserialize, Serialize};
2use solana_program::{account_info::AccountInfo, instruction::AccountMeta};
3
4use crate::Pubkey;
5
6#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
7pub struct ActionArgs {
8 pub escrow_index: u8,
9 pub data: Vec<u8>,
10}
11
12#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
13pub struct BaseActionArgs {
14 pub args: ActionArgs,
15 pub compute_units: u32, pub escrow_authority: u8, pub destination_program: Pubkey, pub accounts: Vec<ShortAccountMeta>, }
20
21#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
22pub enum CommitTypeArgs {
23 Standalone(Vec<u8>), WithBaseActions {
25 committed_accounts: Vec<u8>, base_actions: Vec<BaseActionArgs>,
27 },
28}
29
30impl CommitTypeArgs {
31 pub fn committed_accounts_indices(&self) -> &Vec<u8> {
32 match self {
33 Self::Standalone(value) => value,
34 Self::WithBaseActions {
35 committed_accounts, ..
36 } => committed_accounts,
37 }
38 }
39}
40
41#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
42pub enum UndelegateTypeArgs {
43 Standalone,
44 WithBaseActions { base_actions: Vec<BaseActionArgs> },
45}
46
47#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
48pub struct CommitAndUndelegateArgs {
49 pub commit_type: CommitTypeArgs,
50 pub undelegate_type: UndelegateTypeArgs,
51}
52
53impl CommitAndUndelegateArgs {
54 pub fn committed_accounts_indices(&self) -> &Vec<u8> {
55 self.commit_type.committed_accounts_indices()
56 }
57}
58
59#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
60pub enum MagicBaseIntentArgs {
61 BaseActions(Vec<BaseActionArgs>),
62 Commit(CommitTypeArgs),
63 CommitAndUndelegate(CommitAndUndelegateArgs),
64}
65
66#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
72pub struct ShortAccountMeta {
73 pub pubkey: Pubkey,
74 pub is_writable: bool,
77}
78impl From<AccountMeta> for ShortAccountMeta {
79 fn from(value: AccountMeta) -> Self {
80 Self {
81 pubkey: value.pubkey,
82 is_writable: value.is_writable,
83 }
84 }
85}
86
87impl<'a> From<AccountInfo<'a>> for ShortAccountMeta {
88 fn from(value: AccountInfo<'a>) -> Self {
89 Self::from(&value)
90 }
91}
92
93impl<'a> From<&AccountInfo<'a>> for ShortAccountMeta {
94 fn from(value: &AccountInfo<'a>) -> Self {
95 Self {
96 pubkey: *value.key,
97 is_writable: value.is_writable,
98 }
99 }
100}