thruput-node-types 0.63.0

Thruput node types shared by the node RPC bindings: transaction batches, block proposals, consensus values and common RPC results
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
// -*-Rust-*-
// Generated Code: DO NOT CHECK IN

// Generated from xdrc commit: 6ab835b07c234abb4b0b50b61d687904727a4f32

// clang-format off

#![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};

#[cfg(feature = "std")]
use std::io::{Read, Write};
use xdrs::*;


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



// clang-format on

// An internal unique ID describing a block.
pub type BlockID = u64;

/// The contract-visible facts about the block an executor is running.
///
/// Passed to both executor open-block calls so that a block looks identical
/// to the executor whether it is being proposed or validated, and so that
/// everything a contract can observe about "the current block" comes from
/// one place rather than being inferred from the parent tip.
///
/// This is deliberately not `ProposalContext` (its `protocol` and `proposer`
/// are scheduler concerns, and `protocol` is not recoverable from a
/// `ProposalHeader` when validating) and not `ProposalHeader` (whose txs,
/// storage, events and config hashes are outputs of executing the block, so
/// they do not exist when it is opened).
///
/// Does not travel on network: the scheduler builds it per block, from the
/// coordinator's `ProposalContext` when proposing and from the proposal's
/// `ProposalHeader` when validating. A validator must take these values from
/// the proposal it is validating rather than regenerating them, or its
/// execution diverges from the proposer's and consensus splits.
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
#[derive(schemars::JsonSchema)]
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[repr(C)]
pub struct BlockExecutionContext {
    /// Height of the block being executed -- the parent tip's height plus one.
    /// Supplied rather than derived so that height and timepoint have a single
    /// source; the executor is expected to check it against the tip it reads.
    pub block_height: BlockHeight,
    /// The block's timepoint, fixed before execution begins. Unlike the
    /// height there is no way to recover this from the parent tip: the
    /// parent's timepoint is the previous block's.
    pub block_timepoint: TimePoint,
}

#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
#[derive(schemars::JsonSchema)]
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[repr(C)]
pub struct DbTip {
    pub id: BlockID,
    pub storage_long_hash: StorageLongHash,
    pub value: ConsensusValue,
    /// The chain-configured contract resolved for a root invocation of an
    /// address with no deployed contract (see
    /// SystemCallHandler::resolve_runtime). Set at genesis from
    /// GenesisConfiguration::default_wallet; carried forward verbatim by
    /// every subsequent commit, and committed to by this tip's own
    /// ProposalHeader::config_hash through ConfigHashPreimage.
    pub default_wallet: DeployedContractHash,
    /// The execution parameters in force for the block that follows this tip.
    /// Set at genesis from GenesisConfiguration::network_config and carried
    /// forward verbatim by every commit: no mechanism changes it after genesis
    /// yet (see [`ConfigParam`]).
    pub network_config: NetworkConfig,
}

// Internal unique ID describing a transaction.
// Can be reused across blocks but cannot be reused within one block.
pub type TransactionID = u64;

// This is missing error codes, and is here purely as a placeholder.
// These are some of the error codes I suspect we will need, but these
// are not organized in any particular manner.
//
// TODO: This probably should get moved to a different file?
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(transparent))]
#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
#[derive(schemars::JsonSchema)]
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[derive(Copy)]
#[repr(transparent)]
pub struct RPCError(pub i32);

impl RPCError {
    pub const kRPCNone: Self = Self(0);

    // Lookup on an item in the database that does not exist.
    // Used by any database lookup RPC, not just for one type.
    pub const kRPCNotFound: Self = Self(1);

    // BlockID does not exist, or is not in correct state
    pub const kRPCBadBlockID: Self = Self(3);

    // bad storage modification
    pub const kRPCStorageWriteFailed: Self = Self(4);

    // tx validation or proposal failed
    pub const kRPCTransactionFailed: Self = Self(5);

    // Unimplemented RPC
    pub const kRPCUnimplemented: Self = Self(6);

