thruput-view 0.63.0

Bindings for Thruput ViewGateway1 read-only invocation RPC
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
// -*-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

/// Successful view payload returned by ViewGateway1::viewgateway_view.
///
/// The height is the committed snapshot height used for the full view
/// execution, not a post-execution tip sample. gas_consumed is
/// TransactionViewResult::gas_consumed for that execution.
#[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 ViewGatewayPayload {
    pub height: BlockHeight,
    pub output: InvocationFrameOutput,
    pub gas_consumed: GasAmount,
    pub events: VecM<TxEmittedEvent>,
}

#[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 ViewGatewayOutcome(pub i32);

impl ViewGatewayOutcome {
    pub const ViewGatewayOk: Self = Self(0);

    // Raw view attempts returned Abandoned until the bounded service retry
    // budget was exhausted. Callers may retry the public view request later.
    pub const ViewGatewayAbandoned: Self = Self(1);

    // Server-side invariant failure or unavailable execution dependency.
    pub const ViewGatewayInternalError: Self = Self(2);

    // The request was rejected before any frame output existed: forwarded
    // tokens without a parent address or deeper than the network allows, an
    // invocation the executor would not admit, or a root frame that failed on a
    // syscall error before it returned, aborted, or faulted. Deterministic for
    // the same request against the same state, so retrying does not help. The
    // error_code arm carries the SyscallErrorCode the executor reported.
    pub const ViewGatewayInvalidInput: Self = Self(3);
}
impl From<i32> for ViewGatewayOutcome {
    fn from(v: i32) -> Self {
        Self(v)
    }
}
#[cfg(feature = "std")]
impl core::fmt::Display for ViewGatewayOutcome {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self.0 {
            x if x == Self::ViewGatewayOk.0 => {
                write!(f, "ViewGatewayOutcome::ViewGatewayOk")
            },
            x if x == Self::ViewGatewayAbandoned.0 => {
                write!(f, "ViewGatewayOutcome::ViewGatewayAbandoned")
            },
            x if x == Self::ViewGatewayInternalError.0 => {
                write!(f, "ViewGatewayOutcome::ViewGatewayInternalError")
            },
            x if x == Self::ViewGatewayInvalidInput.0 => {
                write!(f, "ViewGatewayOutcome::ViewGatewayInvalidInput")
            },
            _ => {
                write!(f, "ViewGatewayOutcome({})", self.0)
            }
        }
    }
}


#[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 ViewGatewayResult {
    // case ViewGatewayOk:
    //   ViewGatewayPayload payload;
    ViewGatewayOk { payload: ViewGatewayPayload } = ViewGatewayOutcome::ViewGatewayOk.0 as i32,
    // case ViewGatewayAbandoned:
    //   void;
    ViewGatewayAbandoned = ViewGatewayOutcome::ViewGatewayAbandoned.0 as i32,
    // case ViewGatewayInternalError:
    //   void;
    ViewGatewayInternalError = ViewGatewayOutcome::ViewGatewayInternalError.0 as i32,
    // case ViewGatewayInvalidInput:
    //   SyscallErrorCode error_code;
    ViewGatewayInvalidInput { error_code: SyscallErrorCode } = ViewGatewayOutcome::ViewGatewayInvalidInput.0 as i32,
    // default:
    //   void;
    #[xdr(default_variant)] Default { outcome: i32 },
}

#[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 ViewGatewayIntroOutcome(pub i32);

impl ViewGatewayIntroOutcome {
    pub const ViewGatewayIntroSuccess: Self = Self(0);
    pub const ViewGatewayIntroMismatchedProtocol: Self = Self(1);
}
impl From<i32> for ViewGatewayIntroOutcome {
    fn from(v: i32) -> Self {
        Self(v)
    }
}
#[cfg(feature = "std")]
impl core::fmt::Display for ViewGatewayIntroOutcome {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self.0 {
            x if x == Self::ViewGatewayIntroSuccess.0 => {
                write!(f, "ViewGatewayIntroOutcome::ViewGatewayIntroSuccess")
            },
            x if x == Self::ViewGatewayIntroMismatchedProtocol.0 => {
                write!(f, "ViewGatewayIntroOutcome::ViewGatewayIntroMismatchedProtocol")
            },
            _ => {
                write!(f, "ViewGatewayIntroOutcome({})", self.0)
            }
        }
    }
}


