tendermint/abci/request/
offer_snapshot.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use super::super::types::Snapshot;
// bring into scope for doc links
#[allow(unused)]
use super::ApplySnapshotChunk;
use crate::{prelude::*, AppHash};

#[doc = include_str!("../doc/request-offersnapshot.md")]
#[derive(Clone, PartialEq, Eq, Debug)]
pub struct OfferSnapshot {
    /// The snapshot offered for restoration.
    pub snapshot: Snapshot,
    /// The light client verified app hash for this height.
    pub app_hash: AppHash,
}

// =============================================================================
// Protobuf conversions
// =============================================================================

tendermint_pb_modules! {
    use super::OfferSnapshot;

    impl From<OfferSnapshot> for pb::abci::RequestOfferSnapshot {
        fn from(offer_snapshot: OfferSnapshot) -> Self {
            Self {
                snapshot: Some(offer_snapshot.snapshot.into()),
                app_hash: offer_snapshot.app_hash.into(),
            }
        }
    }

    impl TryFrom<pb::abci::RequestOfferSnapshot> for OfferSnapshot {
        type Error = crate::Error;

        fn try_from(offer_snapshot: pb::abci::RequestOfferSnapshot) -> Result<Self, Self::Error> {
            Ok(Self {
                snapshot: offer_snapshot
                    .snapshot
                    .ok_or_else(crate::Error::missing_data)?
                    .try_into()?,
                app_hash: offer_snapshot.app_hash.try_into()?,
            })
        }
    }

    impl Protobuf<pb::abci::RequestOfferSnapshot> for OfferSnapshot {}
}