#![warn(missing_docs)]
#![warn(unused_crate_dependencies)]
use error::GrpcError;
use massa_models::slot::Slot;
use massa_proto_rs::massa::model::v1 as grpc_model;
use std::hash::Hash;
use tonic_health as _;
use tonic_reflection as _;
use tonic_web as _;
#[cfg(feature = "execution-trace")]
use serde_json as _;
pub mod config;
pub mod error;
pub mod handler;
pub mod private;
pub mod public;
pub mod server;
pub mod stream;
#[cfg(test)]
pub mod tests;
#[derive(Clone, Debug, Default, Eq, Hash, PartialEq)]
pub struct SlotRange {
start_slot: Option<Slot>,
end_slot: Option<Slot>,
}
impl SlotRange {
pub fn check(&self) -> Result<(), GrpcError> {
match (self.start_slot, self.end_slot) {
(None, None) => Err(GrpcError::InvalidArgument(
"Invalid slot range: both start slot and end slot are empty".to_string(),
)),
(Some(s_slot), Some(e_slot)) if s_slot > e_slot => {
Err(GrpcError::InvalidArgument(format!(
"Invalid slot range: start slot {} is greater than end slot {}",
s_slot, e_slot
)))
}
(Some(s_slot), Some(e_slot)) if e_slot < s_slot => {
Err(GrpcError::InvalidArgument(format!(
"Invalid slot range: end slot {} is lower to start slot {}",
s_slot, e_slot
)))
}
(Some(s_slot), Some(e_slot)) if s_slot == e_slot => {
Err(GrpcError::InvalidArgument(format!(
"Invalid slot range: start slot {} is equal to end slot {}",
s_slot, e_slot
)))
}
_ => Ok(()),
}
}
}
#[derive(Clone, Debug, Default, Eq, Hash, PartialEq)]
struct SlotDraw {
slot: Option<Slot>,
block_producer: Option<String>,
endorsement_draws: Vec<EndorsementDraw>,
}
#[derive(Clone, Debug, Default, Eq, Hash, PartialEq)]
struct EndorsementDraw {
index: u64,
producer: String,
}
impl From<SlotDraw> for grpc_model::SlotDraw {
fn from(value: SlotDraw) -> Self {
grpc_model::SlotDraw {
slot: value.slot.map(Into::into),
block_producer: value.block_producer,
endorsement_draws: value
.endorsement_draws
.into_iter()
.map(Into::into)
.collect(),
}
}
}
impl From<EndorsementDraw> for grpc_model::EndorsementDraw {
fn from(value: EndorsementDraw) -> Self {
grpc_model::EndorsementDraw {
index: value.index,
producer: value.producer,
}
}
}