Skip to main content

magicblock_magic_program_api/
response.rs

1use serde::{Deserialize, Serialize};
2use solana_signature::Signature;
3
4#[derive(Debug, Clone, Serialize, Deserialize)]
5pub enum MagicResponse {
6    V1(MagicResponseV1),
7}
8
9impl MagicResponse {
10    pub fn ok(&self) -> bool {
11        match self {
12            Self::V1(value) => value.ok,
13        }
14    }
15
16    pub fn data(&self) -> &[u8] {
17        match self {
18            Self::V1(value) => &value.data,
19        }
20    }
21
22    pub fn error(&self) -> &String {
23        match self {
24            Self::V1(value) => &value.error,
25        }
26    }
27}
28
29#[derive(Debug, Clone, Serialize, Deserialize)]
30pub struct MagicResponseV1 {
31    pub ok: bool,
32    /// Data user specified as payload for callback
33    /// Present even in case of an error
34    pub data: Vec<u8>,
35    /// Reason for callback execution with ok = false
36    /// TimeoutError/ActionError
37    pub error: String,
38    /// Action execution receipt entries
39    /// Present if signature of action tx is available
40    pub receipt: Option<ActionReceipt>,
41}
42
43#[derive(Debug, Clone, Serialize, Deserialize)]
44pub struct ActionReceipt {
45    /// action signature
46    pub signature: Signature,
47}