thruput-operator 0.71.0

Bindings for Thruput Operator1, the read-only status program every daemon can serve
Documentation
// Generated by xdrc 0.18.0 (xdrs d7777c37264da66eb41f8139bd539c4aa049fcc5). Do not edit.

// A read-only program every daemon can serve so thruput-ctl can ask what it is
// and where it stands.  This file imports no other .x file.

#![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::ops::{Deref, DerefMut};
use core::option::Option;
#[cfg(feature = "std")]
use std::io::{Read, Write};
use xdrs::*;
#[cfg(feature = "serde")]
use ::serde::{Deserialize, Serialize};

// always used optionally: absent, never short
pub type OperatorHash = [u8; 32];

pub type OperatorShortText = StringM<32>;

pub type OperatorText = StringM<64>;

pub type OperatorDetail = StringM<256>;

// Closed by design: a new value needs a new program version.  A client that
// sees a value it doesn't know reports it as an error.
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
#[cfg_attr(feature = "serde", serde(transparent))]
#[derive(schemars::JsonSchema)]
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[derive(Copy)]
#[repr(transparent)]
pub struct OperatorReadiness(pub i32);

impl OperatorReadiness {
    // not yet able to serve its role
    pub const OPERATOR_STARTING: Self = Self(0);
    pub const OPERATOR_READY: Self = Self(1);
    // was ready and is not (see detail); unused by coordinators in Operator1
    pub const OPERATOR_NOT_READY: Self = Self(2);
}

impl From<i32> for OperatorReadiness {
    fn from(v: i32) -> Self {
        Self(v)
    }
}

impl xdrs::XDRDiscriminant for OperatorReadiness {
    const ENCODING: xdrs::DiscriminantEncoding = xdrs::DiscriminantEncoding::Signed;
    fn discriminant(&self) -> i32 {
        self.0
    }
    fn from_discriminant(d: i32) -> Self {
        Self(d)
    }
}

#[cfg(feature = "std")]
impl core::fmt::Display for OperatorReadiness {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self.0 {
            x if x == Self::OPERATOR_STARTING.0 => {
                f.write_str("OperatorReadiness::OPERATOR_STARTING")
            }
            x if x == Self::OPERATOR_READY.0 => {
                f.write_str("OperatorReadiness::OPERATOR_READY")
            }
            x if x == Self::OPERATOR_NOT_READY.0 => {
                f.write_str("OperatorReadiness::OPERATOR_NOT_READY")
            }
            _ => write!(f, "OperatorReadiness({})", self.0),
        }
    }
}

// A height this process reports.  Names are lowercase snake_case ASCII.
// A daemon may report names a client does not know; the client ignores them.
//
// Known names:
//   decided    Highest height consensus has decided: the higher of committed
//              and the highest externalized.
//   committed  Highest height committed, as this process sees it.
// Later daemons add their own names with no version bump.
#[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 OperatorPosition {
    pub name: OperatorText,
    // >= 0
    // The block at that height, when known.  This is the same hash as the one
    // derived from the ConsensusValue at that height, so values compare across
    // sources.
    pub height: i64,
    pub block_hash: Option<OperatorHash>,
}

#[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 OperatorStatus {
    // What part the process plays, not which implementation it is:
    // "coordinator", "scheduler", "db", ...  thruput-ctl checks it, so an
    // endpoint that points at the wrong daemon is caught.
    pub role: OperatorShortText,
    // "chuckd", "coordinator", "hog-scheduler", ...
    pub process_name: OperatorText,
    // component release version
    pub build_version: OperatorText,
    // source commit of this build
    pub build_commit: OperatorText,
    // "hogp/..." (20 bytes); provenance only
    pub protocol_token: OperatorShortText,
    // absent until the daemon knows it
    pub network_hash: Option<OperatorHash>,
    pub readiness: OperatorReadiness,
    pub readiness_detail: OperatorDetail,
    pub positions: VecM<OperatorPosition, 64>,
}

/// 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 Operator_Operator1: Send + Sync {
    fn operator_null(
        &self,
    ) -> impl ::core::future::Future<
        Output = Result<impl xdrs::EncodesAs<()>, ::thruput_rpc_api::ProgramError>,
    > + Send;
    fn operator_status(
        &self,
    ) -> impl ::core::future::Future<
        Output = Result<
            impl xdrs::EncodesAs<OperatorStatus>,
            ::thruput_rpc_api::ProgramError,
        >,
    > + Send;
}

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

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

#[async_trait::async_trait]
impl<__Handler: Operator_Operator1> ::thruput_rpc_api::RpcHandler
for Operator_Operator1_Dispatcher<__Handler> {
    fn prog_vers(&self) -> ::thruput_rpc_api::ProgVers {
        ::thruput_rpc_api::ProgVers::new(0x20000000, 1)
    }
    async fn dispatch(
        &self,
        proc: u32,
        data: &[u8],
    ) -> Result<Vec<u8>, ::thruput_rpc_api::RpcError> {
        match proc {
            // operator_null
            0 => {
                let args: () = xdrs::txs::decode(data)
                    .map_err(|_| ::thruput_rpc_api::RpcError::GarbageArguments)?;
                let res = self
                    .inner
                    .operator_null()
                    .await
                    .map_err(|_| ::thruput_rpc_api::RpcError::SystemError)?;
                xdrs::txs::encode(&res)
                    .map_err(|_| ::thruput_rpc_api::RpcError::SystemError)
            }
            // operator_status
            1 => {
                let args: () = xdrs::txs::decode(data)
                    .map_err(|_| ::thruput_rpc_api::RpcError::GarbageArguments)?;
                let res = self
                    .inner
                    .operator_status()
                    .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 Operator_Operator1_Client {
    handle: ::std::sync::Arc<dyn ::thruput_rpc_api::RpcSender>,
}

impl Operator_Operator1_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(0x20000000, 1)
    }
    // SAFETY: the call future is awaited within this method, 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.
    pub async fn operator_null(&self) -> Result<(), ::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(&(), &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(())
        };
        unsafe { self.handle.send_call_decoded(Self::prog_vers(), 0, call, &mut decode) }
            .await?;
        out.ok_or(::thruput_rpc_api::RpcError::SystemError)
    }
    // SAFETY: the call future is awaited within this method, 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.
    pub async fn operator_status(
        &self,
    ) -> Result<OperatorStatus, ::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(&(), &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(())
        };
        unsafe { self.handle.send_call_decoded(Self::prog_vers(), 1, call, &mut decode) }
            .await?;
        out.ok_or(::thruput_rpc_api::RpcError::SystemError)
    }
}

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