thruput_trace/ffi_enums.rs
1// Generated by xdrc 0.18.0 (xdrs d7777c37264da66eb41f8139bd539c4aa049fcc5). Do not edit.
2
3#![allow(non_camel_case_types)]
4#![allow(non_snake_case)]
5#![allow(non_upper_case_globals)]
6#![allow(unused_imports)]
7#![allow(dead_code)]
8#![allow(unused_variables)]
9#![allow(clippy::unnecessary_cast)]
10use crate::*;
11use core::ops::{Deref, DerefMut};
12use core::option::Option;
13#[cfg(feature = "std")]
14use std::io::{Read, Write};
15use xdrs::*;
16#[cfg(feature = "serde")]
17use ::serde::{Deserialize, Serialize};
18
19// Error codes returned from a contract invocation.
20// This is the external interface to a smart contract. Normally wrapped in an
21// InvokeStatus<int32_t> (a std::expected).
22//
23// When InvokeStatus<int32_t> has an int32_t value (and an
24// InvokeErrorCode::None), the int32_t value represents a handleable
25// (deterministic) result from the invocation. (Specifically, the invoke()
26// syscall in a nested smart contract invocation passes an
27// {InvokeErrorCode::None, code} back as a
28// {HostFnErrorCode::NoneOrRecoverable, code}).
29//
30// This value is either the value returned by the contract's entry point, the
31// code caused by a host function returning HostFnErrorCode::Exit, or 0, if
32// invocation ends because a host function returns HostFnErrorCode::Return.
33#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
34#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
35#[cfg_attr(feature = "serde", serde(transparent))]
36#[derive(schemars::JsonSchema)]
37#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
38#[derive(Copy)]
39#[repr(transparent)]
40pub struct InvokeErrorCode(pub i32);
41
42impl InvokeErrorCode {
43 // A call frame can only succeed if this code is returned.
44 // All others revert the call frame.
45 pub const None: Self = Self(0);
46 // An unspecified deterministic error.
47 pub const Deterministic: Self = Self(1);
48 // Runtime exceeded its gas budget.
49 pub const OutOfGas: Self = Self(2);
50 // Nondeterministic error during invocation (e.g. malloc error)
51 // Signals a serious system issue or a serious bug in our code and should be
52 // diagnosed ASAP.
53 pub const Unrecoverable: Self = Self(3);
54 // Discovered during validation that the proposer submitted bad data.
55 // The transaction is aborted and consumes nothing, and execution continues
56 // with the rest of the batch, but the block fails validation and is
57 // rejected, as it is for any transaction whose result is not OK, a
58 // deterministic error or a root frame revert.
59 pub const ValidationFailure: Self = Self(4);
60 // The transaction was aborted due to an external reason (such as the current
61 // block being discarded),
62 // but this is not the result of a totally unrecoverable error. This is to be
63 // expected during normal system operation.
64 pub const Abandon: Self = Self(5);
65}
66
67impl From<i32> for InvokeErrorCode {
68 fn from(v: i32) -> Self {
69 Self(v)
70 }
71}
72
73impl xdrs::XDRDiscriminant for InvokeErrorCode {
74 const ENCODING: xdrs::DiscriminantEncoding = xdrs::DiscriminantEncoding::Signed;
75 fn discriminant(&self) -> i32 {
76 self.0
77 }
78 fn from_discriminant(d: i32) -> Self {
79 Self(d)
80 }
81}
82
83#[cfg(feature = "std")]
84impl core::fmt::Display for InvokeErrorCode {
85 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
86 match self.0 {
87 x if x == Self::None.0 => f.write_str("InvokeErrorCode::None"),
88 x if x == Self::Deterministic.0 => {
89 f.write_str("InvokeErrorCode::Deterministic")
90 }
91 x if x == Self::OutOfGas.0 => f.write_str("InvokeErrorCode::OutOfGas"),
92 x if x == Self::Unrecoverable.0 => {
93 f.write_str("InvokeErrorCode::Unrecoverable")
94 }
95 x if x == Self::ValidationFailure.0 => {
96 f.write_str("InvokeErrorCode::ValidationFailure")
97 }
98 x if x == Self::Abandon.0 => f.write_str("InvokeErrorCode::Abandon"),
99 _ => write!(f, "InvokeErrorCode({})", self.0),
100 }
101 }
102}
103
104// HostFunctionErrorCode categorizes errors returned from system calls. The
105// normal usage pattern is to wrap them within HostFnStatus<int32_t>, where the
106// int32 is the more detailed error code.
107//
108// A host function is one the contract runtime provides to the contract; system
109// calls are made through host functions.
110//
111// When a HostFnStatus<int32_t> (a wrapper around std::expected) has an int32_t
112// value, (and a HostFnErrorCode::NoneOrRecoverable), that int32_t is passed to
113// the contract as a handleable error code, as the return result from the host
114// function. The contract itself never sees the HostFnErrorCode. Other
115// HostFnErrorCodes terminate the contract (returning to the caller), and are
116// handled by the contract runtime.
117#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
118#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
119#[cfg_attr(feature = "serde", serde(transparent))]
120#[derive(schemars::JsonSchema)]
121#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
122#[derive(Copy)]
123#[repr(transparent)]
124pub struct HostFnErrorCode(pub i32);
125
126impl HostFnErrorCode {
127 pub const NoneOrRecoverable: Self = Self(0);
128 // Insufficient gas to continue contract execution.
129 //
130 // Result: the contract runtime immediately returns an
131 // InvokeErrorCode::OutOfGas.
132 pub const OutOfGas: Self = Self(1);
133 // Unrecoverable (nondeterministic) error, such as a malloc error.
134 // The only course of action is to abort the entire transaction.
135 //
136 // Result: the contract runtime immediately returns an
137 // InvokeErrorCode::Unrecoverable
138 // Signals a serious system issue or a serious bug in our code and should be
139 // diagnosed ASAP.
140 pub const Unrecoverable: Self = Self(2);
141 // Return from a contract invocation to the caller. Registers a byte
142 // buffer to be passed back to the caller.
143 //
144 // Result: Runtime immediately returns an {InvokeErrorCode::None, 0}.
145 pub const Return: Self = Self(3);
146 // Return from a contract invocation to the caller, with some (int32_t)
147 // error code.
148 //
149 // Result: Runtime immediately returns an {InvokeErrorCode::None, code}.
150 //
151 // On a root smart contract invocation, a nonzero code is converted to a
152 // InvokeErrorCode::Deterministic.
153 pub const Exit: Self = Self(4);
154 // Validation fails because a proposer submitted bad nondeterministic
155 // proposal data.
156 //
157 // Result: the contract runtime immediately returns an
158 // InvokeErrorCode::ValidationFailure
159 pub const ValidationFailure: Self = Self(5);
160 // The transaction was aborted due to an external reason (such as the current
161 // block being discarded), but this is not the result of a totally
162 // unrecoverable error. This is to be expected during normal system operation.
163 //
164 // Result: the contract runtime immediately returns an
165 // InvokeErrorCode::Abandon
166 pub const Abandon: Self = Self(6);
167}
168
169impl From<i32> for HostFnErrorCode {
170 fn from(v: i32) -> Self {
171 Self(v)
172 }
173}
174
175impl xdrs::XDRDiscriminant for HostFnErrorCode {
176 const ENCODING: xdrs::DiscriminantEncoding = xdrs::DiscriminantEncoding::Signed;
177 fn discriminant(&self) -> i32 {
178 self.0
179 }
180 fn from_discriminant(d: i32) -> Self {
181 Self(d)
182 }
183}
184
185#[cfg(feature = "std")]
186impl core::fmt::Display for HostFnErrorCode {
187 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
188 match self.0 {
189 x if x == Self::NoneOrRecoverable.0 => {
190 f.write_str("HostFnErrorCode::NoneOrRecoverable")
191 }
192 x if x == Self::OutOfGas.0 => f.write_str("HostFnErrorCode::OutOfGas"),
193 x if x == Self::Unrecoverable.0 => {
194 f.write_str("HostFnErrorCode::Unrecoverable")
195 }
196 x if x == Self::Return.0 => f.write_str("HostFnErrorCode::Return"),
197 x if x == Self::Exit.0 => f.write_str("HostFnErrorCode::Exit"),
198 x if x == Self::ValidationFailure.0 => {
199 f.write_str("HostFnErrorCode::ValidationFailure")
200 }
201 x if x == Self::Abandon.0 => f.write_str("HostFnErrorCode::Abandon"),
202 _ => write!(f, "HostFnErrorCode({})", self.0),
203 }
204 }
205}
206
207// General-purpose system error codes returned from within various executor operations.
208// These can be mapped into either InvokeErrorCode or HostFnErrorCode, depending on the context in which the
209// error occurs.
210#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
211#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
212#[cfg_attr(feature = "serde", serde(transparent))]
213#[derive(schemars::JsonSchema)]
214#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
215#[derive(Copy)]
216#[repr(transparent)]
217pub struct SystemErrorCode(pub i32);
218
219impl SystemErrorCode {
220 // Unrecoverable error (e.g. out of memory, or critical logic error).
221 // Only recourse is to abort entire transaction and possibly crash binary.
222 // Signals serious error, which we should investigate.
223 // This converts to InvokeErrorCode::Unrecoverable or HostFnErrorCode::Unrecoverable.
224 pub const Unrecoverable: Self = Self(1);
225 // Nondeterministic error that occurs during normal course of operation.
226 // E.g. a transaction is being executed concurrently with the whole block
227 // getting cancelled.
228 // Only recourse is to abort the entire transaction.
229 // This converts to InvokeErrorCode::Abandon or HostFnErrorCode::Abandon.
230 pub const Abandon: Self = Self(2);
231 // Failure during validation of a transaction. Signals that the whole
232 // block must be aborted.
233 // This converts to InvokeErrorCode::ValidationFailure or HostFnErrorCode::ValidationFailure.
234 pub const ValidationFailure: Self = Self(3);
235}
236
237impl From<i32> for SystemErrorCode {
238 fn from(v: i32) -> Self {
239 Self(v)
240 }
241}
242
243impl xdrs::XDRDiscriminant for SystemErrorCode {
244 const ENCODING: xdrs::DiscriminantEncoding = xdrs::DiscriminantEncoding::Signed;
245 fn discriminant(&self) -> i32 {
246 self.0
247 }
248 fn from_discriminant(d: i32) -> Self {
249 Self(d)
250 }
251}
252
253#[cfg(feature = "std")]
254impl core::fmt::Display for SystemErrorCode {
255 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
256 match self.0 {
257 x if x == Self::Unrecoverable.0 => {
258 f.write_str("SystemErrorCode::Unrecoverable")
259 }
260 x if x == Self::Abandon.0 => f.write_str("SystemErrorCode::Abandon"),
261 x if x == Self::ValidationFailure.0 => {
262 f.write_str("SystemErrorCode::ValidationFailure")
263 }
264 _ => write!(f, "SystemErrorCode({})", self.0),
265 }
266 }
267}