1#![allow(non_camel_case_types)]
7#![allow(non_snake_case)]
8#![allow(non_upper_case_globals)]
9#![allow(unused_imports)]
10#![allow(dead_code)]
11#![allow(unused_variables)]
12#![allow(clippy::unnecessary_cast)]
13
14use crate::*;
15use core::option::Option;
16use core::ops::{Deref, DerefMut};
17
18#[cfg(feature = "std")]
19use std::io::{Read, Write};
20use xdrs::*;
21
22
23#[cfg(feature = "serde")]
24use ::serde::{{Serialize, Deserialize}};
25
26
27
28#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
30#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
31#[derive(schemars::JsonSchema)]
32#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
33#[repr(C)]
34pub struct EventCard {
35 pub protocol: ProtocolCommit,
36 pub upid: UPID,
37 pub address_for_exec: ServerAddress,
38 pub address_for_sched: ServerAddress,
39}
40
41#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
42#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
43#[derive(schemars::JsonSchema)]
44#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
45#[repr(C)]
46pub struct EventCanonicalTip {
47 pub block_id: BlockID,
48 pub consensus_value: ConsensusValue,
49}
50
51#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
52#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
53#[derive(schemars::JsonSchema)]
54#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
55#[repr(C)]
56pub struct EventRegistrationSnapshot {
57 pub tip: EventCanonicalTip,
58 pub token: u64,
59}
60
61#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
62#[cfg_attr(feature = "serde", serde(transparent))]
63#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
64#[derive(schemars::JsonSchema)]
65#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
66#[derive(Copy)]
67#[repr(transparent)]
68pub struct EventPrepareOutcome(pub i32);
69
70impl EventPrepareOutcome {
71 pub const EventPrepareOK: Self = Self(0);
72 pub const EventPrepareNotReady: Self = Self(1);
73 pub const EventPrepareError: Self = Self(2);
74}
75impl From<i32> for EventPrepareOutcome {
76 fn from(v: i32) -> Self {
77 Self(v)
78 }
79}
80#[cfg(feature = "std")]
81impl core::fmt::Display for EventPrepareOutcome {
82 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
83 match self.0 {
84 x if x == Self::EventPrepareOK.0 => {
85 write!(f, "EventPrepareOutcome::EventPrepareOK")
86 },
87 x if x == Self::EventPrepareNotReady.0 => {
88 write!(f, "EventPrepareOutcome::EventPrepareNotReady")
89 },
90 x if x == Self::EventPrepareError.0 => {
91 write!(f, "EventPrepareOutcome::EventPrepareError")
92 },
93 _ => {
94 write!(f, "EventPrepareOutcome({})", self.0)
95 }
96 }
97 }
98}
99
100
101#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
102#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
103#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
104#[derive(schemars::JsonSchema)]
105#[repr(i32)]
106#[non_exhaustive]
107pub enum EventPrepareResult {
108 EventPrepareOK { snapshot: EventRegistrationSnapshot } = EventPrepareOutcome::EventPrepareOK.0 as i32,
111 #[xdr(default_variant)] Default { outcome: i32 },
114}
115
116#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
117#[cfg_attr(feature = "serde", serde(transparent))]
118#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
119#[derive(schemars::JsonSchema)]
120#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
121#[derive(Copy)]
122#[repr(transparent)]
123pub struct EventActivationOutcome(pub i32);
124
125impl EventActivationOutcome {
126 pub const EventActivationOK: Self = Self(0);
127 pub const EventActivationRetry: Self = Self(1);
128 pub const EventActivationError: Self = Self(2);
129}
130impl From<i32> for EventActivationOutcome {
131 fn from(v: i32) -> Self {
132 Self(v)
133 }
134}
135#[cfg(feature = "std")]
136impl core::fmt::Display for EventActivationOutcome {
137 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
138 match self.0 {
139 x if x == Self::EventActivationOK.0 => {
140 write!(f, "EventActivationOutcome::EventActivationOK")
141 },
142 x if x == Self::EventActivationRetry.0 => {
143 write!(f, "EventActivationOutcome::EventActivationRetry")
144 },
145 x if x == Self::EventActivationError.0 => {
146 write!(f, "EventActivationOutcome::EventActivationError")
147 },
148 _ => {
149 write!(f, "EventActivationOutcome({})", self.0)
150 }
151 }
152 }
153}
154
155
156#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
157#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
158#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
159#[derive(schemars::JsonSchema)]
160#[repr(i32)]
161#[non_exhaustive]
162pub enum EventActivationResult {
163 EventActivationRetry { current_tip: EventCanonicalTip } = EventActivationOutcome::EventActivationRetry.0 as i32,
166 #[xdr(default_variant)] Default { outcome: i32 },
169}
170
171
172#[allow(non_camel_case_types)]
176pub trait SchedEvent_SchedEvent1: Send + Sync {
177 fn schedevent_prepare_event(&self, arg0 : EventCard) -> impl ::core::future::Future<Output = Result<impl xdrs::EncodesAs<EventPrepareResult>, ::thruput_rpc_api::ProgramError>> + Send;
178
179 fn schedevent_activate_event(&self, arg0 : EventRegistrationSnapshot) -> impl ::core::future::Future<Output = Result<impl xdrs::EncodesAs<EventActivationResult>, ::thruput_rpc_api::ProgramError>> + Send;
180}
181
182
183#[allow(non_camel_case_types)]
184pub struct SchedEvent_SchedEvent1_Dispatcher<__Handler> {
185 inner: Box<__Handler>,
186}
187
188impl<__Handler: SchedEvent_SchedEvent1> SchedEvent_SchedEvent1_Dispatcher<__Handler> {
189 pub fn new(inner: Box<__Handler>) -> Self {
190 Self { inner }
191 }
192}
193
194#[async_trait::async_trait]
195impl<__Handler: SchedEvent_SchedEvent1> ::thruput_rpc_api::RpcHandler for SchedEvent_SchedEvent1_Dispatcher<__Handler> {
196 fn prog_vers(&self) -> ::thruput_rpc_api::ProgVers {
197 ::thruput_rpc_api::ProgVers::new(0x7ee79996, 1)
198 }
199 async fn dispatch(&self, proc: u32, data: &[u8]) -> Result<Vec<u8>, ::thruput_rpc_api::RpcError> {
200 match proc {
201 1 => {
203 let args: (EventCard, ) =
204 xdrs::txs::decode(data).map_err(|_| ::thruput_rpc_api::RpcError::GarbageArguments)?;
205 let res = self.inner.schedevent_prepare_event(args.0).await.map_err(|_| ::thruput_rpc_api::RpcError::SystemError)?;
206 xdrs::txs::encode(&res).map_err(|_| ::thruput_rpc_api::RpcError::SystemError)
207 }
208 2 => {
210 let args: (EventRegistrationSnapshot, ) =
211 xdrs::txs::decode(data).map_err(|_| ::thruput_rpc_api::RpcError::GarbageArguments)?;
212 let res = self.inner.schedevent_activate_event(args.0).await.map_err(|_| ::thruput_rpc_api::RpcError::SystemError)?;
213 xdrs::txs::encode(&res).map_err(|_| ::thruput_rpc_api::RpcError::SystemError)
214 }
215 _ => Err(::thruput_rpc_api::RpcError::InvalidProcedure),
216 }
217 }
218}
219
220#[derive(Clone)]
221pub struct SchedEvent_SchedEvent1_Client {
222 handle: ::std::sync::Arc<dyn ::thruput_rpc_api::RpcSender>,
223}
224
225impl SchedEvent_SchedEvent1_Client {
226 pub fn new(handle: ::std::sync::Arc<dyn ::thruput_rpc_api::RpcSender>) -> Self {
227 Self { handle }
228 }
229
230 fn prog_vers() -> ::thruput_rpc_api::ProgVers {
231 ::thruput_rpc_api::ProgVers::new(0x7ee79996, 1)
232 }
233 pub async fn schedevent_prepare_event(&self, arg0 : &(impl xdrs::EncodesAs<EventCard> + ?Sized)) -> Result<EventPrepareResult, ::thruput_rpc_api::RpcError> {
234 let mut call = self.handle.call_buf();
235 call.append_with(|buf| {
236 let mut w = xdrs::txs::buf_writer::BufWriter::from(::core::mem::take(buf));
237 let r = xdrs::write_xdr(&(arg0), &mut w);
238 *buf = w.into();
239 r
240 }).map_err(|_| ::thruput_rpc_api::RpcError::GarbageArguments)?;
241 let mut out = ::core::option::Option::None;
242 let mut decode = |reply: &[u8]| -> ::core::result::Result<(), ::thruput_rpc_api::RpcError> {
243 out = ::core::option::Option::Some(xdrs::txs::decode(reply).map_err(|_| ::thruput_rpc_api::RpcError::SystemError)?);
244 Ok(())
245 };
246 unsafe { self.handle.send_call_decoded(Self::prog_vers(), 1, call, &mut decode) }.await?;
251 out.ok_or(::thruput_rpc_api::RpcError::SystemError)
252 }
253 pub async fn schedevent_activate_event(&self, arg0 : &(impl xdrs::EncodesAs<EventRegistrationSnapshot> + ?Sized)) -> Result<EventActivationResult, ::thruput_rpc_api::RpcError> {
254 let mut call = self.handle.call_buf();
255 call.append_with(|buf| {
256 let mut w = xdrs::txs::buf_writer::BufWriter::from(::core::mem::take(buf));
257 let r = xdrs::write_xdr(&(arg0), &mut w);
258 *buf = w.into();
259 r
260 }).map_err(|_| ::thruput_rpc_api::RpcError::GarbageArguments)?;
261 let mut out = ::core::option::Option::None;
262 let mut decode = |reply: &[u8]| -> ::core::result::Result<(), ::thruput_rpc_api::RpcError> {
263 out = ::core::option::Option::Some(xdrs::txs::decode(reply).map_err(|_| ::thruput_rpc_api::RpcError::SystemError)?);
264 Ok(())
265 };
266 unsafe { self.handle.send_call_decoded(Self::prog_vers(), 2, call, &mut decode) }.await?;
271 out.ok_or(::thruput_rpc_api::RpcError::SystemError)
272 }
273}
274
275impl From<::std::sync::Arc<dyn ::thruput_rpc_api::RpcSender>> for SchedEvent_SchedEvent1_Client {
276 fn from(handle: ::std::sync::Arc<dyn ::thruput_rpc_api::RpcSender>) -> Self {
277 Self::new(handle)
278 }
279}
280
281
282
283impl EventPrepareResult {
288 #[allow(clippy::match_single_binding)]
289 pub fn outcome(&self) -> EventPrepareOutcome {
290 match self {
291 EventPrepareResult::Default{ outcome } => (*outcome).into(),
292
293 _ => (unsafe { *(self as *const Self as *const i32) }).into(),
294 }
295 }
296}
297
298impl EventActivationResult {
299 #[allow(clippy::match_single_binding)]
300 pub fn outcome(&self) -> EventActivationOutcome {
301 match self {
302 EventActivationResult::Default{ outcome } => (*outcome).into(),
303
304 _ => (unsafe { *(self as *const Self as *const i32) }).into(),
305 }
306 }
307}
308
309