Skip to main content

thruput_view/
view_gateway.rs

1// -*-Rust-*-
2// Generated Code: DO NOT CHECK IN
3
4// Generated from xdrc commit: 6ab835b07c234abb4b0b50b61d687904727a4f32
5
6// clang-format off
7
8#![allow(non_camel_case_types)]
9#![allow(non_snake_case)]
10#![allow(non_upper_case_globals)]
11#![allow(unused_imports)]
12#![allow(dead_code)]
13#![allow(unused_variables)]
14#![allow(clippy::unnecessary_cast)]
15
16use crate::*;
17use core::option::Option;
18use core::ops::{Deref, DerefMut};
19
20#[cfg(feature = "std")]
21use std::io::{Read, Write};
22use xdrs::*;
23
24
25#[cfg(feature = "serde")]
26use ::serde::{{Serialize, Deserialize}};
27
28
29
30// clang-format on
31
32/// Successful view payload returned by ViewGateway1::viewgateway_view.
33///
34/// The height is the committed snapshot height used for the full view
35/// execution, not a post-execution tip sample. gas_consumed is
36/// TransactionViewResult::gas_consumed for that execution.
37#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
38#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
39#[derive(schemars::JsonSchema)]
40#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
41#[repr(C)]
42pub struct ViewGatewayPayload {
43    pub height: BlockHeight,
44    pub output: InvocationFrameOutput,
45    pub gas_consumed: GasAmount,
46    pub events: VecM<TxEmittedEvent>,
47}
48
49#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
50#[cfg_attr(feature = "serde", serde(transparent))]
51#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
52#[derive(schemars::JsonSchema)]
53#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
54#[derive(Copy)]
55#[repr(transparent)]
56pub struct ViewGatewayOutcome(pub i32);
57
58impl ViewGatewayOutcome {
59    pub const ViewGatewayOk: Self = Self(0);
60
61    // Raw view attempts returned Abandoned until the bounded service retry
62    // budget was exhausted. Callers may retry the public view request later.
63    pub const ViewGatewayAbandoned: Self = Self(1);
64
65    // Server-side invariant failure or unavailable execution dependency.
66    pub const ViewGatewayInternalError: Self = Self(2);
67
68    // The request was rejected before any frame output existed: forwarded
69    // tokens without a parent address or deeper than the network allows, an
70    // invocation the executor would not admit, or a root frame that failed on a
71    // syscall error before it returned, aborted, or faulted. Deterministic for
72    // the same request against the same state, so retrying does not help. The
73    // error_code arm carries the SyscallErrorCode the executor reported.
74    pub const ViewGatewayInvalidInput: Self = Self(3);
75}
76impl From<i32> for ViewGatewayOutcome {
77    fn from(v: i32) -> Self {
78        Self(v)
79    }
80}
81#[cfg(feature = "std")]
82impl core::fmt::Display for ViewGatewayOutcome {
83    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
84        match self.0 {
85            x if x == Self::ViewGatewayOk.0 => {
86                write!(f, "ViewGatewayOutcome::ViewGatewayOk")
87            },
88            x if x == Self::ViewGatewayAbandoned.0 => {
89                write!(f, "ViewGatewayOutcome::ViewGatewayAbandoned")
90            },
91            x if x == Self::ViewGatewayInternalError.0 => {
92                write!(f, "ViewGatewayOutcome::ViewGatewayInternalError")
93            },
94            x if x == Self::ViewGatewayInvalidInput.0 => {
95                write!(f, "ViewGatewayOutcome::ViewGatewayInvalidInput")
96            },
97            _ => {
98                write!(f, "ViewGatewayOutcome({})", self.0)
99            }
100        }
101    }
102}
103
104
105#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
106#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
107#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
108#[derive(schemars::JsonSchema)]
109#[repr(i32)]
110#[non_exhaustive]
111pub enum ViewGatewayResult {
112    // case ViewGatewayOk:
113    //   ViewGatewayPayload payload;
114    ViewGatewayOk { payload: ViewGatewayPayload } = ViewGatewayOutcome::ViewGatewayOk.0 as i32,
115    // case ViewGatewayAbandoned:
116    //   void;
117    ViewGatewayAbandoned = ViewGatewayOutcome::ViewGatewayAbandoned.0 as i32,
118    // case ViewGatewayInternalError:
119    //   void;
120    ViewGatewayInternalError = ViewGatewayOutcome::ViewGatewayInternalError.0 as i32,
121    // case ViewGatewayInvalidInput:
122    //   SyscallErrorCode error_code;
123    ViewGatewayInvalidInput { error_code: SyscallErrorCode } = ViewGatewayOutcome::ViewGatewayInvalidInput.0 as i32,
124    // default:
125    //   void;
126    #[xdr(default_variant)] Default { outcome: i32 },
127}
128
129#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
130#[cfg_attr(feature = "serde", serde(transparent))]
131#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
132#[derive(schemars::JsonSchema)]
133#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
134#[derive(Copy)]
135#[repr(transparent)]
136pub struct ViewGatewayIntroOutcome(pub i32);
137
138impl ViewGatewayIntroOutcome {
139    pub const ViewGatewayIntroSuccess: Self = Self(0);
140    pub const ViewGatewayIntroMismatchedProtocol: Self = Self(1);
141}
142impl From<i32> for ViewGatewayIntroOutcome {
143    fn from(v: i32) -> Self {
144        Self(v)
145    }
146}
147#[cfg(feature = "std")]
148impl core::fmt::Display for ViewGatewayIntroOutcome {
149    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
150        match self.0 {
151            x if x == Self::ViewGatewayIntroSuccess.0 => {
152                write!(f, "ViewGatewayIntroOutcome::ViewGatewayIntroSuccess")
153            },
154            x if x == Self::ViewGatewayIntroMismatchedProtocol.0 => {
155                write!(f, "ViewGatewayIntroOutcome::ViewGatewayIntroMismatchedProtocol")
156            },
157            _ => {
158                write!(f, "ViewGatewayIntroOutcome({})", self.0)
159            }
160        }
161    }
162}
163
164
165// Independent simulations against one committed snapshot. Calls do not see
166// each other's simulated writes. The trusted gateway applies operator request
167// limits before dispatch. RPC message-size limits also bound decoding.
168#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
169#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
170#[derive(schemars::JsonSchema)]
171#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
172#[repr(C)]
173pub struct ViewGatewayBatchQuery {
174    pub calls: VecM<TransactionViewQuery>,
175    // Freshness floor only: reject an older snapshot without waiting or
176    // requesting a refresh. Snapshot maintenance is shared across requests.
177    pub min_height: Option<BlockHeight>,
178    // Remaining work budget from receipt, including scheduling and retries.
179    // Must be positive. Running calls remain gas-bounded.
180    pub budget_millis: u32,
181    // Maximum XDR-encoded ViewGatewayBatchResult, including events.
182    // Must be positive; enforced while constructing the result.
183    pub max_response_bytes: u32,
184}
185
186#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
187#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
188#[derive(schemars::JsonSchema)]
189#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
190#[repr(C)]
191pub struct ViewGatewayBatchPayload {
192    pub height: BlockHeight,
193    pub results: VecM<TransactionViewResult>,
194}
195
196#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
197#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
198#[derive(schemars::JsonSchema)]
199#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
200#[repr(C)]
201pub struct ViewGatewayHeightUnavailable {
202    pub requested: BlockHeight,
203    pub observed: BlockHeight,
204}
205
206#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
207#[cfg_attr(feature = "serde", serde(transparent))]
208#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
209#[derive(schemars::JsonSchema)]
210#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
211#[derive(Copy)]
212#[repr(transparent)]
213pub struct ViewGatewayBatchOutcome(pub i32);
214
215impl ViewGatewayBatchOutcome {
216    pub const ViewGatewayBatchOk: Self = Self(0);
217    pub const ViewGatewayBatchInvalidRequest: Self = Self(1);
218    pub const ViewGatewayBatchHeightUnavailable: Self = Self(2);
219    pub const ViewGatewayBatchAbandoned: Self = Self(3);
220    pub const ViewGatewayBatchDeadlineExceeded: Self = Self(4);
221    pub const ViewGatewayBatchResponseTooLarge: Self = Self(5);
222    pub const ViewGatewayBatchInternalError: Self = Self(6);
223}
224impl From<i32> for ViewGatewayBatchOutcome {
225    fn from(v: i32) -> Self {
226        Self(v)
227    }
228}
229#[cfg(feature = "std")]
230impl core::fmt::Display for ViewGatewayBatchOutcome {
231    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
232        match self.0 {
233            x if x == Self::ViewGatewayBatchOk.0 => {
234                write!(f, "ViewGatewayBatchOutcome::ViewGatewayBatchOk")
235            },
236            x if x == Self::ViewGatewayBatchInvalidRequest.0 => {
237                write!(f, "ViewGatewayBatchOutcome::ViewGatewayBatchInvalidRequest")
238            },
239            x if x == Self::ViewGatewayBatchHeightUnavailable.0 => {
240                write!(f, "ViewGatewayBatchOutcome::ViewGatewayBatchHeightUnavailable")
241            },
242            x if x == Self::ViewGatewayBatchAbandoned.0 => {
243                write!(f, "ViewGatewayBatchOutcome::ViewGatewayBatchAbandoned")
244            },
245            x if x == Self::ViewGatewayBatchDeadlineExceeded.0 => {
246                write!(f, "ViewGatewayBatchOutcome::ViewGatewayBatchDeadlineExceeded")
247            },
248            x if x == Self::ViewGatewayBatchResponseTooLarge.0 => {
249                write!(f, "ViewGatewayBatchOutcome::ViewGatewayBatchResponseTooLarge")
250            },
251            x if x == Self::ViewGatewayBatchInternalError.0 => {
252                write!(f, "ViewGatewayBatchOutcome::ViewGatewayBatchInternalError")
253            },
254            _ => {
255                write!(f, "ViewGatewayBatchOutcome({})", self.0)
256            }
257        }
258    }
259}
260
261
262// Success contains exactly one ordered result per input call, all from height.
263// Contract aborts and faults are per-call results. Other failures discard the
264// whole attempt; abandoned batches retry as a group, never one call at a time.
265#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
266#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
267#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
268#[derive(schemars::JsonSchema)]
269#[repr(i32)]
270#[non_exhaustive]
271pub enum ViewGatewayBatchResult {
272    // case ViewGatewayBatchOk:
273    //   ViewGatewayBatchPayload payload;
274    ViewGatewayBatchOk { payload: ViewGatewayBatchPayload } = ViewGatewayBatchOutcome::ViewGatewayBatchOk.0 as i32,
275    // case ViewGatewayBatchHeightUnavailable:
276    //   ViewGatewayHeightUnavailable height_unavailable;
277    ViewGatewayBatchHeightUnavailable { height_unavailable: ViewGatewayHeightUnavailable } = ViewGatewayBatchOutcome::ViewGatewayBatchHeightUnavailable.0 as i32,
278    // default:
279    //   void;
280    #[xdr(default_variant)] Default { outcome: i32 },
281}
282
283
284/// Each handler replies with anything that encodes like the reply type.
285/// Implementations can be plain `async fn`s returning a concrete reply type
286/// under `#[allow(refining_impl_trait)]`.
287#[allow(non_camel_case_types)]
288pub trait ViewGateway_ViewGateway1: Send + Sync {    
289    fn viewgateway_intro(&self, arg0 : ProtocolCommit) -> impl ::core::future::Future<Output = Result<impl xdrs::EncodesAs<ViewGatewayIntroOutcome>, ::thruput_rpc_api::ProgramError>> + Send;
290    
291    fn viewgateway_view(&self, arg0 : TransactionViewQuery) -> impl ::core::future::Future<Output = Result<impl xdrs::EncodesAs<ViewGatewayResult>, ::thruput_rpc_api::ProgramError>> + Send;
292    
293    fn viewgateway_view_batch(&self, arg0 : ViewGatewayBatchQuery) -> impl ::core::future::Future<Output = Result<impl xdrs::EncodesAs<ViewGatewayBatchResult>, ::thruput_rpc_api::ProgramError>> + Send;
294}
295
296
297#[allow(non_camel_case_types)]
298pub struct ViewGateway_ViewGateway1_Dispatcher<__Handler> {
299  inner: Box<__Handler>,
300}
301
302impl<__Handler: ViewGateway_ViewGateway1> ViewGateway_ViewGateway1_Dispatcher<__Handler> {
303  pub fn new(inner: Box<__Handler>) -> Self {
304    Self { inner }
305  }
306}
307
308#[async_trait::async_trait]
309impl<__Handler: ViewGateway_ViewGateway1> ::thruput_rpc_api::RpcHandler for ViewGateway_ViewGateway1_Dispatcher<__Handler> {
310    fn prog_vers(&self) -> ::thruput_rpc_api::ProgVers {
311        ::thruput_rpc_api::ProgVers::new(0x56475759, 1)
312    }
313    async fn dispatch(&self, proc: u32, data: &[u8]) -> Result<Vec<u8>, ::thruput_rpc_api::RpcError> {
314        match proc {
315            // viewgateway_intro
316            0 => {
317                let args: (ProtocolCommit, ) =
318                    xdrs::txs::decode(data).map_err(|_| ::thruput_rpc_api::RpcError::GarbageArguments)?;
319                let res = self.inner.viewgateway_intro(args.0).await.map_err(|_| ::thruput_rpc_api::RpcError::SystemError)?;
320                xdrs::txs::encode(&res).map_err(|_| ::thruput_rpc_api::RpcError::SystemError)
321            }
322            // viewgateway_view
323            1 => {
324                let args: (TransactionViewQuery, ) =
325                    xdrs::txs::decode(data).map_err(|_| ::thruput_rpc_api::RpcError::GarbageArguments)?;
326                let res = self.inner.viewgateway_view(args.0).await.map_err(|_| ::thruput_rpc_api::RpcError::SystemError)?;
327                xdrs::txs::encode(&res).map_err(|_| ::thruput_rpc_api::RpcError::SystemError)
328            }
329            // viewgateway_view_batch
330            2 => {
331                let args: (ViewGatewayBatchQuery, ) =
332                    xdrs::txs::decode(data).map_err(|_| ::thruput_rpc_api::RpcError::GarbageArguments)?;
333                let res = self.inner.viewgateway_view_batch(args.0).await.map_err(|_| ::thruput_rpc_api::RpcError::SystemError)?;
334                xdrs::txs::encode(&res).map_err(|_| ::thruput_rpc_api::RpcError::SystemError)
335            }
336            _ => Err(::thruput_rpc_api::RpcError::InvalidProcedure),
337        }
338    }
339}
340
341#[derive(Clone)]
342pub struct ViewGateway_ViewGateway1_Client {
343    handle: ::std::sync::Arc<dyn ::thruput_rpc_api::RpcSender>,
344}
345
346impl ViewGateway_ViewGateway1_Client {
347    pub fn new(handle: ::std::sync::Arc<dyn ::thruput_rpc_api::RpcSender>) -> Self {
348        Self { handle }
349    }
350
351    fn prog_vers() -> ::thruput_rpc_api::ProgVers {
352        ::thruput_rpc_api::ProgVers::new(0x56475759, 1)
353    }
354    pub async fn viewgateway_intro(&self, arg0 : &(impl xdrs::EncodesAs<ProtocolCommit> + ?Sized)) -> Result<ViewGatewayIntroOutcome, ::thruput_rpc_api::RpcError> {
355         let mut call = self.handle.call_buf();
356         call.append_with(|buf| {
357             let mut w = xdrs::txs::buf_writer::BufWriter::from(::core::mem::take(buf));
358             let r = xdrs::write_xdr(&(arg0), &mut w);
359             *buf = w.into();
360             r
361         }).map_err(|_| ::thruput_rpc_api::RpcError::GarbageArguments)?;
362         let mut out = ::core::option::Option::None;
363         let mut decode = |reply: &[u8]| -> ::core::result::Result<(), ::thruput_rpc_api::RpcError> {
364             out = ::core::option::Option::Some(xdrs::txs::decode(reply).map_err(|_| ::thruput_rpc_api::RpcError::SystemError)?);
365             Ok(())
366         };
367         // SAFETY: the call future is awaited right here, so it lives in
368         // this method's future along with `out` and `decode`. Once that
369         // is polled it is pinned, so neither can be freed without the
370         // call future being dropped first. Decoding never blocks.
371         unsafe { self.handle.send_call_decoded(Self::prog_vers(), 0, call, &mut decode) }.await?;
372         out.ok_or(::thruput_rpc_api::RpcError::SystemError)
373    }
374    pub async fn viewgateway_view(&self, arg0 : &(impl xdrs::EncodesAs<TransactionViewQuery> + ?Sized)) -> Result<ViewGatewayResult, ::thruput_rpc_api::RpcError> {
375         let mut call = self.handle.call_buf();
376         call.append_with(|buf| {
377             let mut w = xdrs::txs::buf_writer::BufWriter::from(::core::mem::take(buf));
378             let r = xdrs::write_xdr(&(arg0), &mut w);
379             *buf = w.into();
380             r
381         }).map_err(|_| ::thruput_rpc_api::RpcError::GarbageArguments)?;
382         let mut out = ::core::option::Option::None;
383         let mut decode = |reply: &[u8]| -> ::core::result::Result<(), ::thruput_rpc_api::RpcError> {
384             out = ::core::option::Option::Some(xdrs::txs::decode(reply).map_err(|_| ::thruput_rpc_api::RpcError::SystemError)?);
385             Ok(())
386         };
387         // SAFETY: the call future is awaited right here, so it lives in
388         // this method's future along with `out` and `decode`. Once that
389         // is polled it is pinned, so neither can be freed without the
390         // call future being dropped first. Decoding never blocks.
391         unsafe { self.handle.send_call_decoded(Self::prog_vers(), 1, call, &mut decode) }.await?;
392         out.ok_or(::thruput_rpc_api::RpcError::SystemError)
393    }
394    pub async fn viewgateway_view_batch(&self, arg0 : &(impl xdrs::EncodesAs<ViewGatewayBatchQuery> + ?Sized)) -> Result<ViewGatewayBatchResult, ::thruput_rpc_api::RpcError> {
395         let mut call = self.handle.call_buf();
396         call.append_with(|buf| {
397             let mut w = xdrs::txs::buf_writer::BufWriter::from(::core::mem::take(buf));
398             let r = xdrs::write_xdr(&(arg0), &mut w);
399             *buf = w.into();
400             r
401         }).map_err(|_| ::thruput_rpc_api::RpcError::GarbageArguments)?;
402         let mut out = ::core::option::Option::None;
403         let mut decode = |reply: &[u8]| -> ::core::result::Result<(), ::thruput_rpc_api::RpcError> {
404             out = ::core::option::Option::Some(xdrs::txs::decode(reply).map_err(|_| ::thruput_rpc_api::RpcError::SystemError)?);
405             Ok(())
406         };
407         // SAFETY: the call future is awaited right here, so it lives in
408         // this method's future along with `out` and `decode`. Once that
409         // is polled it is pinned, so neither can be freed without the
410         // call future being dropped first. Decoding never blocks.
411         unsafe { self.handle.send_call_decoded(Self::prog_vers(), 2, call, &mut decode) }.await?;
412         out.ok_or(::thruput_rpc_api::RpcError::SystemError)
413    }
414}
415
416impl From<::std::sync::Arc<dyn ::thruput_rpc_api::RpcSender>> for ViewGateway_ViewGateway1_Client {
417    fn from(handle: ::std::sync::Arc<dyn ::thruput_rpc_api::RpcSender>) -> Self {
418        Self::new(handle)
419    }
420}
421
422
423
424//
425// XDR internals below this point
426//
427
428impl ViewGatewayResult {
429    #[allow(clippy::match_single_binding)]
430    pub fn outcome(&self) -> ViewGatewayOutcome {
431        match self {
432            ViewGatewayResult::Default{ outcome } => (*outcome).into(),
433
434            _ => (unsafe { *(self as *const Self as *const i32) }).into(),
435        }
436    }
437}
438
439impl ViewGatewayBatchResult {
440    #[allow(clippy::match_single_binding)]
441    pub fn outcome(&self) -> ViewGatewayBatchOutcome {
442        match self {
443            ViewGatewayBatchResult::Default{ outcome } => (*outcome).into(),
444
445            _ => (unsafe { *(self as *const Self as *const i32) }).into(),
446        }
447    }
448}
449
450