tendermint/abci/response/
offer_snapshot.rs

1// bring into scope for doc links
2#[allow(unused)]
3use super::super::types::Snapshot;
4use crate::prelude::*;
5
6#[doc = include_str!("../doc/response-offersnapshot.md")]
7#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
8#[repr(i32)]
9pub enum OfferSnapshot {
10    /// Unknown result, abort all snapshot restoration
11    Unknown = 0,
12    /// Snapshot accepted, apply chunks
13    Accept = 1,
14    /// Abort all snapshot restoration
15    Abort = 2,
16    /// Reject this specific snapshot, try others
17    Reject = 3,
18    /// Reject all snapshots of this format, try others
19    RejectFormat = 4,
20    /// Reject all snapshots from the sender(s), try others
21    RejectSender = 5,
22}
23
24impl Default for OfferSnapshot {
25    fn default() -> Self {
26        Self::Unknown
27    }
28}
29
30// =============================================================================
31// Protobuf conversions
32// =============================================================================
33
34tendermint_pb_modules! {
35    use super::OfferSnapshot;
36
37    impl From<OfferSnapshot> for pb::abci::ResponseOfferSnapshot {
38        fn from(offer_snapshot: OfferSnapshot) -> Self {
39            Self {
40                result: offer_snapshot as i32,
41            }
42        }
43    }
44
45    impl TryFrom<pb::abci::ResponseOfferSnapshot> for OfferSnapshot {
46        type Error = crate::Error;
47
48        fn try_from(offer_snapshot: pb::abci::ResponseOfferSnapshot) -> Result<Self, Self::Error> {
49            Ok(match offer_snapshot.result {
50                0 => OfferSnapshot::Unknown,
51                1 => OfferSnapshot::Accept,
52                2 => OfferSnapshot::Abort,
53                3 => OfferSnapshot::Reject,
54                4 => OfferSnapshot::RejectFormat,
55                5 => OfferSnapshot::RejectSender,
56                _ => return Err(crate::Error::unsupported_offer_snapshot_chunk_result()),
57            })
58        }
59    }
60
61    impl Protobuf<pb::abci::ResponseOfferSnapshot> for OfferSnapshot {}
62}