Skip to main content

thruput_spec/
contract_spec.rs

1// -*-Rust-*-
2// Generated Code: DO NOT CHECK IN
3
4// Generated from xdrc commit: 6ab835b07c234abb4b0b50b61d687904727a4f32
5
6// Thruput contract specification AST
7//
8// Excluded from goxdr in CI. protocol-rs generates its thruput-spec crate from
9// this file, and the SDK's contract-spec crate re-exports those types.
10
11#![allow(non_camel_case_types)]
12#![allow(non_snake_case)]
13#![allow(non_upper_case_globals)]
14#![allow(unused_imports)]
15#![allow(dead_code)]
16#![allow(unused_variables)]
17#![allow(clippy::unnecessary_cast)]
18
19use crate::*;
20use core::option::Option;
21use core::ops::{Deref, DerefMut};
22
23use xdrs::*;
24
25
26#[cfg(feature = "serde")]
27use ::serde::{{Serialize, Deserialize}};
28
29
30
31// RFC 4506: string types must declare a max length; `<>` is unbounded (max 2^32-1 bytes).
32pub type ContractSpecString = StringM;
33
34// ---------------------------------------------------------------------------
35// Spec ids
36// ---------------------------------------------------------------------------
37
38/// The identity of a user-defined type or event.
39///
40/// Every spec-named item — a `#[contract_type]`, a `#[contract_exception]`, a
41/// `#[derive(Event)]` — is named by one of these, and every reference to one
42/// resolves through it. A bare identifier cannot tell two of them apart: two
43/// crates, two modules of one crate, or two major versions of one crate may
44/// each declare a `Transfer`, and a spec naming both could not say which is
45/// which.
46///
47/// The segments are carried apart rather than joined into
48/// `CRATE@MAJOR::module::path::Name`, because the joined form cannot be split
49/// back. `name = "..."` on a spec-named item substitutes its value verbatim —
50/// a value carrying `::` spells its own segments and nothing rejects it — so
51/// the boundary between the module path and the declared name is not
52/// recoverable from the string. Consumers that need a display name or a
53/// target-language identifier read `declared` directly; how an id is shortened
54/// for display stays each codegen's business.
55#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
56#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
57#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
58#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
59#[repr(C)]
60pub struct ContractSpecId {
61    // Declaring crate, as Cargo names the package (`CARGO_PKG_NAME`, so
62    // hyphenated). This is the spelling event signatures already hash and the
63    // spelling RPC reports as an exception's crate.
64    pub crate_name: ContractSpecString,
65    // Identity version: the leftmost non-zero component of the declaring
66    // crate's semver ("0.1" before 1.0, "1" after), or of the item's own
67    // `version = "..."` where it pins one. Semver-compatible releases share an
68    // id; only a breaking release changes it.
69    pub major: ContractSpecString,
70    // `module_path!()` at the declaration, verbatim -- so it leads with the
71    // crate as a Rust ident (underscored), unlike `crate_name` above. Kept
72    // whole because that is the one string the compiler hands the macro; the
73    // generator splits nothing to fill this in. Compiler-generated, so a
74    // consumer that wants the segments apart can split it safely, which is not
75    // true of `declared`.
76    pub module_path: ContractSpecString,
77    // The declared name. Substituted verbatim from `name = "..."` where an item
78    // pins one, so it may itself contain `::` -- which is why it has its own
79    // field rather than being the last `::` separated segment of a joined id.
80    pub declared: ContractSpecString,
81}
82
83
84#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
85#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
86#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
87#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
88#[repr(C)]
89pub struct ContractArrayType {
90    // #[rust(box_ptr)]
91    pub element: Box<ContractType>,
92    pub len: u32,
93}
94
95#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
96#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
97#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
98#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
99#[repr(C)]
100pub struct ContractVectorType {
101    // #[rust(box_ptr)]
102    pub element: Box<ContractType>,
103    pub max_len: u32,
104}
105
106#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
107#[cfg_attr(feature = "serde", serde(transparent))]
108#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
109#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
110#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
111#[derive(Copy)]
112#[repr(transparent)]
113pub struct ContractTypeKind(pub i32);
114
115impl ContractTypeKind {
116    pub const Void: Self = Self(0);
117    pub const Bool: Self = Self(1);
118    pub const U32: Self = Self(2);
119    pub const I32: Self = Self(3);
120    pub const U64: Self = Self(4);
121    pub const I64: Self = Self(5);
122    pub const U128: Self = Self(6);
123    pub const I128: Self = Self(7);
124    pub const String: Self = Self(8);
125    pub const Bytes: Self = Self(9);
126    pub const Address: Self = Self(10);
127    pub const Option: Self = Self(11);
128    pub const Vector: Self = Self(12);
129    pub const Tuple: Self = Self(13);
130    pub const Named: Self = Self(14);
131    pub const U8: Self = Self(15);
132    pub const Array: Self = Self(16);
133    pub const SignedToken: Self = Self(17);
134
135    // Contract values are exactly 32 bytes, most-significant byte first.
136    // Event topics use the same bytes directly, without hashing.
137    pub const U256: Self = Self(18);
138
139    // Contract values are exactly 32 bytes, most-significant byte first, in
140    // two's-complement representation. Event topics use the same bytes directly.
141    pub const I256: Self = Self(19);
142}
143impl From<i32> for ContractTypeKind {
144    fn from(v: i32) -> Self {
145        Self(v)
146    }
147}
148
149
150#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
151#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
152#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
153#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
154#[repr(i32)]
155#[non_exhaustive]
156pub enum ContractType {
157    // case Void:
158    //   void;
159    Void = ContractTypeKind::Void.0 as i32,
160    // case Bool:
161    //   void;
162    Bool = ContractTypeKind::Bool.0 as i32,
163    // case U32:
164    //   void;
165    U32 = ContractTypeKind::U32.0 as i32,
166    // case I32:
167    //   void;
168    I32 = ContractTypeKind::I32.0 as i32,
169    // case U64:
170    //   void;
171    U64 = ContractTypeKind::U64.0 as i32,
172    // case I64:
173    //   void;
174    I64 = ContractTypeKind::I64.0 as i32,
175    // case U128:
176    //   void;
177    U128 = ContractTypeKind::U128.0 as i32,
178    // case I128:
179    //   void;
180    I128 = ContractTypeKind::I128.0 as i32,
181    // case String:
182    //   void;
183    String = ContractTypeKind::String.0 as i32,
184    // case Bytes:
185    //   void;
186    Bytes = ContractTypeKind::Bytes.0 as i32,
187    // case Address:
188    //   void;
189    Address = ContractTypeKind::Address.0 as i32,
190    // #[rust(box_ptr)], #[cpp(box)]
191    // case Option:
192    //   Box<ContractType> option_inner;
193    Option { option_inner: Box<ContractType> } = ContractTypeKind::Option.0 as i32,
194    // case Vector:
195    //   ContractVectorType vector;
196    Vector { vector: ContractVectorType } = ContractTypeKind::Vector.0 as i32,
197    // case Tuple:
198    //   VecM<ContractType> tuple;
199    Tuple { tuple: VecM<ContractType> } = ContractTypeKind::Tuple.0 as i32,
200    // case Named:
201    //   ContractSpecId named;
202    Named { named: ContractSpecId } = ContractTypeKind::Named.0 as i32,
203    // case U8:
204    //   void;
205    U8 = ContractTypeKind::U8.0 as i32,
206    // case Array:
207    //   ContractArrayType array;
208    Array { array: ContractArrayType } = ContractTypeKind::Array.0 as i32,
209    // case SignedToken:
210    //   ContractSignedTokenPreimage signed_token_preimage;
211    SignedToken { signed_token_preimage: ContractSignedTokenPreimage } = ContractTypeKind::SignedToken.0 as i32,
212    // case U256:
213    //   void;
214    U256 = ContractTypeKind::U256.0 as i32,
215    // case I256:
216    //   void;
217    I256 = ContractTypeKind::I256.0 as i32,
218    
219}
220
221// ---------------------------------------------------------------------------
222// SignedTokenPreimage (Rust: SignedTokenPreimage)
223// ---------------------------------------------------------------------------
224
225#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
226#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
227#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
228#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
229#[repr(C)]
230pub struct ContractSignedTokenPreimage {
231    // #[rust(box_ptr)], #[cpp(box)]
232    pub preimage_type: Option<Box<ContractType>>,
233}
234
235// ---------------------------------------------------------------------------
236// Exception type wrapper (carries selector metadata alongside the type)
237// ---------------------------------------------------------------------------
238
239#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
240#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
241#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
242#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
243#[repr(C)]
244pub struct ContractExceptionType {
245    pub selector: u64,
246    pub ty: ContractType,
247}
248
249// ---------------------------------------------------------------------------
250// Fields, methods, interfaces
251// ---------------------------------------------------------------------------
252
253#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
254#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
255#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
256#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
257#[repr(C)]
258pub struct ContractField {
259    pub name: ContractSpecString,
260    pub ty: ContractType,
261}
262
263/// Author-declared effects of the whole invocation, including nested calls.
264/// These declarations are not compiler or runtime guarantees. They do not
265/// select an execution path, change entrypoint IDs, or guarantee success.
266/// Application effects include storage deltas, events, transfers and deployment.
267#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
268#[cfg_attr(feature = "serde", serde(transparent))]
269#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
270#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
271#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
272#[derive(Copy)]
273#[repr(transparent)]
274pub struct ContractMethodEffect(pub i32);
275
276impl ContractMethodEffect {
277    // Arguments and constants only: no state or execution-context reads or effects.
278    pub const EffectPure: Self = Self(1);
279
280    // May read state and execution context; no application effects.
281    pub const EffectReadOnly: Self = Self(2);
282
283    // May produce application effects; need not change state on every invocation.
284    pub const EffectStateChanging: Self = Self(3);
285}
286impl From<i32> for ContractMethodEffect {
287    fn from(v: i32) -> Self {
288        Self(v)
289    }
290}
291
292
293#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
294#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
295#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
296#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
297#[repr(C)]
298pub struct ContractSpecMethod {
299    pub name: ContractSpecString,
300    pub args: VecM<ContractField>,
301    pub return_type: ContractType,
302    // Absent when unannotated; never assume read-only from absence.
303    pub effect: Option<ContractMethodEffect>,
304}
305
306#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
307#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
308#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
309#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
310#[repr(C)]
311pub struct ContractSpecInterface {
312    pub name: ContractSpecString,
313    pub vers: ContractSpecString,
314    pub throws: VecM<ContractExceptionType>,
315    pub methods: VecM<ContractSpecMethod>,
316}
317
318// ---------------------------------------------------------------------------
319// User-defined types (Rust: ContractTypeDef and components)
320// ---------------------------------------------------------------------------
321
322#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
323#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
324#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
325#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
326#[repr(C)]
327pub struct ContractStructDef {
328    pub name: ContractSpecId,
329    pub fields: VecM<ContractField>,
330}
331
332#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
333#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
334#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
335#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
336#[repr(C)]
337pub struct ContractEnumVariant {
338    pub name: ContractSpecString,
339    pub value: i32,
340}
341
342#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
343#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
344#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
345#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
346#[repr(C)]
347pub struct ContractEnumDef {
348    pub name: ContractSpecId,
349    pub variants: VecM<ContractEnumVariant>,
350}
351
352/// Case names carry a `UnionCase` prefix because enum tags share one namespace,
353/// and ContractTypeKind already has `Void` and `Tuple`.
354#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
355#[cfg_attr(feature = "serde", serde(transparent))]
356#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
357#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
358#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
359#[derive(Copy)]
360#[repr(transparent)]
361pub struct ContractUnionCaseKind(pub i32);
362
363impl ContractUnionCaseKind {
364    pub const UnionCaseVoid: Self = Self(0);
365    pub const UnionCaseTuple: Self = Self(1);
366    pub const UnionCaseStruct: Self = Self(2);
367}
368impl From<i32> for ContractUnionCaseKind {
369    fn from(v: i32) -> Self {
370        Self(v)
371    }
372}
373
374
375#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
376#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
377#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
378#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
379#[repr(i32)]
380#[non_exhaustive]
381pub enum ContractUnionCaseType {
382    // case UnionCaseVoid:
383    //   void;
384    UnionCaseVoid = ContractUnionCaseKind::UnionCaseVoid.0 as i32,
385    // case UnionCaseTuple:
386    //   VecM<ContractType> tuple;
387    UnionCaseTuple { tuple: VecM<ContractType> } = ContractUnionCaseKind::UnionCaseTuple.0 as i32,
388    // case UnionCaseStruct:
389    //   VecM<ContractField> struct_fields;
390    UnionCaseStruct { struct_fields: VecM<ContractField> } = ContractUnionCaseKind::UnionCaseStruct.0 as i32,
391    
392}
393
394#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
395#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
396#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
397#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
398#[repr(C)]
399pub struct ContractUnionCase {
400    pub name: ContractSpecString,
401    pub discriminant: i32,
402    pub case_type: ContractUnionCaseType,
403}
404
405#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
406#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
407#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
408#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
409#[repr(C)]
410pub struct ContractUnionDef {
411    pub name: ContractSpecId,
412    pub cases: VecM<ContractUnionCase>,
413}
414
415#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
416#[cfg_attr(feature = "serde", serde(transparent))]
417#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
418#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
419#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
420#[derive(Copy)]
421#[repr(transparent)]
422pub struct ContractTypeDefKind(pub i32);
423
424impl ContractTypeDefKind {
425    pub const TypeDefStruct: Self = Self(0);
426    pub const TypeDefEnum: Self = Self(1);
427    pub const TypeDefUnion: Self = Self(2);
428}
429impl From<i32> for ContractTypeDefKind {
430    fn from(v: i32) -> Self {
431        Self(v)
432    }
433}
434
435
436#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
437#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
438#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
439#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
440#[repr(i32)]
441#[non_exhaustive]
442pub enum ContractTypeDef {
443    // case TypeDefStruct:
444    //   ContractStructDef struct_def;
445    TypeDefStruct { struct_def: ContractStructDef } = ContractTypeDefKind::TypeDefStruct.0 as i32,
446    // case TypeDefEnum:
447    //   ContractEnumDef enum_def;
448    TypeDefEnum { enum_def: ContractEnumDef } = ContractTypeDefKind::TypeDefEnum.0 as i32,
449    // case TypeDefUnion:
450    //   ContractUnionDef union_def;
451    TypeDefUnion { union_def: ContractUnionDef } = ContractTypeDefKind::TypeDefUnion.0 as i32,
452    
453}
454
455// ---------------------------------------------------------------------------
456// Event definitions (Rust: ContractEventDef)
457// ---------------------------------------------------------------------------
458
459/// Describes an event emitted via the LogEvent syscall (see event.x).
460/// Topic 0 is always the event signature:
461///   sha256(MAJOR_VERSION :: CRATE_NAME :: TYPE_NAME)
462/// Topic fields and payload fields are listed separately, each in
463/// declaration order. Topic values that are not already 32 bytes wide are
464/// XDR-encoded and sha256-hashed; payload fields are XDR-encoded in order
465/// to form the event data.
466#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
467#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
468#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
469#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
470#[repr(C)]
471pub struct ContractEventDef {
472    pub name: ContractSpecId,
473    // topic 0
474    pub signature: Topic,
475    // topics 1.. ; at most kMaxTopics-1 entries
476    pub topics: VecM<ContractField>,
477    // payload, XDR-encoded in order
478    pub fields: VecM<ContractField>,
479}
480
481// ---------------------------------------------------------------------------
482// Full spec (Rust: ContractSpec)
483// ---------------------------------------------------------------------------
484
485#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
486#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
487#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
488#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
489#[repr(C)]
490pub struct ContractSpec {
491    pub interfaces: VecM<ContractSpecInterface>,
492    pub type_defs: VecM<ContractTypeDef>,
493    pub events: VecM<ContractEventDef>,
494}
495
496
497//
498// XDR internals below this point
499//
500
501impl ContractType {
502    #[allow(clippy::match_single_binding)]
503    pub fn v(&self) -> ContractTypeKind {
504        match self {
505            
506            _ => (unsafe { *(self as *const Self as *const i32) }).into(),
507        }
508    }
509}
510
511impl ContractUnionCaseType {
512    #[allow(clippy::match_single_binding)]
513    pub fn v(&self) -> ContractUnionCaseKind {
514        match self {
515            
516            _ => (unsafe { *(self as *const Self as *const i32) }).into(),
517        }
518    }
519}
520
521impl ContractTypeDef {
522    #[allow(clippy::match_single_binding)]
523    pub fn v(&self) -> ContractTypeDefKind {
524        match self {
525            
526            _ => (unsafe { *(self as *const Self as *const i32) }).into(),
527        }
528    }
529}
530
531