Skip to main content

thruput_trace/
ffi_enums.rs

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