pub mod address;
pub mod crypto;
pub mod env;
pub mod event;
pub mod message;
pub mod modules;
pub mod storage;
pub mod token;
pub mod testing;
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, cbor::Decode, cbor::Encode)]
#[cbor(transparent)]
pub struct CodeId(u64);
impl CodeId {
pub fn as_u64(&self) -> u64 {
self.0
}
pub fn increment(&self) -> Self {
CodeId(self.0 + 1)
}
pub fn to_storage_key(self) -> [u8; 8] {
self.0.to_be_bytes()
}
}
impl From<u64> for CodeId {
fn from(v: u64) -> Self {
CodeId(v)
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, cbor::Decode, cbor::Encode)]
#[cbor(transparent)]
pub struct InstanceId(u64);
impl InstanceId {
pub fn as_u64(&self) -> u64 {
self.0
}
pub fn increment(&self) -> Self {
InstanceId(self.0 + 1)
}
pub fn to_storage_key(self) -> [u8; 8] {
self.0.to_be_bytes()
}
}
impl From<u64> for InstanceId {
fn from(v: u64) -> Self {
InstanceId(v)
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, cbor::Encode, cbor::Decode)]
#[repr(u8)]
#[cbor(with_default)]
pub enum CallFormat {
Plain = 0,
EncryptedX25519DeoxysII = 1,
}
impl CallFormat {
fn is_plain(&self) -> bool {
matches!(self, CallFormat::Plain)
}
}
impl Default for CallFormat {
fn default() -> Self {
Self::Plain
}
}
#[cfg(feature = "oasis-runtime-sdk")]
impl From<oasis_runtime_sdk::types::transaction::CallFormat> for CallFormat {
fn from(a: oasis_runtime_sdk::types::transaction::CallFormat) -> Self {
use oasis_runtime_sdk::types::transaction::CallFormat as RuntimeCallFormat;
match a {
RuntimeCallFormat::Plain => Self::Plain,
RuntimeCallFormat::EncryptedX25519DeoxysII => Self::EncryptedX25519DeoxysII,
}
}
}
#[derive(Debug, Default, cbor::Decode, cbor::Encode)]
pub struct ExecutionContext {
pub instance_id: InstanceId,
pub instance_address: address::Address,
pub caller_address: address::Address,
#[cbor(optional)]
pub deposited_tokens: Vec<token::BaseUnits>,
#[cbor(optional)]
pub read_only: bool,
#[cbor(optional, skip_serializing_if = "CallFormat::is_plain")]
pub call_format: CallFormat,
}
#[derive(Clone, Debug, cbor::Encode, cbor::Decode)]
pub enum ExecutionResult {
#[cbor(rename = "ok")]
Ok(ExecutionOk),
#[cbor(rename = "fail")]
Failed {
#[cbor(optional)]
module: String,
code: u32,
#[cbor(optional)]
message: String,
},
}
#[derive(Clone, Debug, Default, cbor::Encode, cbor::Decode)]
pub struct ExecutionOk {
pub data: Vec<u8>,
#[cbor(optional)]
pub messages: Vec<message::Message>,
#[cbor(optional)]
pub events: Vec<event::Event>,
}