oasis_contract_sdk_types/
lib.rs1pub mod address;
4pub mod crypto;
5pub mod env;
6pub mod event;
7pub mod message;
8pub mod modules;
9pub mod storage;
10pub mod token;
11
12pub mod testing;
13
14#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, cbor::Decode, cbor::Encode)]
16#[cbor(transparent)]
17pub struct CodeId(u64);
18
19impl CodeId {
20 pub fn as_u64(&self) -> u64 {
22 self.0
23 }
24
25 pub fn increment(&self) -> Self {
27 CodeId(self.0 + 1)
28 }
29
30 pub fn to_storage_key(self) -> [u8; 8] {
32 self.0.to_be_bytes()
33 }
34}
35
36impl From<u64> for CodeId {
37 fn from(v: u64) -> Self {
38 CodeId(v)
39 }
40}
41
42#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, cbor::Decode, cbor::Encode)]
44#[cbor(transparent)]
45pub struct InstanceId(u64);
46
47impl InstanceId {
48 pub fn as_u64(&self) -> u64 {
50 self.0
51 }
52
53 pub fn increment(&self) -> Self {
55 InstanceId(self.0 + 1)
56 }
57
58 pub fn to_storage_key(self) -> [u8; 8] {
60 self.0.to_be_bytes()
61 }
62}
63
64impl From<u64> for InstanceId {
65 fn from(v: u64) -> Self {
66 InstanceId(v)
67 }
68}
69
70#[derive(Clone, Copy, Default, Debug, PartialEq, Eq, cbor::Encode, cbor::Decode)]
72#[repr(u8)]
73#[cbor(with_default)]
74pub enum CallFormat {
75 #[default]
77 Plain = 0,
78 EncryptedX25519DeoxysII = 1,
80}
81
82impl CallFormat {
83 fn is_plain(&self) -> bool {
84 matches!(self, CallFormat::Plain)
85 }
86}
87
88#[cfg(feature = "oasis-runtime-sdk")]
89impl From<oasis_runtime_sdk::types::transaction::CallFormat> for CallFormat {
90 fn from(a: oasis_runtime_sdk::types::transaction::CallFormat) -> Self {
91 use oasis_runtime_sdk::types::transaction::CallFormat as RuntimeCallFormat;
92
93 match a {
94 RuntimeCallFormat::Plain => Self::Plain,
95 RuntimeCallFormat::EncryptedX25519DeoxysII => Self::EncryptedX25519DeoxysII,
96 }
97 }
98}
99
100#[derive(Debug, Default, cbor::Decode, cbor::Encode)]
105pub struct ExecutionContext {
106 pub instance_id: InstanceId,
108 pub instance_address: address::Address,
110 pub caller_address: address::Address,
112 #[cbor(optional)]
114 pub deposited_tokens: Vec<token::BaseUnits>,
115 #[cbor(optional)]
120 pub read_only: bool,
121 #[cbor(optional, skip_serializing_if = "CallFormat::is_plain")]
123 pub call_format: CallFormat,
124}
125
126#[derive(Clone, Debug, cbor::Encode, cbor::Decode)]
128pub enum ExecutionResult {
129 #[cbor(rename = "ok")]
130 Ok(ExecutionOk),
131
132 #[cbor(rename = "fail")]
133 Failed {
134 #[cbor(optional)]
135 module: String,
136
137 code: u32,
138
139 #[cbor(optional)]
140 message: String,
141 },
142}
143
144#[derive(Clone, Debug, Default, cbor::Encode, cbor::Decode)]
146pub struct ExecutionOk {
147 pub data: Vec<u8>,
149 #[cbor(optional)]
151 pub messages: Vec<message::Message>,
152 #[cbor(optional)]
154 pub events: Vec<event::Event>,
155}