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
use rill_protocol::config::ConfigPatch;
use rill_protocol::provider::EntryId;
use serde::Deserialize;
pub static NODE: ConfigPatch<String> = ConfigPatch::new("RILLRATE_NODE");
pub static NAME: ConfigPatch<EntryId> = ConfigPatch::new("RILLRATE_NAME");
#[derive(Deserialize, Debug, Clone)]
pub struct ProviderConfig {
pub node: Option<String>,
pub name: Option<EntryId>,
}
impl Default for ProviderConfig {
fn default() -> Self {
Self {
node: None,
name: None,
}
}
}
impl ProviderConfig {
pub fn is_node_specified(&self) -> bool {
NODE.env_var().is_ok() || self.node.is_some()
}
pub fn node_url(&self) -> String {
let host = NODE.get(|| self.node.clone(), || "localhost:1636".into());
format!("ws://{}/live/provider", host)
}
pub fn provider_name(&self) -> EntryId {
NAME.get(
|| self.name.clone(),
|| {
std::env::current_exe()
.ok()
.and_then(|path| path.to_str().map(EntryId::from))
.unwrap_or_else(|| "rillrate".into())
},
)
}
}