thruput-spec 0.63.0

Bindings for Thruput specs
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
// -*-Rust-*-
// Generated Code: DO NOT CHECK IN

// Generated from xdrc commit: 6ab835b07c234abb4b0b50b61d687904727a4f32

// Thruput contract specification AST
//
// Excluded from goxdr in CI. protocol-rs generates its thruput-spec crate from
// this file, and the SDK's contract-spec crate re-exports those types.

#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
#![allow(non_upper_case_globals)]
#![allow(unused_imports)]
#![allow(dead_code)]
#![allow(unused_variables)]
#![allow(clippy::unnecessary_cast)]

use crate::*;
use core::option::Option;
use core::ops::{Deref, DerefMut};

use xdrs::*;


#[cfg(feature = "serde")]
use ::serde::{{Serialize, Deserialize}};



// RFC 4506: string types must declare a max length; `<>` is unbounded (max 2^32-1 bytes).
pub type ContractSpecString = StringM;

// ---------------------------------------------------------------------------
// Spec ids
// ---------------------------------------------------------------------------

/// The identity of a user-defined type or event.
///
/// Every spec-named item — a `#[contract_type]`, a `#[contract_exception]`, a
/// `#[derive(Event)]` — is named by one of these, and every reference to one
/// resolves through it. A bare identifier cannot tell two of them apart: two
/// crates, two modules of one crate, or two major versions of one crate may
/// each declare a `Transfer`, and a spec naming both could not say which is
/// which.
///
/// The segments are carried apart rather than joined into
/// `CRATE@MAJOR::module::path::Name`, because the joined form cannot be split
/// back. `name = "..."` on a spec-named item substitutes its value verbatim —
/// a value carrying `::` spells its own segments and nothing rejects it — so
/// the boundary between the module path and the declared name is not
/// recoverable from the string. Consumers that need a display name or a
/// target-language identifier read `declared` directly; how an id is shortened
/// for display stays each codegen's business.
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[repr(C)]
pub struct ContractSpecId {
    // Declaring crate, as Cargo names the package (`CARGO_PKG_NAME`, so
    // hyphenated). This is the spelling event signatures already hash and the
    // spelling RPC reports as an exception's crate.
    pub crate_name: ContractSpecString,
    // Identity version: the leftmost non-zero component of the declaring
    // crate's semver ("0.1" before 1.0, "1" after), or of the item's own
    // `version = "..."` where it pins one. Semver-compatible releases share an
    // id; only a breaking release changes it.
    pub major: ContractSpecString,
    // `module_path!()` at the declaration, verbatim -- so it leads with the
    // crate as a Rust ident (underscored), unlike `crate_name` above. Kept
    // whole because that is the one string the compiler hands the macro; the
    // generator splits nothing to fill this in. Compiler-generated, so a
    // consumer that wants the segments apart can split it safely, which is not
    // true of `declared`.
    pub module_path: ContractSpecString,
    // The declared name. Substituted verbatim from `name = "..."` where an item
    // pins one, so it may itself contain `::` -- which is why it has its own
    // field rather than being the last `::` separated segment of a joined id.
    pub declared: ContractSpecString,
}


#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[repr(C)]
pub struct ContractArrayType {
    // #[rust(box_ptr)]
    pub element: Box<ContractType>,
    pub len: u32,
}

#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[repr(C)]
pub struct ContractVectorType {
    // #[rust(box_ptr)]
    pub element: Box<ContractType>,
    pub max_len: u32,
}

#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(transparent))]
#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[derive(Copy)]
#[repr(transparent)]
pub struct ContractTypeKind(pub i32);

impl ContractTypeKind {
    pub const Void: Self = Self(0);
    pub const Bool: Self = Self(1);
    pub const U32: Self = Self(2);
    pub const I32: Self = Self(3);
    pub const U64: Self = Self(4);
    pub const I64: Self = Self(5);
    pub const U128: Self = Self(6);
    pub const I128: Self = Self(7);
    pub const String: Self = Self(8);
    pub const Bytes: Self = Self(9);
    pub const Address: Self = Self(10);
    pub const Option: Self = Self(11);
    pub const Vector: Self = Self(12);
    pub const Tuple: Self = Self(13);
    pub const Named: Self = Self(14);
    pub const U8: Self = Self(15);
    pub const Array: Self = Self(16);
    pub const SignedToken: Self = Self(17);

    // Contract values are exactly 32 bytes, most-significant byte first.
    // Event topics use the same bytes directly, without hashing.
    pub const U256: Self = Self(18);

    // Contract values are exactly 32 bytes, most-significant byte first, in
    // two's-complement representation. Event topics use the same bytes directly.
    pub const I256: Self = Self(19);
}
impl From<i32> for ContractTypeKind {
    fn from(v: i32) -> Self {
        Self(v)
    }
}