// Independent simulations against one committed snapshot. Calls do not see
// each other's simulated writes. The trusted gateway applies operator request
// limits before dispatch. RPC message-size limits also bound decoding.
#[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 ViewGatewayBatchQuery {
    pub calls: VecM<TransactionViewQuery>,
    // Freshness floor only: reject an older snapshot without waiting or
    // requesting a refresh. Snapshot maintenance is shared across requests.
    pub min_height: Option<BlockHeight>,
    // Remaining work budget from receipt, including scheduling and retries.
    // Must be positive. Running calls remain gas-bounded.
    pub budget_millis: u32,
    // Maximum XDR-encoded ViewGatewayBatchResult, including events.
    // Must be positive; enforced while constructing the result.
    pub max_response_bytes: u32,
}

#[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 ViewGatewayBatchPayload {
    pub height: BlockHeight,
    pub results: VecM<TransactionViewResult>,
}

#[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 ViewGatewayHeightUnavailable {
    pub requested: BlockHeight,
    pub observed: BlockHeight,
}

#[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 ViewGatewayBatchOutcome(pub i32);

impl ViewGatewayBatchOutcome {
    pub const ViewGatewayBatchOk: Self = Self(0);
    pub const ViewGatewayBatchInvalidRequest: Self = Self(1);
    pub const ViewGatewayBatchHeightUnavailable: Self = Self(2);
    pub const ViewGatewayBatchAbandoned: Self = Self(3);
    pub const ViewGatewayBatchDeadlineExceeded: Self = Self(4);
    pub const ViewGatewayBatchResponseTooLarge: Self = Self(5);
    pub const ViewGatewayBatchInternalError: Self = Self(6);
}
impl From<i32> for ViewGatewayBatchOutcome {
    fn from(v: i32) -> Self {
        Self(v)
    }
}
#[cfg(feature = "std")]
impl core::fmt::Display for ViewGatewayBatchOutcome {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self.0 {
            x if x == Self::ViewGatewayBatchOk.0 => {
                write!(f, "ViewGatewayBatchOutcome::ViewGatewayBatchOk")
            },
            x if x == Self::ViewGatewayBatchInvalidRequest.0 => {
                write!(f, "ViewGatewayBatchOutcome::ViewGatewayBatchInvalidRequest")
            },
            x if x == Self::ViewGatewayBatchHeightUnavailable.0 => {
                write!(f, "ViewGatewayBatchOutcome::ViewGatewayBatchHeightUnavailable")
            },
            x if x == Self::ViewGatewayBatchAbandoned.0 => {
                write!(f, "ViewGatewayBatchOutcome::ViewGatewayBatchAbandoned")
            },
            x if x == Self::ViewGatewayBatchDeadlineExceeded.0 => {
                write!(f, "ViewGatewayBatchOutcome::ViewGatewayBatchDeadlineExceeded")
            },
            x if x == Self::ViewGatewayBatchResponseTooLarge.0 => {
                write!(f, "ViewGatewayBatchOutcome::ViewGatewayBatchResponseTooLarge")
            },
            x if x == Self::ViewGatewayBatchInternalError.0 => {
                write!(f, "ViewGatewayBatchOutcome::ViewGatewayBatchInternalError")
            },
            _ => {
                write!(f, "ViewGatewayBatchOutcome({})", self.0)
            }
        }
    }
}


// Success contains exactly one ordered result per input call, all from height.
// Contract aborts and faults are per-call results. Other failures discard the
// whole attempt; abandoned batches retry as a group, never one call at a time.
#[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 ViewGatewayBatchResult {
    // case ViewGatewayBatchOk:
    //   ViewGatewayBatchPayload payload;
    ViewGatewayBatchOk { payload: ViewGatewayBatchPayload } = ViewGatewayBatchOutcome::ViewGatewayBatchOk.0 as i32,
    // case ViewGatewayBatchHeightUnavailable:
    //   ViewGatewayHeightUnavailable height_unavailable;
    ViewGatewayBatchHeightUnavailable { height_unavailable: ViewGatewayHeightUnavailable } = ViewGatewayBatchOutcome::ViewGatewayBatchHeightUnavailable.0 as i32,
    // default:
    //   void;
    #[xdr(default_variant)] Default { outcome: i32 },
}


