#[non_exhaustive]
#[derive(Clone, Debug, cbor::Encode, cbor::Decode)]
pub enum Message {
#[cbor(rename = "call")]
Call {
#[cbor(optional)]
id: u64,
reply: NotifyReply,
method: String,
body: cbor::Value,
#[cbor(optional)]
max_gas: Option<u64>,
#[cbor(optional)]
data: Option<cbor::Value>,
},
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, cbor::Encode, cbor::Decode)]
#[repr(u8)]
pub enum NotifyReply {
Never = 0,
OnError = 1,
OnSuccess = 2,
Always = 3,
}
#[non_exhaustive]
#[derive(Clone, Debug, cbor::Encode, cbor::Decode)]
pub enum Reply {
#[cbor(rename = "call")]
Call {
#[cbor(optional)]
id: u64,
result: CallResult,
#[cbor(optional)]
data: Option<cbor::Value>,
},
}
#[derive(Clone, Debug, cbor::Encode, cbor::Decode)]
pub enum CallResult {
#[cbor(rename = "ok")]
Ok(cbor::Value),
#[cbor(rename = "fail")]
Failed { module: String, code: u32 },
}
impl CallResult {
pub fn is_success(&self) -> bool {
match self {
CallResult::Ok(_) => true,
CallResult::Failed { .. } => false,
}
}
}
#[cfg(feature = "oasis-runtime-sdk")]
impl From<oasis_runtime_sdk::module::CallResult> for CallResult {
fn from(r: oasis_runtime_sdk::module::CallResult) -> Self {
match r {
oasis_runtime_sdk::module::CallResult::Ok(value) => Self::Ok(value),
oasis_runtime_sdk::module::CallResult::Failed { module, code, .. } => {
Self::Failed { module, code }
}
oasis_runtime_sdk::module::CallResult::Aborted(err) => {
use oasis_runtime_sdk::error::Error;
Self::Failed {
module: err.module_name().to_string(),
code: err.code(),
}
}
}
}
}