Final version

This commit is contained in:
transatoshi
2025-09-20 01:57:17 -07:00
parent e28e2d1d98
commit 7652299d25
2 changed files with 24 additions and 12 deletions

View File

@@ -14,7 +14,7 @@ import time
def run_grin_wallet(): def run_grin_wallet():
# Start the grin-wallet finalize command # Start the grin-wallet finalize command
command = "<DIR>/grin-wallet finalize" command = "/usr/local/bin/grin-wallet finalize"
child = pexpect.spawn(command) child = pexpect.spawn(command)
# Expect the password prompt and send the password # Expect the password prompt and send the password

View File

@@ -19,7 +19,7 @@ struct Response {
#[tokio::main] #[tokio::main]
async fn main() { async fn main() {
// Initialize logging // Initialize logging
let log_file = File::create("app.log").unwrap(); let log_file = File::create("finalize.log").unwrap();
CombinedLogger::init(vec![ CombinedLogger::init(vec![
TermLogger::new(LevelFilter::Info, Config::default(), TerminalMode::Mixed, ColorChoice::Auto), TermLogger::new(LevelFilter::Info, Config::default(), TerminalMode::Mixed, ColorChoice::Auto),
WriteLogger::new(LevelFilter::Info, Config::default(), log_file), WriteLogger::new(LevelFilter::Info, Config::default(), log_file),
@@ -45,36 +45,48 @@ async fn main() {
// Execute the command // Execute the command
let output = Command::new("bash") let output = Command::new("bash")
.arg("-c") .arg("-c")
.arg(format!( .arg("python3 /home/grin/grin-finalize/finalize.py")
"python <DIR>/finalize.py"
))
.output() .output()
.expect("Failed to execute command"); .expect("Failed to execute command");
// Process the command output // Process the command output
let stdout = String::from_utf8_lossy(&output.stdout); let stdout = String::from_utf8_lossy(&output.stdout);
let stderr = String::from_utf8_lossy(&output.stderr); let stderr = String::from_utf8_lossy(&output.stderr);
let _exit_status = output.status;
if stderr.is_empty() { // Log the outputs for debugging
info!("Command stdout: {}", stdout);
error!("Command stderr: {}", stderr);
// Check for specific success messages in stdout
if stdout.contains("The slatepack data is NOT encrypted") && stdout.contains("Command 'finalize' completed successfully") {
info!("Transaction finalized: {}", stdout); info!("Transaction finalized: {}", stdout);
return warp::reply::json(&Response { return warp::reply::json(&Response {
message: "Grin transaction successfully finalized ツ".to_string(), message: "Grin transaction successfully finalized ツ".to_string(),
}); });
} else { } else {
error!("Failed to finalize transaction: {}", stderr); let error_message = if !stderr.is_empty() {
stderr.to_string()
} else if !stdout.is_empty() {
stdout.to_string()
} else {
"Command executed but produced no output.".to_string()
};
error!("Failed to finalize transaction: {}", error_message);
return warp::reply::json(&Response { return warp::reply::json(&Response {
message: format!("Error: {}", stderr), message: format!("Error: {}", error_message),
}); });
} }
}); });
// Load SSL keys and certs // Load SSL keys and certs
let cert_path = "<DIR>/cert.pem"; let cert_path = "/etc/ssl/cert.pem";
let key_path = "<DIR>/cert.key"; let key_path = "/etc/ssl/privkey.pem";
// Enable CORS // Enable CORS
let cors = warp::cors() let cors = warp::cors()
.allow_origin("<URL>") .allow_origin("https://faucet.grinminer.net")
.allow_methods(vec!["POST"]) .allow_methods(vec!["POST"])
.allow_headers(vec!["Content-Type"]); .allow_headers(vec!["Content-Type"]);
@@ -83,7 +95,7 @@ async fn main() {
.tls() .tls()
.cert_path(cert_path) .cert_path(cert_path)
.key_path(key_path) .key_path(key_path)
.run(([0, 0, 0, 0], 3032)) // Listen on all interfaces .run(([0, 0, 0, 0], 3033)) // Listen on all interfaces
.await; .await;
} }