Skip to content

Commit

Permalink
remove async-std from mining-device-sv1
Browse files Browse the repository at this point in the history
  • Loading branch information
Shourya742 committed Feb 1, 2025
1 parent d9d7ec7 commit f414ad9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
10 changes: 5 additions & 5 deletions roles/Cargo.lock

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

2 changes: 1 addition & 1 deletion roles/test-utils/mining-device-sv1/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ path = "src/lib.rs"
[dependencies]
stratum-common = { path = "../../../common" }
async-channel = "1.5.1"
async-std = { version = "1.8.0", features = ["attributes"] }
roles_logic_sv2 = { path = "../../../protocols/v2/roles-logic-sv2" }
serde = { version = "1.0.89", default-features = false, features = ["derive", "alloc"] }
serde_json = { version = "1.0.64", default-features = false, features = ["alloc"] }
Expand All @@ -29,3 +28,4 @@ num-bigint = "0.4.3"
num-traits = "0.2.15"
tracing = "0.1.41"
tracing-subscriber = "0.3.19"
tokio = { version = "1.43.0", features = ["full"] }
23 changes: 13 additions & 10 deletions roles/test-utils/mining-device-sv1/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
use async_std::net::TcpStream;
use std::{convert::TryInto, net::SocketAddr, ops::Div};

use async_channel::{bounded, Receiver, Sender};
use async_std::{io::BufReader, prelude::*, task};
use num_bigint::BigUint;
use num_traits::FromPrimitive;
use roles_logic_sv2::utils::Mutex;
use std::{sync::Arc, time};
use tokio::{
io::{AsyncBufReadExt, AsyncWriteExt, BufReader},
net::TcpStream,
task,
};
use tracing::{error, info, warn};

use stratum_common::bitcoin::util::uint::Uint256;
Expand Down Expand Up @@ -69,8 +72,8 @@ impl Client {
/// and then serialized into a json message that is sent to the Upstream via
/// `sender_outgoing`.
pub async fn connect(client_id: u32, upstream_addr: SocketAddr) {
let stream = std::sync::Arc::new(TcpStream::connect(upstream_addr).await.unwrap());
let (reader, writer) = (stream.clone(), stream);
let stream = TcpStream::connect(upstream_addr).await.unwrap();
let (reader, mut writer) = stream.into_split();

// `sender_incoming` listens on socket for incoming messages from the Upstream and sends
// messages to the `receiver_incoming` to be parsed and handled by the `Client`
Expand Down Expand Up @@ -101,17 +104,17 @@ impl Client {
// Reads messages sent by the Upstream from the socket to be passed to the
// `receiver_incoming`
task::spawn(async move {
let mut messages = BufReader::new(&*reader).lines();
while let Some(message) = messages.next().await {
let mut messages = BufReader::new(reader).lines();
while let Ok(message) = messages.next_line().await {
match message {
Ok(msg) => {
Some(msg) => {
if let Err(e) = sender_incoming.send(msg).await {
error!("Failed to send message to receiver_incoming: {:?}", e);
break; // Exit the loop if sending fails
}
}
Err(e) => {
error!("Error reading from socket: {:?}", e);
None => {
error!("Error reading from socket");
break; // Exit the loop on read failure
}
}
Expand All @@ -124,7 +127,7 @@ impl Client {
task::spawn(async move {
loop {
let message: String = receiver_outgoing.recv().await.unwrap();
(&*writer).write_all(message.as_bytes()).await.unwrap();
(writer).write_all(message.as_bytes()).await.unwrap();
}
});

Expand Down
2 changes: 1 addition & 1 deletion roles/test-utils/mining-device-sv1/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{net::SocketAddr, str::FromStr};

pub(crate) use client::Client;

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

Expand Down

0 comments on commit f414ad9

Please sign in to comment.