/// Each handler replies with anything that encodes like the reply type.
/// Implementations can be plain `async fn`s returning a concrete reply type
/// under `#[allow(refining_impl_trait)]`.
#[allow(non_camel_case_types)]
pub trait ViewGateway_ViewGateway1: Send + Sync {    
    fn viewgateway_intro(&self, arg0 : ProtocolCommit) -> impl ::core::future::Future<Output = Result<impl xdrs::EncodesAs<ViewGatewayIntroOutcome>, ::thruput_rpc_api::ProgramError>> + Send;
    
    fn viewgateway_view(&self, arg0 : TransactionViewQuery) -> impl ::core::future::Future<Output = Result<impl xdrs::EncodesAs<ViewGatewayResult>, ::thruput_rpc_api::ProgramError>> + Send;
    
    fn viewgateway_view_batch(&self, arg0 : ViewGatewayBatchQuery) -> impl ::core::future::Future<Output = Result<impl xdrs::EncodesAs<ViewGatewayBatchResult>, ::thruput_rpc_api::ProgramError>> + Send;
}


#[allow(non_camel_case_types)]
pub struct ViewGateway_ViewGateway1_Dispatcher<__Handler> {
  inner: Box<__Handler>,
}

impl<__Handler: ViewGateway_ViewGateway1> ViewGateway_ViewGateway1_Dispatcher<__Handler> {
  pub fn new(inner: Box<__Handler>) -> Self {
    Self { inner }
  }
}

#[async_trait::async_trait]
impl<__Handler: ViewGateway_ViewGateway1> ::thruput_rpc_api::RpcHandler for ViewGateway_ViewGateway1_Dispatcher<__Handler> {
    fn prog_vers(&self) -> ::thruput_rpc_api::ProgVers {
        ::thruput_rpc_api::ProgVers::new(0x56475759, 1)
    }
    async fn dispatch(&self, proc: u32, data: &[u8]) -> Result<Vec<u8>, ::thruput_rpc_api::RpcError> {
        match proc {
            // viewgateway_intro
            0 => {
                let args: (ProtocolCommit, ) =
                    xdrs::txs::decode(data).map_err(|_| ::thruput_rpc_api::RpcError::GarbageArguments)?;
                let res = self.inner.viewgateway_intro(args.0).await.map_err(|_| ::thruput_rpc_api::RpcError::SystemError)?;
                xdrs::txs::encode(&res).map_err(|_| ::thruput_rpc_api::RpcError::SystemError)
            }
            // viewgateway_view
            1 => {
                let args: (TransactionViewQuery, ) =
                    xdrs::txs::decode(data).map_err(|_| ::thruput_rpc_api::RpcError::GarbageArguments)?;
                let res = self.inner.viewgateway_view(args.0).await.map_err(|_| ::thruput_rpc_api::RpcError::SystemError)?;
                xdrs::txs::encode(&res).map_err(|_| ::thruput_rpc_api::RpcError::SystemError)
            }
            // viewgateway_view_batch
            2 => {
                let args: (ViewGatewayBatchQuery, ) =
                    xdrs::txs::decode(data).map_err(|_| ::thruput_rpc_api::RpcError::GarbageArguments)?;
                let res = self.inner.viewgateway_view_batch(args.0).await.map_err(|_| ::thruput_rpc_api::RpcError::SystemError)?;
                xdrs::txs::encode(&res).map_err(|_| ::thruput_rpc_api::RpcError::SystemError)
            }
            _ => Err(::thruput_rpc_api::RpcError::InvalidProcedure),
        }
    }
}

#[derive(Clone)]
pub struct ViewGateway_ViewGateway1_Client {
    handle: ::std::sync::Arc<dyn ::thruput_rpc_api::RpcSender>,
}

impl ViewGateway_ViewGateway1_Client {
    pub fn new(handle: ::std::sync::Arc<dyn ::thruput_rpc_api::RpcSender>) -> Self {
        Self { handle }
    }

