tendermint/block/
signed_header.rsuse serde::{Deserialize, Serialize};
use tendermint_proto::v0_37::types::SignedHeader as RawSignedHeader;
use crate::{block, Error};
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(try_from = "RawSignedHeader", into = "RawSignedHeader")] #[non_exhaustive]
pub struct SignedHeader {
pub header: block::Header,
pub commit: block::Commit,
}
tendermint_pb_modules! {
use super::SignedHeader;
use crate::Error;
use pb::types::SignedHeader as RawSignedHeader;
impl TryFrom<RawSignedHeader> for SignedHeader {
type Error = Error;
fn try_from(value: RawSignedHeader) -> Result<Self, Self::Error> {
let header = value
.header
.ok_or_else(Error::invalid_signed_header)?
.try_into()?;
let commit = value
.commit
.ok_or_else(Error::invalid_signed_header)?
.try_into()?;
Self::new(header, commit) }
}
impl From<SignedHeader> for RawSignedHeader {
fn from(value: SignedHeader) -> Self {
RawSignedHeader {
header: Some(value.header.into()),
commit: Some(value.commit.into()),
}
}
}
impl Protobuf<RawSignedHeader> for SignedHeader {}
}
impl SignedHeader {
pub fn new(header: block::Header, commit: block::Commit) -> Result<Self, Error> {
if header.height != commit.height {
return Err(Error::invalid_signed_header());
}
Ok(Self { header, commit })
}
pub fn header(&self) -> &block::Header {
&self.header
}
pub fn commit(&self) -> &block::Commit {
&self.commit
}
}