Skip to main content

thruput_xdr/
syscall_error.rs

1// Generated by xdrc 0.18.0 (xdrs d7777c37264da66eb41f8139bd539c4aa049fcc5). Do not edit.
2
3// clang-format off
4
5#![allow(non_camel_case_types)]
6#![allow(non_snake_case)]
7#![allow(non_upper_case_globals)]
8#![allow(unused_imports)]
9#![allow(dead_code)]
10#![allow(unused_variables)]
11#![allow(clippy::unnecessary_cast)]
12use crate::*;
13use core::ops::{Deref, DerefMut};
14use core::option::Option;
15#[cfg(feature = "std")]
16use std::io::{Read, Write};
17#[cfg(feature = "xdrs")]
18use xdrs::*;
19#[cfg(feature = "serde")]
20use ::serde::{Deserialize, Serialize};
21
22// clang-format on
23// triple slash comments are added to the generated rust docs
24/// Error codes returned by system calls.
25/// Each syscall can return a specific subset of these error codes.
26/// Check the syscalls.yaml documentation for which errors each syscall can return.
27#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
28#[cfg_attr(feature = "xdrs", derive(ReadXDR, WriteXDR, ConstXDRSize))]
29#[cfg_attr(feature = "serde", serde(transparent))]
30#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
31#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
32#[derive(Copy)]
33#[repr(transparent)]
34pub struct SyscallErrorCode(pub i32);
35
36impl SyscallErrorCode {
37    /// No error
38    pub const kSyscallErrorCodeNone: Self = Self(0);
39    /// Out of bounds pointer to contract memory passed to syscall
40    pub const kSyscallErrorCodeFault: Self = Self(1);
41    /// System call for supplied number is not supported
42    pub const kSyscallErrorCodeNoSyscall: Self = Self(2);
43    /// Cannot call get_msg_sender on root invocation
44    pub const kSyscallErrorCodeIsRootTransaction: Self = Self(3);
45    /// Reentrance guard violation
46    pub const kSyscallErrorCodeReentrance: Self = Self(4);
47    /// Attempt made to deploy a contract twice (same nonce and contract hash, from
48    /// same address)
49    pub const kSyscallErrorCodeContractAlreadyDeployed: Self = Self(5);
50    /// No return buffer is available.  Either the most recent subcall faulted, or
51    /// there have been no subcalls within this call frame.
52    pub const kSyscallErrorCodeNoReturnBufferAvailable: Self = Self(6);
53    /// Invalid input to a syscall, such as subtracting below 0 on an nnint
54    /// or a bytestring that is too long
55    pub const kSyscallErrorCodeInvalidSyscallInput: Self = Self(7);
56    /// Accessing a storage key that does not exist in the current view
57    pub const kSyscallErrorCodeStorageKeyNotExist: Self = Self(8);
58    /// No entry in the retrocausal queue to consume
59    pub const kSyscallErrorCodeNoRetrocausalQueueEntry: Self = Self(9);
60    /// The transaction has reached its per-transaction limit on concurrent
61    /// retrocausal-queue reads (kMaxConcurrentRcqReadsPerTx). This is a resource
62    /// limit, not a malformed call, and does not by itself fail the transaction;
63    /// a contract may use it as a stop condition (e.g. drain a queue until it
64    /// returns this).
65    pub const kSyscallErrorCodeRetrocausalQueueReadLimitReached: Self = Self(10);
66    /// The invocation would exceed the network's cross-invoke depth bound
67    /// (kConfigParamMaxCrossInvokeDepth), which limits how many invocation
68    /// frames one transaction may hold open at once. Like the retrocausal-queue
69    /// read limit this is a resource limit, not a malformed call: the same
70    /// invocation succeeds from a shallower frame. It is reported before any
71    /// child frame runs, so the syscall is a complete no-op and the caller's
72    /// invoke outputs are left untouched.
73    pub const kSyscallErrorCodeInvokeDepthExceeded: Self = Self(11);
74}
75
76impl From<i32> for SyscallErrorCode {
77    fn from(v: i32) -> Self {
78        Self(v)
79    }
80}
81
82#[cfg(feature = "xdrs")]
83impl xdrs::XDRDiscriminant for SyscallErrorCode {
84    const ENCODING: xdrs::DiscriminantEncoding = xdrs::DiscriminantEncoding::Signed;
85    fn discriminant(&self) -> i32 {
86        self.0
87    }
88    fn from_discriminant(d: i32) -> Self {
89        Self(d)
90    }
91}
92
93#[cfg(feature = "std")]
94impl core::fmt::Display for SyscallErrorCode {
95    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
96        match self.0 {
97            x if x == Self::kSyscallErrorCodeNone.0 => {
98                f.write_str("SyscallErrorCode::kSyscallErrorCodeNone")
99            }
100            x if x == Self::kSyscallErrorCodeFault.0 => {
101                f.write_str("SyscallErrorCode::kSyscallErrorCodeFault")
102            }
103            x if x == Self::kSyscallErrorCodeNoSyscall.0 => {
104                f.write_str("SyscallErrorCode::kSyscallErrorCodeNoSyscall")
105            }
106            x if x == Self::kSyscallErrorCodeIsRootTransaction.0 => {
107                f.write_str("SyscallErrorCode::kSyscallErrorCodeIsRootTransaction")
108            }
109            x if x == Self::kSyscallErrorCodeReentrance.0 => {
110                f.write_str("SyscallErrorCode::kSyscallErrorCodeReentrance")
111            }
112            x if x == Self::kSyscallErrorCodeContractAlreadyDeployed.0 => {
113                f.write_str("SyscallErrorCode::kSyscallErrorCodeContractAlreadyDeployed")
114            }
115            x if x == Self::kSyscallErrorCodeNoReturnBufferAvailable.0 => {
116                f.write_str("SyscallErrorCode::kSyscallErrorCodeNoReturnBufferAvailable")
117            }
118            x if x == Self::kSyscallErrorCodeInvalidSyscallInput.0 => {
119                f.write_str("SyscallErrorCode::kSyscallErrorCodeInvalidSyscallInput")
120            }
121            x if x == Self::kSyscallErrorCodeStorageKeyNotExist.0 => {
122                f.write_str("SyscallErrorCode::kSyscallErrorCodeStorageKeyNotExist")
123            }
124            x if x == Self::kSyscallErrorCodeNoRetrocausalQueueEntry.0 => {
125                f.write_str("SyscallErrorCode::kSyscallErrorCodeNoRetrocausalQueueEntry")
126            }
127            x if x == Self::kSyscallErrorCodeRetrocausalQueueReadLimitReached.0 => {
128                f.write_str(
129                    "SyscallErrorCode::kSyscallErrorCodeRetrocausalQueueReadLimitReached",
130                )
131            }
132            x if x == Self::kSyscallErrorCodeInvokeDepthExceeded.0 => {
133                f.write_str("SyscallErrorCode::kSyscallErrorCodeInvokeDepthExceeded")
134            }
135            _ => write!(f, "SyscallErrorCode({})", self.0),
136        }
137    }
138}