    fn prog_vers() -> ::thruput_rpc_api::ProgVers {
        ::thruput_rpc_api::ProgVers::new(0x56475759, 1)
    }
    pub async fn viewgateway_intro(&self, arg0 : &(impl xdrs::EncodesAs<ProtocolCommit> + ?Sized)) -> Result<ViewGatewayIntroOutcome, ::thruput_rpc_api::RpcError> {
         let mut call = self.handle.call_buf();
         call.append_with(|buf| {
             let mut w = xdrs::txs::buf_writer::BufWriter::from(::core::mem::take(buf));
             let r = xdrs::write_xdr(&(arg0), &mut w);
             *buf = w.into();
             r
         }).map_err(|_| ::thruput_rpc_api::RpcError::GarbageArguments)?;
         let mut out = ::core::option::Option::None;
         let mut decode = |reply: &[u8]| -> ::core::result::Result<(), ::thruput_rpc_api::RpcError> {
             out = ::core::option::Option::Some(xdrs::txs::decode(reply).map_err(|_| ::thruput_rpc_api::RpcError::SystemError)?);
             Ok(())
         };
         // SAFETY: the call future is awaited right here, so it lives in
         // this method's future along with `out` and `decode`. Once that
         // is polled it is pinned, so neither can be freed without the
         // call future being dropped first. Decoding never blocks.
         unsafe { self.handle.send_call_decoded(Self::prog_vers(), 0, call, &mut decode) }.await?;
         out.ok_or(::thruput_rpc_api::RpcError::SystemError)
    }
    pub async fn viewgateway_view(&self, arg0 : &(impl xdrs::EncodesAs<TransactionViewQuery> + ?Sized)) -> Result<ViewGatewayResult, ::thruput_rpc_api::RpcError> {
         let mut call = self.handle.call_buf();
         call.append_with(|buf| {
             let mut w = xdrs::txs::buf_writer::BufWriter::from(::core::mem::take(buf));
             let r = xdrs::write_xdr(&(arg0), &mut w);
             *buf = w.into();
             r
         }).map_err(|_| ::thruput_rpc_api::RpcError::GarbageArguments)?;
         let mut out = ::core::option::Option::None;
         let mut decode = |reply: &[u8]| -> ::core::result::Result<(), ::thruput_rpc_api::RpcError> {
             out = ::core::option::Option::Some(xdrs::txs::decode(reply).map_err(|_| ::thruput_rpc_api::RpcError::SystemError)?);
             Ok(())
         };
         // SAFETY: the call future is awaited right here, so it lives in
         // this method's future along with `out` and `decode`. Once that
         // is polled it is pinned, so neither can be freed without the
         // call future being dropped first. Decoding never blocks.
         unsafe { self.handle.send_call_decoded(Self::prog_vers(), 1, call, &mut decode) }.await?;
         out.ok_or(::thruput_rpc_api::RpcError::SystemError)
    }
    pub async fn viewgateway_view_batch(&self, arg0 : &(impl xdrs::EncodesAs<ViewGatewayBatchQuery> + ?Sized)) -> Result<ViewGatewayBatchResult, ::thruput_rpc_api::RpcError> {
         let mut call = self.handle.call_buf();
         call.append_with(|buf| {
             let mut w = xdrs::txs::buf_writer::BufWriter::from(::core::mem::take(buf));
             let r = xdrs::write_xdr(&(arg0), &mut w);
             *buf = w.into();
             r
         }).map_err(|_| ::thruput_rpc_api::RpcError::GarbageArguments)?;
         let mut out = ::core::option::Option::None;
         let mut decode = |reply: &[u8]| -> ::core::result::Result<(), ::thruput_rpc_api::RpcError> {
             out = ::core::option::Option::Some(xdrs::txs::decode(reply).map_err(|_| ::thruput_rpc_api::RpcError::SystemError)?);
             Ok(())
         };
         // SAFETY: the call future is awaited right here, so it lives in
         // this method's future along with `out` and `decode`. Once that
         // is polled it is pinned, so neither can be freed without the
         // call future being dropped first. Decoding never blocks.
         unsafe { self.handle.send_call_decoded(Self::prog_vers(), 2, call, &mut decode) }.await?;
         out.ok_or(::thruput_rpc_api::RpcError::SystemError)
    }
}

impl From<::std::sync::Arc<dyn ::thruput_rpc_api::RpcSender>> for ViewGateway_ViewGateway1_Client {
    fn from(handle: ::std::sync::Arc<dyn ::thruput_rpc_api::RpcSender>) -> Self {
        Self::new(handle)
    }
}



//
// XDR internals below this point
//

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

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

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

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