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