Skip to content

Commit 4c64407

Browse files
committed
ledger cleanup
1 parent 5b4349a commit 4c64407

File tree

4 files changed

+47
-144
lines changed

4 files changed

+47
-144
lines changed

Cargo.lock

Lines changed: 3 additions & 106 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wallet/Cargo.toml

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,29 +53,25 @@ zeroize.workspace = true
5353
[dev-dependencies]
5454
chainstate-test-framework = { path = "../chainstate/test-framework" }
5555
test-utils = { path = "../test-utils" }
56-
tokio = { workspace = true, default-features = false, features = [
57-
"io-util",
58-
"macros",
59-
"net",
60-
"rt",
61-
"sync",
62-
] }
63-
strum = { workspace = true }
64-
reqwest = { workspace = true, features = ["json"] }
65-
tracing = { workspace = true }
66-
anyhow = { workspace = true }
67-
clap = { workspace = true }
68-
bollard = "0.14"
69-
bytes = "1.10"
70-
tar = "0.4"
71-
7256

57+
anyhow.workspace = true
58+
clap.workspace = true
7359
ctor.workspace = true
7460
lazy_static.workspace = true
61+
reqwest = { workspace = true, features = ["json"] }
7562
rstest.workspace = true
7663
serde_json.workspace = true
7764
serial_test.workspace = true
65+
strum.workspace = true
7866
tempfile.workspace = true
67+
tokio = { workspace = true, default-features = false, features = [
68+
"io-util",
69+
"macros",
70+
"net",
71+
"rt",
72+
"sync",
73+
] }
74+
tracing.workspace = true
7975

8076
[features]
8177
trezor = ["dep:trezor-client", "wallet-types/trezor"]

wallet/src/signer/ledger_signer/speculus/drivers/mod.rs

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ use tokio::{
2424
process::Command as TokioCommand,
2525
sync::oneshot::{channel, Sender},
2626
};
27-
use tracing::debug;
2827

2928
use crate::signer::ledger_signer::speculus::{Handle, Options};
3029

@@ -64,7 +63,6 @@ impl PodmanDriver {
6463
Ok(Self)
6564
}
6665

