Skip to main content

magicblock_magic_program_api/
response.rs

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