Skip to content

Commit

Permalink
feat: update println! and eprintln! to info using tracing cargo.
Browse files Browse the repository at this point in the history
  • Loading branch information
devworlds committed Dec 19, 2024
1 parent 22da418 commit 0b30d0e
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
18 changes: 10 additions & 8 deletions roles/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions roles/test-utils/mining-device-sv1/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ serde_json = { version = "1.0.64", default-features = false, features = ["alloc"
v1 = { path="../../../protocols/v1", package="sv1_api" }
num-bigint = "0.4.3"
num-traits = "0.2.15"
tracing = "0.1.41"
tracing-subscriber = "0.3.19"
11 changes: 6 additions & 5 deletions roles/test-utils/mining-device-sv1/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use num_bigint::BigUint;
use num_traits::FromPrimitive;
use roles_logic_sv2::utils::Mutex;
use std::{sync::Arc, time};
use tracing::info;

use stratum_common::bitcoin::util::uint::Uint256;
use v1::{
Expand Down Expand Up @@ -105,17 +106,17 @@ impl Client {
match message {
Ok(msg) => {
if let Err(e) = sender_incoming.send(msg).await {
eprintln!("Failed to send message to receiver_incoming: {:?}", e);
info!("Failed to send message to receiver_incoming: {:?}", e);
break; // Exit the loop if sending fails
}
}
Err(e) => {
eprintln!("Error reading from socket: {:?}", e);
info!("Error reading from socket: {:?}", e);
break; // Exit the loop on read failure
}
}
}
eprintln!("Reader task terminated.");
info!("Reader task terminated.");
});

// Waits to receive a message from `sender_outgoing` and writes it to the socket for the
Expand Down Expand Up @@ -234,7 +235,7 @@ impl Client {
) {
// If we have a line (1 line represents 1 sv1 incoming message), then handle that message
if let Ok(line) = incoming_message {
println!(
info!(
"CLIENT {} - Received: {}",
self_.safe_lock(|s| s.client_id).unwrap(),
line
Expand All @@ -254,7 +255,7 @@ impl Client {
/// Send SV1 messages to the receiver_outgoing which writes to the socket (aka Upstream node)
async fn send_message(sender: Sender<String>, msg: json_rpc::Message) {
let msg = format!("{}\n", serde_json::to_string(&msg).unwrap());
println!(" - Send: {}", &msg);
info!(" - Send: {}", &msg);
sender.send(msg).await.unwrap();
}

Expand Down
2 changes: 2 additions & 0 deletions roles/test-utils/mining-device-sv1/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ pub(crate) use client::Client;

#[async_std::main]
async fn main() {
tracing_subscriber::fmt().init();

const ADDR: &str = "127.0.0.1:34255";
Client::connect(
80,
Expand Down
3 changes: 2 additions & 1 deletion roles/test-utils/mining-device-sv1/src/miner.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::job::Job;
use tracing::info;
use std::convert::TryInto;
use stratum_common::bitcoin::{
blockdata::block::BlockHeader,
Expand Down Expand Up @@ -75,7 +76,7 @@ impl Miner {
hash.reverse();
let hash = Uint256::from_be_bytes(hash);
if hash < *self.target.as_ref().ok_or(())? {
println!(
info!(
"Found share with nonce: {}, for target: {:?}, hash: {:?}",
header.nonce, self.target, hash
);
Expand Down

0 comments on commit 0b30d0e

Please sign in to comment.