67-
/// Helper to run a synchronous std::process::Command in a non-blocking way.
6866
fn run_command(mut command: std::process::Command) -> anyhow::Result<std::process::Output> {
6967
let command_str = format!("{:?}", command);
7068
let output = command.output().unwrap();
@@ -77,7 +75,7 @@ impl PodmanDriver {
7775
String::from_utf8_lossy(&output.stderr)
7876
);
7977
}
80-
debug!(
78+
logging::log::debug!(
8179
"Successfully ran podman command: {}\nSTDOUT: {}",
8280
command_str,
8381
String::from_utf8_lossy(&output.stdout)
@@ -96,7 +94,7 @@ impl Driver for PodmanDriver {
9694
let name = format!("speculos-{}", opts.http_port);
9795

9896
// Ensure any previous container with the same name is removed.
99-
debug!("Force removing existing container '{}'", &name);
97+
logging::log::debug!("Force removing existing container '{}'", &name);
10098
let mut cleanup_cmd = std::process::Command::new("podman");
10199
cleanup_cmd.args(["rm", "-f", &name]);
102100
// We don't care if this fails (e.g., if the container didn't exist).
@@ -117,12 +115,11 @@ impl Driver for PodmanDriver {
117115
let mut speculos_cmd_args = opts.args();
118116
speculos_cmd_args.push(format!("/app/{}", app_file_name));
119117

120-
debug!("Container command: {}", speculos_cmd_args.join(" "));
118+
logging::log::debug!("Container command: {}", speculos_cmd_args.join(" "));
121119

122120
// Build the `podman run` command.
123121
let mut command = std::process::Command::new("podman");
124122
command.arg("run");
125-
// command.args(["--detach", "--name", &name]);
126123
command.arg("--detach");
127124
command.arg("--name");
128125
command.arg(&name);
@@ -138,25 +135,24 @@ impl Driver for PodmanDriver {
138135
command.arg("-p").arg(format!("{}:{}", port, port));
139136
}
140137

141-
// Mount the app's directory as a volume instead of copying the file.
142-
// This is simpler and more efficient than creating a tarball.
138+
// Mount the app's directory as a volume
143139
command.arg("-v").arg(format!("{}:/app:ro", app_parent_dir));
144140

145141
// Set image and the command to run.
146142
command.arg(DEFAULT_IMAGE);
147143
command.args(&speculos_cmd_args);
148144

149145
// Create and start the container.
150-
debug!("Creating and starting container '{}'", &name);
146+
logging::log::debug!("Creating and starting container '{}'", &name);
151147
Self::run_command(command)?;
152-
debug!("Container '{}' started", &name);
148+
logging::log::debug!("Container '{}' started", &name);
153149

154150
let (exit_tx, mut exit_rx) = channel();
155151

156152
// Spawn a task to stream container logs.
157153
let container_name_clone = name.clone();
158154
tokio::spawn(async move {
159-
debug!(
155+
logging::log::debug!(
160156
"Starting log streaming for container '{}'",
161157
container_name_clone
162158
);
@@ -168,7 +164,7 @@ impl Driver for PodmanDriver {
168164
let mut child = match cmd.spawn() {
169165
Ok(child) => child,
170166
Err(e) => {
171-
debug!("Failed to spawn podman logs: {}", e);
167+
logging::log::debug!("Failed to spawn podman logs: {}", e);
172168
return;
173169
}
174170
};
@@ -183,23 +179,23 @@ impl Driver for PodmanDriver {
183179
tokio::select! {
184180
// Check for exit signal
185181
_ = &mut exit_rx => {
186-
debug!("Received exit signal for log streaming. Killing process.");
182+
logging::log::debug!("Received exit signal for log streaming. Killing process.");
187183
let _ = child.kill().await;
188184
break;
189185
},
190186
// Read from stdout
191187
Ok(Some(line)) = stdout_reader.next_line() => {
192-
println!("[{}] {}", container_name_clone, line);
188+
logging::log::debug!("[{}] {}", container_name_clone, line);
193189
},
194190
// Read from stderr
195191
Ok(Some(line)) = stderr_reader.next_line() => {
196-
eprintln!("[{}] {}", container_name_clone, line);
192+
logging::log::debug!("[{}] {}", container_name_clone, line);
197193
},
198194
// Break if log stream ends
199195
else => break,
200196
}
201197
}
202-
debug!(
198+
logging::log::debug!(
203199
"Log streaming task for '{}' finished.",
204200
container_name_clone
205201
);
@@ -214,8 +210,7 @@ impl Driver for PodmanDriver {
214210
}
215211

216212
fn exit(&self, handle: Self::Handle) -> anyhow::Result<()> {
217-
debug!("Stopping container {}", handle.name);
218-
eprintln!("Stopping container {}", handle.name);
213+
logging::log::debug!("Stopping container {}", handle.name);
219214

220215
// Signal the log streaming task to terminate.
221216
let _ = handle.exit_tx.send(());
@@ -227,12 +222,12 @@ impl Driver for PodmanDriver {
227222
let _ = Self::run_command(stop_cmd);
228223

229224
// Remove the container.
230-
debug!("Removing container {}", handle.name);
225+
logging::log::debug!("Removing container {}", handle.name);
231226
let mut rm_cmd = std::process::Command::new("podman");
232227
rm_cmd.args(["rm", "-f", &handle.name]);
233228
Self::run_command(rm_cmd)?;
234229

235-
debug!("Container {} removed", handle.name);
230+
logging::log::debug!("Container {} removed", handle.name);
236231
Ok(())
237232
}
238233
}

0 commit comments

Comments
 (0)