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, Debug, PartialEq, Eq, cbor::Encode, cbor::Decode)]
72#[repr(u8)]
73#[cbor(with_default)]
74pub enum CallFormat {
75 Plain = 0,
77 EncryptedX25519DeoxysII = 1,
79}
80
81impl CallFormat {
82 fn is_plain(&self) -> bool {
83 matches!(self, CallFormat::Plain)
84 }
85}
86
87impl Default for CallFormat {
88 fn default() -> Self {
89 Self::Plain
90 }
91}
92
93#[cfg(feature = "oasis-runtime-sdk")]
94impl From<oasis_runtime_sdk::types::transaction::CallFormat> for CallFormat {
95 fn from(a: oasis_runtime_sdk::types::transaction::CallFormat) -> Self {
96 use oasis_runtime_sdk::types::transaction::CallFormat as RuntimeCallFormat;
97
98 match a {
99 RuntimeCallFormat::Plain => Self::Plain,
100 RuntimeCallFormat::EncryptedX25519DeoxysII => Self::EncryptedX25519DeoxysII,
101 }
102 }
103}
104
105#[derive(Debug, Default, cbor::Decode, cbor::Encode)]
110pub struct ExecutionContext {
111 pub instance_id: InstanceId,
113 pub instance_address: address::Address,
115 pub caller_address: address::Address,
117 #[cbor(optional)]
119 pub deposited_tokens: Vec<token::BaseUnits>,
120 #[cbor(optional)]
125 pub read_only: bool,
126 #[cbor(optional, skip_serializing_if = "CallFormat::is_plain")]
128 pub call_format: CallFormat,
129}
130
131#[derive(Clone, Debug, cbor::Encode, cbor::Decode)]
133pub enum ExecutionResult {
134 #[cbor(rename = "ok")]
135 Ok(ExecutionOk),
136
137 #[cbor(rename = "fail")]
138 Failed {
139 #[cbor(optional)]
140 module: String,
141
142 code: u32,
143
144 #[cbor(optional)]
145 message: String,
146 },
147}
148
149#[derive(Clone, Debug, Default, cbor::Encode, cbor::Decode)]
151pub struct ExecutionOk {
152 pub data: Vec<u8>,
154 #[cbor(optional)]
156 pub messages: Vec<message::Message>,
157 #[cbor(optional)]
159 pub events: Vec<event::Event>,
160}