wapo_env/
messages.rs

1use scale::{Decode, Encode};
2
3use crate::OcallError;
4
5pub type AccountId = [u8; 32];
6pub type H256 = [u8; 32];
7
8#[derive(Encode, Decode)]
9pub struct QueryRequest {
10    pub origin: Option<AccountId>,
11    pub payload: Vec<u8>,
12    pub reply_tx: i32,
13}
14
15#[derive(Encode, Decode, Debug)]
16pub struct HttpHead {
17    pub method: String,
18    pub url: String,
19    pub headers: Vec<(String, String)>,
20}
21
22impl HttpHead {
23    pub fn get_header(&self, key: &str) -> Option<&str> {
24        let key = key.to_ascii_lowercase();
25        for (k, v) in &self.headers {
26            if k.to_ascii_lowercase() == key {
27                return Some(v);
28            }
29        }
30        None
31    }
32}
33
34#[derive(Encode, Decode, Debug)]
35pub struct HttpRequest {
36    pub head: HttpHead,
37    pub response_tx: i32,
38    pub io_stream: i32,
39}
40
41#[derive(Encode, Decode, Debug)]
42pub struct HttpResponseHead {
43    pub status: u16,
44    pub headers: Vec<(String, String)>,
45}
46
47/// Errors that may occur during the contract query.
48#[derive(Debug, Encode, Decode)]
49pub enum QueryError {
50    /// Ocall error.
51    OcallError(OcallError),
52    /// The origin is invalid.
53    BadOrigin,
54    /// An error occurred during the contract execution.
55    RuntimeError(String),
56    /// The instance is not found.
57    InstanceNotFound,
58    /// No response received from the contract. Maybe the contract was panicked during execution.
59    NoResponse,
60    /// The contract is busy and cannot process the request.
61    ServiceUnavailable,
62    /// The request is timeout.
63    Timeout,
64    /// Signature is invalid.
65    InvalidSignature,
66    /// No such contract.
67    ContractNotFound,
68    /// Unable to decode the request data.
69    DecodeError,
70    /// Other errors reported during the contract query execution.
71    OtherError(String),
72    /// The operation is unsupported.
73    Unsupported,
74    /// Failed to decode the ContractExecResult.
75    InvalidContractExecResult,
76    /// Error reported by the pink runtime.
77    DispatchError(String),
78}
79
80impl From<OcallError> for QueryError {
81    fn from(err: OcallError) -> Self {
82        Self::OcallError(err)
83    }
84}
85
86#[derive(Encode, Decode)]
87pub enum QueryResponse {
88    OutputWithGasEstimation {
89        output: Vec<u8>,
90        gas_consumed: u64,
91        gas_required: u64,
92        storage_deposit_value: u128,
93        storage_deposit_is_charge: bool,
94    },
95    SimpleOutput(Vec<u8>),
96}