    // Unrecoverable error in the server (i.e. OOM, DB corruption)
    pub const kRPCUnrecoverable: Self = Self(7);
}
impl From<i32> for RPCError {
    fn from(v: i32) -> Self {
        Self(v)
    }
}
#[cfg(feature = "std")]
impl core::fmt::Display for RPCError {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self.0 {
            x if x == Self::kRPCNone.0 => {
                write!(f, "RPCError::kRPCNone")
            },
            x if x == Self::kRPCNotFound.0 => {
                write!(f, "RPCError::kRPCNotFound")
            },
            x if x == Self::kRPCBadBlockID.0 => {
                write!(f, "RPCError::kRPCBadBlockID")
            },
            x if x == Self::kRPCStorageWriteFailed.0 => {
                write!(f, "RPCError::kRPCStorageWriteFailed")
            },
            x if x == Self::kRPCTransactionFailed.0 => {
                write!(f, "RPCError::kRPCTransactionFailed")
            },
            x if x == Self::kRPCUnimplemented.0 => {
                write!(f, "RPCError::kRPCUnimplemented")
            },
            x if x == Self::kRPCUnrecoverable.0 => {
                write!(f, "RPCError::kRPCUnrecoverable")
            },
            _ => {
                write!(f, "RPCError({})", self.0)
            }
        }
    }
}


// The mode in which a block executes.
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(transparent))]
#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
#[derive(schemars::JsonSchema)]
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[derive(Copy)]
#[repr(transparent)]
pub struct BlockExecutionMode(pub i32);

impl BlockExecutionMode {
    pub const kBlockExecutionModeValidation: Self = Self(0);
    pub const kBlockExecutionModeProposal: Self = Self(1);

    // Read-only access to the database.
    // Used for view RPCs, guaranteeing that the executor cannot accidentally
    // do a write operation when it should not be able to.
    pub const kBlockExecutionModeViewing: Self = Self(2);
}
impl From<i32> for BlockExecutionMode {
    fn from(v: i32) -> Self {
        Self(v)
    }
}
#[cfg(feature = "std")]
impl core::fmt::Display for BlockExecutionMode {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self.0 {
            x if x == Self::kBlockExecutionModeValidation.0 => {
                write!(f, "BlockExecutionMode::kBlockExecutionModeValidation")
            },
            x if x == Self::kBlockExecutionModeProposal.0 => {
                write!(f, "BlockExecutionMode::kBlockExecutionModeProposal")
            },
            x if x == Self::kBlockExecutionModeViewing.0 => {
                write!(f, "BlockExecutionMode::kBlockExecutionModeViewing")
            },
            _ => {
                write!(f, "BlockExecutionMode({})", self.0)
            }
        }
    }
}


pub type StorageCost = int128_xdr;

#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
#[derive(schemars::JsonSchema)]
#[repr(i32)]
#[non_exhaustive]
pub enum ExpectedStorageCost {
    // case kRPCNone:
    //   StorageCost storage_cost;
    kRPCNone { storage_cost: StorageCost } = RPCError::kRPCNone.0 as i32,
    // default:
    //   void;
    #[xdr(default_variant)] Default { error: i32 },
}

// Is this the XDR pattern we want?
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
#[derive(schemars::JsonSchema)]
#[repr(i32)]
#[non_exhaustive]
pub enum ExpectedContract {
    // case kRPCNone:
    //   Contract contract;
    kRPCNone { contract: Contract } = RPCError::kRPCNone.0 as i32,
    // default:
    //   void;
    #[xdr(default_variant)] Default { error: i32 },
}

#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
#[derive(schemars::JsonSchema)]
#[repr(i32)]
#[non_exhaustive]
pub enum ExpectedDeployment {
    // case kRPCNone:
    //   DeployedContractHash deployed_hash;
    kRPCNone { deployed_hash: DeployedContractHash } = RPCError::kRPCNone.0 as i32,
    // default:
    //   void;
    #[xdr(default_variant)] Default { error: i32 },
}

#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
#[derive(schemars::JsonSchema)]
#[repr(i32)]
#[non_exhaustive]
pub enum ExpectedProposalData {
    // case kRPCNone:
    //   NondeterministicProposalData proposal_data;
    kRPCNone { proposal_data: NondeterministicProposalData } = RPCError::kRPCNone.0 as i32,
    // default:
    //   void;
    #[xdr(default_variant)] Default { error: i32 },
}

