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#[derive(Debug, Encode, Decode)]
49pub enum QueryError {
50 OcallError(OcallError),
52 BadOrigin,
54 RuntimeError(String),
56 InstanceNotFound,
58 NoResponse,
60 ServiceUnavailable,
62 Timeout,
64 InvalidSignature,
66 ContractNotFound,
68 DecodeError,
70 OtherError(String),
72 Unsupported,
74 InvalidContractExecResult,
76 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}