thruput-scp 0.72.0

Bindings for Thruput scp rpcs
Documentation
// Generated by xdrc 0.18.0 (xdrs d7777c37264da66eb41f8139bd539c4aa049fcc5). Do not edit.

// Copyright 2015 Stellar Development Foundation and contributors. Licensed
// under the Apache License, Version 2.0. See the COPYING file at the root
// of this distribution or at http://www.apache.org/licenses/LICENSE-2.0

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

// clang-format on
pub type SCPHash = [u8; 32];

pub type SCPNodeID = PublicKey;

pub type SCPCount = u32;

pub type SCPSlotIndex = u64;

pub type SCPValue = BytesM;

pub type SCPValues = VecM<SCPValue>;

pub type SCPOptValue = Option<SCPValue>;

#[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 SCPBallot {
    // n
    pub counter: SCPCount,
    // x
    pub value: SCPValue,
}

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

impl SCPStatementType {
    pub const SCP_ST_PREPARE: Self = Self(0);
    pub const SCP_ST_CONFIRM: Self = Self(1);
    pub const SCP_ST_EXTERNALIZE: Self = Self(2);
    pub const SCP_ST_NOMINATE: Self = Self(3);
}

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

impl xdrs::XDRDiscriminant for SCPStatementType {
    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 SCPStatementType {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self.0 {
            x if x == Self::SCP_ST_PREPARE.0 => {
                f.write_str("SCPStatementType::SCP_ST_PREPARE")
            }
            x if x == Self::SCP_ST_CONFIRM.0 => {
                f.write_str("SCPStatementType::SCP_ST_CONFIRM")
            }
            x if x == Self::SCP_ST_EXTERNALIZE.0 => {
                f.write_str("SCPStatementType::SCP_ST_EXTERNALIZE")
            }
            x if x == Self::SCP_ST_NOMINATE.0 => {
                f.write_str("SCPStatementType::SCP_ST_NOMINATE")
            }
            _ => write!(f, "SCPStatementType({})", self.0),
        }
    }
}

#[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 SCPStatementNominate {
    // D
    pub quorum_set_hash: SCPHash,
    // X
    pub votes: VecM<SCPValue>,
    // Y
    pub accepted: VecM<SCPValue>,
}

#[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 SCPStatementPrepare {
    // D
    pub quorum_set_hash: SCPHash,
    // b
    pub ballot: SCPBallot,
    // p
    pub prepared: Option<SCPBallot>,
    // p'
    pub prepared_prime: Option<SCPBallot>,
    // c.n
    pub n_c: SCPCount,
    // h.n
    pub n_h: SCPCount,
}

#[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 SCPStatementConfirm {
    // b
    pub ballot: SCPBallot,
    // p.n
    pub n_prepared: SCPCount,
    // c.n
    pub n_commit: SCPCount,
    // h.n
    pub n_h: SCPCount,
    // D
    pub quorum_set_hash: SCPHash,
}

#[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 SCPStatementExternalize {
    // c
    pub commit: SCPBallot,
    // h.n
    pub n_h: SCPCount,
    // D used before EXTERNALIZE
    pub commit_quorum_set_hash: SCPHash,
}

#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
#[xdr(discriminant = "SCPStatementType")]
#[derive(schemars::JsonSchema)]
#[repr(i32)]
#[non_exhaustive]
pub enum SCPStatement_pledges {
    SCP_ST_PREPARE {
        prepare: SCPStatementPrepare,
    } = SCPStatementType::SCP_ST_PREPARE.0 as i32,
    SCP_ST_CONFIRM {
        confirm: SCPStatementConfirm,
    } = SCPStatementType::SCP_ST_CONFIRM.0 as i32,
    SCP_ST_EXTERNALIZE {
        externalize: SCPStatementExternalize,
    } = SCPStatementType::SCP_ST_EXTERNALIZE.0 as i32,
    SCP_ST_NOMINATE {
        nominate: SCPStatementNominate,
    } = SCPStatementType::SCP_ST_NOMINATE.0 as i32,
}

impl SCPStatement_pledges {
    #[allow(clippy::match_single_binding)]
    pub fn stmt_type(&self) -> SCPStatementType {
        match self {
            SCPStatement_pledges::SCP_ST_PREPARE { .. } => {
                SCPStatementType::SCP_ST_PREPARE
            }
            SCPStatement_pledges::SCP_ST_CONFIRM { .. } => {
                SCPStatementType::SCP_ST_CONFIRM
            }
            SCPStatement_pledges::SCP_ST_EXTERNALIZE { .. } => {
                SCPStatementType::SCP_ST_EXTERNALIZE
            }
            SCPStatement_pledges::SCP_ST_NOMINATE { .. } => {
                SCPStatementType::SCP_ST_NOMINATE
            }
        }
    }
}

#[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 SCPStatement {
    // v
    pub node_id: SCPNodeID,
    // i
    pub slot_index: SCPSlotIndex,
    pub pledges: SCPStatement_pledges,
}

#[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 SCPEnvelope {
    pub statement: SCPStatement,
    pub signature: Signature,
}

pub type SCPEnvelopes = VecM<SCPEnvelope>;

// supports things like: A,B,C,(D,E,F),(G,H,(I,J,K,L))
// only allows 2 levels of nesting
#[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 SCPQuorumSet {
    pub threshold: SCPCount,
    pub validators: VecM<SCPNodeID>,
    pub inner_sets: VecM<SCPQuorumSet>,
}

pub type SCPOptQuorumSet = Option<SCPQuorumSet>;