#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
#[derive(schemars::JsonSchema)]
#[repr(i32)]
#[non_exhaustive]
pub enum ExpectedRetrocausalQueueBlock {
    // case kRPCNone:
    //   RetrocausalQueueBlock queue_block;
    kRPCNone { queue_block: RetrocausalQueueBlock } = RPCError::kRPCNone.0 as i32,
    // default:
    //   void;
    #[xdr(default_variant)] Default { error: i32 },
}

#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
#[derive(schemars::JsonSchema)]
#[repr(i32)]
#[non_exhaustive]
pub enum ExpectedQueueEntry {
    // case kRPCNone:
    //   QueueEntry queue_entry;
    kRPCNone { queue_entry: QueueEntry } = RPCError::kRPCNone.0 as i32,
    // default:
    //   void;
    #[xdr(default_variant)] Default { error: i32 },
}

#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
#[derive(schemars::JsonSchema)]
#[repr(i32)]
#[non_exhaustive]
pub enum ExpectedDBTip {
    // case kRPCNone:
    //   DbTip db_tip;
    kRPCNone { db_tip: DbTip } = RPCError::kRPCNone.0 as i32,
    // default:
    //   void;
    #[xdr(default_variant)] Default { error: i32 },
}

#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
#[derive(schemars::JsonSchema)]
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[repr(C)]
pub struct ViewingSnapshot {
    pub viewing_block_id: BlockID,
    pub tip: DbTip,
}

#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
#[derive(schemars::JsonSchema)]
#[repr(i32)]
#[non_exhaustive]
pub enum ExpectedViewingSnapshot {
    // case kRPCNone:
    //   ViewingSnapshot snapshot;
    kRPCNone { snapshot: ViewingSnapshot } = RPCError::kRPCNone.0 as i32,
    // default:
    //   void;
    #[xdr(default_variant)] Default { error: i32 },
}

/// Typedef for a list of contract addresses.
pub type ContractAddressBatch = VecM::<ContractAddress>;


//
// XDR internals below this point
//

impl ExpectedStorageCost {
    #[allow(clippy::match_single_binding)]
    pub fn error(&self) -> RPCError {
        match self {
            ExpectedStorageCost::Default{ error } => (*error).into(),

            _ => (unsafe { *(self as *const Self as *const i32) }).into(),
        }
    }
}

impl ExpectedContract {
    #[allow(clippy::match_single_binding)]
    pub fn error(&self) -> RPCError {
        match self {
            ExpectedContract::Default{ error } => (*error).into(),

            _ => (unsafe { *(self as *const Self as *const i32) }).into(),
        }
    }
}

impl ExpectedDeployment {
    #[allow(clippy::match_single_binding)]
    pub fn error(&self) -> RPCError {
        match self {
            ExpectedDeployment::Default{ error } => (*error).into(),

            _ => (unsafe { *(self as *const Self as *const i32) }).into(),
        }
    }
}

impl ExpectedProposalData {
    #[allow(clippy::match_single_binding)]
    pub fn error(&self) -> RPCError {
        match self {
            ExpectedProposalData::Default{ error } => (*error).into(),

            _ => (unsafe { *(self as *const Self as *const i32) }).into(),
        }
    }
}

impl ExpectedRetrocausalQueueBlock {
    #[allow(clippy::match_single_binding)]
    pub fn error(&self) -> RPCError {
        match self {
            ExpectedRetrocausalQueueBlock::Default{ error } => (*error).into(),

            _ => (unsafe { *(self as *const Self as *const i32) }).into(),
        }
    }
}

impl ExpectedQueueEntry {
    #[allow(clippy::match_single_binding)]
    pub fn error(&self) -> RPCError {
        match self {
            ExpectedQueueEntry::Default{ error } => (*error).into(),

            _ => (unsafe { *(self as *const Self as *const i32) }).into(),
        }
    }
}

impl ExpectedDBTip {
    #[allow(clippy::match_single_binding)]
    pub fn error(&self) -> RPCError {
        match self {
            ExpectedDBTip::Default{ error } => (*error).into(),

            _ => (unsafe { *(self as *const Self as *const i32) }).into(),
        }
    }
}

impl ExpectedViewingSnapshot {
    #[allow(clippy::match_single_binding)]
    pub fn error(&self) -> RPCError {
        match self {
            ExpectedViewingSnapshot::Default{ error } => (*error).into(),

            _ => (unsafe { *(self as *const Self as *const i32) }).into(),
        }
    }
}