#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[repr(i32)]
#[non_exhaustive]
pub enum ContractType {
    // case Void:
    //   void;
    Void = ContractTypeKind::Void.0 as i32,
    // case Bool:
    //   void;
    Bool = ContractTypeKind::Bool.0 as i32,
    // case U32:
    //   void;
    U32 = ContractTypeKind::U32.0 as i32,
    // case I32:
    //   void;
    I32 = ContractTypeKind::I32.0 as i32,
    // case U64:
    //   void;
    U64 = ContractTypeKind::U64.0 as i32,
    // case I64:
    //   void;
    I64 = ContractTypeKind::I64.0 as i32,
    // case U128:
    //   void;
    U128 = ContractTypeKind::U128.0 as i32,
    // case I128:
    //   void;
    I128 = ContractTypeKind::I128.0 as i32,
    // case String:
    //   void;
    String = ContractTypeKind::String.0 as i32,
    // case Bytes:
    //   void;
    Bytes = ContractTypeKind::Bytes.0 as i32,
    // case Address:
    //   void;
    Address = ContractTypeKind::Address.0 as i32,
    // #[rust(box_ptr)], #[cpp(box)]
    // case Option:
    //   Box<ContractType> option_inner;
    Option { option_inner: Box<ContractType> } = ContractTypeKind::Option.0 as i32,
    // case Vector:
    //   ContractVectorType vector;
    Vector { vector: ContractVectorType } = ContractTypeKind::Vector.0 as i32,
    // case Tuple:
    //   VecM<ContractType> tuple;
    Tuple { tuple: VecM<ContractType> } = ContractTypeKind::Tuple.0 as i32,
    // case Named:
    //   ContractSpecId named;
    Named { named: ContractSpecId } = ContractTypeKind::Named.0 as i32,
    // case U8:
    //   void;
    U8 = ContractTypeKind::U8.0 as i32,
    // case Array:
    //   ContractArrayType array;
    Array { array: ContractArrayType } = ContractTypeKind::Array.0 as i32,
    // case SignedToken:
    //   ContractSignedTokenPreimage signed_token_preimage;
    SignedToken { signed_token_preimage: ContractSignedTokenPreimage } = ContractTypeKind::SignedToken.0 as i32,
    // case U256:
    //   void;
    U256 = ContractTypeKind::U256.0 as i32,
    // case I256:
    //   void;
    I256 = ContractTypeKind::I256.0 as i32,
    
}

// ---------------------------------------------------------------------------
// SignedTokenPreimage (Rust: SignedTokenPreimage)
// ---------------------------------------------------------------------------

#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[repr(C)]
pub struct ContractSignedTokenPreimage {
    // #[rust(box_ptr)], #[cpp(box)]
    pub preimage_type: Option<Box<ContractType>>,
}

// ---------------------------------------------------------------------------
// Exception type wrapper (carries selector metadata alongside the type)
// ---------------------------------------------------------------------------

#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[repr(C)]
pub struct ContractExceptionType {
    pub selector: u64,
    pub ty: ContractType,
}

// ---------------------------------------------------------------------------
// Fields, methods, interfaces
// ---------------------------------------------------------------------------

#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[repr(C)]
pub struct ContractField {
    pub name: ContractSpecString,
    pub ty: ContractType,
}

/// Author-declared effects of the whole invocation, including nested calls.
/// These declarations are not compiler or runtime guarantees. They do not
/// select an execution path, change entrypoint IDs, or guarantee success.
/// Application effects include storage deltas, events, transfers and deployment.
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(transparent))]
#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[derive(Copy)]
#[repr(transparent)]
pub struct ContractMethodEffect(pub i32);

impl ContractMethodEffect {
    // Arguments and constants only: no state or execution-context reads or effects.
    pub const EffectPure: Self = Self(1);

    // May read state and execution context; no application effects.
    pub const EffectReadOnly: Self = Self(2);

    // May produce application effects; need not change state on every invocation.
    pub const EffectStateChanging: Self = Self(3);
}
impl From<i32> for ContractMethodEffect {
    fn from(v: i32) -> Self {
        Self(v)
    }
}


#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[repr(C)]
pub struct ContractSpecMethod {
    pub name: ContractSpecString,
    pub args: VecM<ContractField>,
    pub return_type: ContractType,
    // Absent when unannotated; never assume read-only from absence.
    pub effect: Option<ContractMethodEffect>,
}

#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[repr(C)]
pub struct ContractSpecInterface {
    pub name: ContractSpecString,
    pub vers: ContractSpecString,
    pub throws: VecM<ContractExceptionType>,
    pub methods: VecM<ContractSpecMethod>,
}

// ---------------------------------------------------------------------------
// User-defined types (Rust: ContractTypeDef and components)
// ---------------------------------------------------------------------------

#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[repr(C)]
pub struct ContractStructDef {
    pub name: ContractSpecId,
    pub fields: VecM<ContractField>,
}

#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[repr(C)]
pub struct ContractEnumVariant {
    pub name: ContractSpecString,
    pub value: i32,
}

