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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
use serde::{Deserialize, Serialize};
use std::str::FromStr;
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(tag = "type", content = "content")]
pub enum ControlMessage {
Nonce,
ResetWifi,
ResetKeys,
ResetAll,
QueryPolicy,
UpdatePolicy(Policy),
QueryAllowlist,
UpdateAllowlist(Vec<String>),
Ota(OtaParams),
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub enum ControlResponse {
Nonce(u64),
ResetWifi,
ResetKeys,
ResetAll,
PolicyCurrent(Policy),
PolicyUpdated(Policy),
AllowlistCurrent(Vec<String>),
AllowlistUpdated(Vec<String>),
OtaConfirm(OtaParams),
Error(String),
}
#[derive(Clone, Debug, Deserialize, Serialize, Default)]
pub struct Config {
pub broker: String,
pub ssid: String,
pub pass: String,
pub network: String,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Policy {
pub sat_limit: u64,
pub interval: Interval,
pub htlc_limit: u64,
}
impl Default for Policy {
fn default() -> Self {
Self {
sat_limit: 1_000_000,
interval: Interval::Daily,
htlc_limit: 1_000_000,
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
#[serde(rename_all = "lowercase")]
pub enum Interval {
Hourly,
Daily,
}
impl FromStr for Interval {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"daily" => Ok(Interval::Daily),
"hourly" => Ok(Interval::Hourly),
_ => Err("invalid interval".to_string()),
}
}
}
impl Interval {
pub fn as_str(&self) -> &'static str {
match self {
Interval::Hourly => "hourly",
Interval::Daily => "daily",
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct OtaParams {
pub version: u64,
pub url: String,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct WifiParams {
pub ssid: String,
pub password: String,
}