use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use crate::{BlockHash, Height};
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct BlockStatus {
pub in_best_chain: bool,
#[serde(skip_serializing_if = "Option::is_none")]
pub height: Option<Height>,
#[serde(skip_serializing_if = "Option::is_none")]
pub next_best: Option<BlockHash>,
}
impl BlockStatus {
pub fn in_best_chain(height: Height, next_best: Option<BlockHash>) -> Self {
Self {
in_best_chain: true,
height: Some(height),
next_best,
}
}
pub fn not_in_best_chain() -> Self {
Self {
in_best_chain: false,
height: None,
next_best: None,
}
}
}