-
Notifications
You must be signed in to change notification settings - Fork 34
/
relay_signer.rs
71 lines (63 loc) · 1.95 KB
/
relay_signer.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use crate::utils::MithrilCommand;
use mithril_common::entities::PartyId;
use mithril_common::StdResult;
use std::collections::HashMap;
use std::path::Path;
use tokio::process::Child;
#[derive(Debug)]
pub struct RelaySigner {
listen_port: u64,
server_port: u64,
party_id: PartyId,
command: MithrilCommand,
process: Option<Child>,
}
impl RelaySigner {
pub fn new(
listen_port: u64,
server_port: u64,
dial_to: String,
aggregator_endpoint: &str,
party_id: PartyId,
work_dir: &Path,
bin_dir: &Path,
) -> StdResult<Self> {
let listen_port_str = format!("{listen_port}");
let server_port_str = format!("{server_port}");
let env = HashMap::from([
("LISTEN_PORT", listen_port_str.as_str()),
("SERVER_PORT", server_port_str.as_str()),
("AGGREGATOR_ENDPOINT", aggregator_endpoint),
("DIAL_TO", &dial_to),
("SIGNER_REPEATER_DELAY", "100"),
]);
let args = vec!["-vvv", "signer"];
let mut command = MithrilCommand::new("mithril-relay", work_dir, bin_dir, env, &args)?;
command.set_log_name(format!("mithril-relay-signer-{party_id}").as_str());
Ok(Self {
listen_port,
server_port,
party_id,
command,
process: None,
})
}
pub fn peer_addr(&self) -> String {
format!("/ip4/127.0.0.1/tcp/{}", self.listen_port)
}
pub fn endpoint(&self) -> String {
format!("http://localhost:{}", &self.server_port)
}
pub fn start(&mut self) -> StdResult<()> {
self.process = Some(self.command.start(&[])?);
Ok(())
}
pub async fn tail_logs(&self, number_of_line: u64) -> StdResult<()> {
self.command
.tail_logs(
Some(format!("mithril-relay-signer-{}", self.party_id).as_str()),
number_of_line,
)
.await
}
}