oasis_contract_sdk_types/
message.rs1#[non_exhaustive]
5#[derive(Clone, Debug, cbor::Encode, cbor::Decode)]
6pub enum Message {
7 #[cbor(rename = "call")]
14 Call {
15 #[cbor(optional)]
16 id: u64,
17 reply: NotifyReply,
18 method: String,
19 body: cbor::Value,
20 #[cbor(optional)]
21 max_gas: Option<u64>,
22 #[cbor(optional)]
23 data: Option<cbor::Value>,
24 },
25}
26
27#[derive(Clone, Copy, Debug, PartialEq, Eq, cbor::Encode, cbor::Decode)]
29#[repr(u8)]
30pub enum NotifyReply {
31 Never = 0,
32 OnError = 1,
33 OnSuccess = 2,
34 Always = 3,
35}
36
37#[non_exhaustive]
39#[derive(Clone, Debug, cbor::Encode, cbor::Decode)]
40pub enum Reply {
41 #[cbor(rename = "call")]
43 Call {
44 #[cbor(optional)]
45 id: u64,
46 result: CallResult,
47 #[cbor(optional)]
48 data: Option<cbor::Value>,
49 },
50}
51
52#[derive(Clone, Debug, cbor::Encode, cbor::Decode)]
54pub enum CallResult {
55 #[cbor(rename = "ok")]
56 Ok(cbor::Value),
57
58 #[cbor(rename = "fail")]
59 Failed { module: String, code: u32 },
60}
61
62impl CallResult {
63 pub fn is_success(&self) -> bool {
65 match self {
66 CallResult::Ok(_) => true,
67 CallResult::Failed { .. } => false,
68 }
69 }
70}
71
72#[cfg(feature = "oasis-runtime-sdk")]
73impl From<oasis_runtime_sdk::module::CallResult> for CallResult {
74 fn from(r: oasis_runtime_sdk::module::CallResult) -> Self {
75 match r {
76 oasis_runtime_sdk::module::CallResult::Ok(value) => Self::Ok(value),
77 oasis_runtime_sdk::module::CallResult::Failed { module, code, .. } => {
78 Self::Failed { module, code }
79 }
80 oasis_runtime_sdk::module::CallResult::Aborted(err) => {
81 use oasis_runtime_sdk::error::Error;
82
83 Self::Failed {
84 module: err.module_name().to_string(),
85 code: err.code(),
86 }
87 }
88 }
89 }
90}