hopr_protocol_hopr/codec/
mod.rs1mod decoder;
2mod encoder;
3
4pub use decoder::HoprDecoder;
5pub use encoder::HoprEncoder;
6
7fn default_outgoing_win_prob() -> Option<hopr_internal_types::prelude::WinningProbability> {
8 Some(hopr_internal_types::prelude::WinningProbability::ALWAYS)
9}
10
11#[cfg_attr(feature = "serde", cfg_eval::cfg_eval, serde_with::serde_as)]
13#[derive(Clone, Copy, Debug, smart_default::SmartDefault, validator::Validate)]
14#[cfg_attr(
15 feature = "serde",
16 derive(serde::Serialize, serde::Deserialize),
17 serde(deny_unknown_fields)
18)]
19pub struct HoprCodecConfig {
20 #[cfg_attr(
24 feature = "serde",
25 serde(default),
26 serde_as(as = "Option<serde_with::DisplayFromStr>")
27 )]
28 pub outgoing_ticket_price: Option<hopr_primitive_types::balance::HoprBalance>,
29 #[cfg_attr(
36 feature = "serde",
37 serde(default = "default_outgoing_win_prob"),
38 serde_as(as = "Option<serde_with::DisplayFromStr>")
39 )]
40 #[default(default_outgoing_win_prob())]
41 pub outgoing_win_prob: Option<hopr_internal_types::prelude::WinningProbability>,
42}
43
44impl PartialEq for HoprCodecConfig {
45 fn eq(&self, other: &Self) -> bool {
46 self.outgoing_ticket_price.eq(&other.outgoing_ticket_price)
47 && match (self.outgoing_win_prob, other.outgoing_win_prob) {
48 (Some(a), Some(b)) => a.approx_eq(&b),
49 (None, None) => true,
50 _ => false,
51 }
52 }
53}