1
pub mod channel_instruction_generated;
2
pub mod claim_v1_generated;
3
pub mod deploy_v1_generated;
4
pub mod execution_request_v1_generated;
5
pub mod input_type_generated;
6
pub mod status_v1_generated;
7
use std::fmt::Display;
8

            
9
use error::ChannelSchemaError;
10
use num_derive::{FromPrimitive, ToPrimitive};
11
pub mod error;
12
pub use channel_instruction_generated::*;
13
pub use claim_v1_generated::*;
14
pub use deploy_v1_generated::*;
15
pub use execution_request_v1_generated::*;
16
pub use input_type_generated::*;
17
pub use status_v1_generated::*;
18
pub fn parse_ix_data(ix_data: &[u8]) -> Result<ChannelInstruction, ChannelSchemaError> {
19
    let instruction =
20
        root_as_channel_instruction(ix_data).map_err(|_| ChannelSchemaError::InvalidInstruction)?;
21
    Ok(instruction)
22
}
23

            
24
#[derive(ToPrimitive, FromPrimitive, PartialEq)]
25
#[repr(u8)]
26
pub enum ExitCode {
27
    Success = 0,
28
    VerifyError = 1,
29
    ProvingError = 2,
30
    InputError = 3,
31
    Expired = 4,
32
}
33

            
34
impl Display for ExitCode {
35
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
36
        match self {
37
            ExitCode::Success => write!(f, "Success"),
38
            ExitCode::VerifyError => write!(f, "VerifyError"),
39
            ExitCode::ProvingError => write!(f, "ProvingError"),
40
            ExitCode::InputError => write!(f, "InputError"),
41
            ExitCode::Expired => write!(f, "Expired"),
42
        }
43
    }
44
}
45

            
46
impl InputT {
47
    pub const fn new(input_type: InputType, data: Option<Vec<u8>>) -> Self {
48
        Self { input_type, data }
49
    }
50

            
51
80
    pub const fn public(data: Vec<u8>) -> Self {
52
80
        Self {
53
80
            input_type: InputType::PublicData,
54
80
            data: Some(data),
55
80
        }
56
80
    }
57
    pub const fn private(data: Vec<u8>) -> Self {
58
        Self {
59
            input_type: InputType::Private,
60
            data: Some(data),
61
        }
62
    }
63
    pub const fn public_proof(data: Vec<u8>) -> Self {
64
        Self {
65
            input_type: InputType::PublicProof,
66
            data: Some(data),
67
        }
68
    }
69
    pub const fn url(data: Vec<u8>) -> Self {
70
        Self {
71
            input_type: InputType::PublicUrl,
72
            data: Some(data),
73
        }
74
    }
75
    pub const fn public_account(data: Vec<u8>) -> Self {
76
        Self {
77
            input_type: InputType::PublicAccountData,
78
            data: Some(data),
79
        }
80
    }
81
}