#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[repr(C)]
pub struct ContractEnumDef {
    pub name: ContractSpecId,
    pub variants: VecM<ContractEnumVariant>,
}

/// Case names carry a `UnionCase` prefix because enum tags share one namespace,
/// and ContractTypeKind already has `Void` and `Tuple`.
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(transparent))]
#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[derive(Copy)]
#[repr(transparent)]
pub struct ContractUnionCaseKind(pub i32);

impl ContractUnionCaseKind {
    pub const UnionCaseVoid: Self = Self(0);
    pub const UnionCaseTuple: Self = Self(1);
    pub const UnionCaseStruct: Self = Self(2);
}
impl From<i32> for ContractUnionCaseKind {
    fn from(v: i32) -> Self {
        Self(v)
    }
}


#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[repr(i32)]
#[non_exhaustive]
pub enum ContractUnionCaseType {
    // case UnionCaseVoid:
    //   void;
    UnionCaseVoid = ContractUnionCaseKind::UnionCaseVoid.0 as i32,
    // case UnionCaseTuple:
    //   VecM<ContractType> tuple;
    UnionCaseTuple { tuple: VecM<ContractType> } = ContractUnionCaseKind::UnionCaseTuple.0 as i32,
    // case UnionCaseStruct:
    //   VecM<ContractField> struct_fields;
    UnionCaseStruct { struct_fields: VecM<ContractField> } = ContractUnionCaseKind::UnionCaseStruct.0 as i32,
    
}

#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[repr(C)]
pub struct ContractUnionCase {
    pub name: ContractSpecString,
    pub discriminant: i32,
    pub case_type: ContractUnionCaseType,
}

#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[repr(C)]
pub struct ContractUnionDef {
    pub name: ContractSpecId,
    pub cases: VecM<ContractUnionCase>,
}

#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(transparent))]
#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[derive(Copy)]
#[repr(transparent)]
pub struct ContractTypeDefKind(pub i32);

impl ContractTypeDefKind {
    pub const TypeDefStruct: Self = Self(0);
    pub const TypeDefEnum: Self = Self(1);
    pub const TypeDefUnion: Self = Self(2);
}
impl From<i32> for ContractTypeDefKind {
    fn from(v: i32) -> Self {
        Self(v)
    }
}


#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[repr(i32)]
#[non_exhaustive]
pub enum ContractTypeDef {
    // case TypeDefStruct:
    //   ContractStructDef struct_def;
    TypeDefStruct { struct_def: ContractStructDef } = ContractTypeDefKind::TypeDefStruct.0 as i32,
    // case TypeDefEnum:
    //   ContractEnumDef enum_def;
    TypeDefEnum { enum_def: ContractEnumDef } = ContractTypeDefKind::TypeDefEnum.0 as i32,
    // case TypeDefUnion:
    //   ContractUnionDef union_def;
    TypeDefUnion { union_def: ContractUnionDef } = ContractTypeDefKind::TypeDefUnion.0 as i32,
    
}

// ---------------------------------------------------------------------------
// Event definitions (Rust: ContractEventDef)
// ---------------------------------------------------------------------------

/// Describes an event emitted via the LogEvent syscall (see event.x).
/// Topic 0 is always the event signature:
///   sha256(MAJOR_VERSION :: CRATE_NAME :: TYPE_NAME)
/// Topic fields and payload fields are listed separately, each in
/// declaration order. Topic values that are not already 32 bytes wide are
/// XDR-encoded and sha256-hashed; payload fields are XDR-encoded in order
/// to form the event data.
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[repr(C)]
pub struct ContractEventDef {
    pub name: ContractSpecId,
    // topic 0
    pub signature: Topic,
    // topics 1.. ; at most kMaxTopics-1 entries
    pub topics: VecM<ContractField>,
    // payload, XDR-encoded in order
    pub fields: VecM<ContractField>,
}

// ---------------------------------------------------------------------------
// Full spec (Rust: ContractSpec)
// ---------------------------------------------------------------------------

#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[repr(C)]
pub struct ContractSpec {
    pub interfaces: VecM<ContractSpecInterface>,
    pub type_defs: VecM<ContractTypeDef>,
    pub events: VecM<ContractEventDef>,
}


//
// XDR internals below this point
//

impl ContractType {
    #[allow(clippy::match_single_binding)]
    pub fn v(&self) -> ContractTypeKind {
        match self {
            
            _ => (unsafe { *(self as *const Self as *const i32) }).into(),
        }
    }
}

impl ContractUnionCaseType {
    #[allow(clippy::match_single_binding)]
    pub fn v(&self) -> ContractUnionCaseKind {
        match self {
            
            _ => (unsafe { *(self as *const Self as *const i32) }).into(),
        }
    }
}

impl ContractTypeDef {
    #[allow(clippy::match_single_binding)]
    pub fn v(&self) -> ContractTypeDefKind {
        match self {
            
            _ => (unsafe { *(self as *const Self as *const i32) }).into(),
        }
    }
}