-
Notifications
You must be signed in to change notification settings - Fork 206
/
offer_snapshot.rs
47 lines (39 loc) · 1.42 KB
/
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
// =============================================================================
use core::convert::{TryFrom, TryInto};
use tendermint_proto::{abci as pb, Protobuf};
impl From<OfferSnapshot> for pb::RequestOfferSnapshot {
fn from(offer_snapshot: OfferSnapshot) -> Self {
Self {
snapshot: Some(offer_snapshot.snapshot.into()),
app_hash: offer_snapshot.app_hash.into(),
}
}
}
impl TryFrom<pb::RequestOfferSnapshot> for OfferSnapshot {
type Error = crate::Error;
fn try_from(offer_snapshot: pb::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::RequestOfferSnapshot> for OfferSnapshot {}