#![no_std]
mod flags;
pub use flags::*;
#[cfg(target_arch = "wasm32")]
mod host;
#[cfg(target_arch = "wasm32")]
pub use host::*;
macro_rules! define_error_codes {
(
$(
$( #[$attr:meta] )*
$name:ident = $discr:literal,
)*
) => {
#[derive(Debug, PartialEq, Eq)]
#[repr(u8)]
pub enum ReturnErrorCode {
Success = 0,
$(
$( #[$attr] )*
$name = $discr,
)*
Unknown,
}
impl From<ReturnCode> for Result {
fn from(return_code: ReturnCode) -> Self {
match return_code.0 {
0 => Ok(()),
$(
$discr => Err(ReturnErrorCode::$name),
)*
_ => Err(ReturnErrorCode::Unknown),
}
}
}
};
}
impl From<ReturnErrorCode> for u32 {
fn from(code: ReturnErrorCode) -> u32 {
code as u32
}
}
define_error_codes! {
CalleeTrapped = 1,
CalleeReverted = 2,
KeyNotFound = 3,
_BelowSubsistenceThreshold = 4,
TransferFailed = 5,
_EndowmentTooLow = 6,
CodeNotFound = 7,
NotCallable = 8,
LoggingDisabled = 9,
CallRuntimeFailed = 10,
EcdsaRecoveryFailed = 11,
Sr25519VerifyFailed = 12,
XcmExecutionFailed = 13,
XcmSendFailed = 14,
}
#[repr(transparent)]
pub struct ReturnCode(u32);
const SENTINEL: u32 = u32::MAX;
impl From<ReturnCode> for Option<u32> {
fn from(code: ReturnCode) -> Self {
(code.0 < SENTINEL).then_some(code.0)
}
}
impl ReturnCode {
pub fn into_u32(self) -> u32 {
self.0
}
pub fn into_bool(self) -> bool {
self.0.ne(&0)
}
}
type Result = core::result::Result<(), ReturnErrorCode>;