diff --git a/roles/Cargo.lock b/roles/Cargo.lock index f7d1d1a8b1..4077bdb834 100644 --- a/roles/Cargo.lock +++ b/roles/Cargo.lock @@ -2300,7 +2300,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] -name = "sv1-mining-device" +name = "sv1_api" +version = "1.0.1" +dependencies = [ + "binary_sv2", + "bitcoin_hashes 0.3.2", + "byteorder", + "hex", + "serde", + "serde_json", + "tracing", +] + +[[package]] +name = "sv1_mining_device" version = "0.1.0" dependencies = [ "async-channel 1.9.0", @@ -2314,19 +2327,6 @@ dependencies = [ "sv1_api", ] -[[package]] -name = "sv1_api" -version = "1.0.1" -dependencies = [ - "binary_sv2", - "bitcoin_hashes 0.3.2", - "byteorder", - "hex", - "serde", - "serde_json", - "tracing", -] - [[package]] name = "syn" version = "1.0.109" diff --git a/roles/test-utils/sv1-mining-device/Cargo.toml b/roles/test-utils/sv1-mining-device/Cargo.toml index edfa6fd1b4..70d338aaec 100644 --- a/roles/test-utils/sv1-mining-device/Cargo.toml +++ b/roles/test-utils/sv1-mining-device/Cargo.toml @@ -1,8 +1,8 @@ [package] -name = "sv1-mining-device" +name = "sv1_mining_device" version = "0.1.0" authors = ["The Stratum V2 Developers"] -edition = "2021" +edition = "2018" publish = false documentation = "https://github.com/stratum-mining/stratum" readme = "README.md" @@ -13,6 +13,10 @@ keywords = ["stratum", "mining", "bitcoin", "protocol"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[lib] +name = "sv1_mining_device" +path = "src/lib.rs" + [dependencies] stratum-common = { path = "../../../common" } async-channel = "1.5.1" diff --git a/roles/test-utils/sv1-mining-device/src/client.rs b/roles/test-utils/sv1-mining-device/src/client.rs index 622c497a6d..be2e5062e7 100644 --- a/roles/test-utils/sv1-mining-device/src/client.rs +++ b/roles/test-utils/sv1-mining-device/src/client.rs @@ -1,5 +1,5 @@ use async_std::net::TcpStream; -use std::{convert::TryInto, ops::Div}; +use std::{convert::TryInto, net::SocketAddr, ops::Div}; use async_channel::{bounded, Receiver, Sender}; use async_std::{io::BufReader, prelude::*, task}; @@ -19,12 +19,10 @@ use v1::{ use crate::{job::Job, miner::Miner}; -const ADDR: &str = "127.0.0.1:34255"; - /// Represents the Mining Device client which is connected to a Upstream node (either a SV1 Pool /// server or a SV1 <-> SV2 Translator Proxy server). #[derive(Debug, Clone)] -pub(crate) struct Client { +pub struct Client { client_id: u32, extranonce1: Option>, extranonce2_size: Option, @@ -69,8 +67,8 @@ impl Client { /// the information from `sender_share`, it is formatted as a `v1::client_to_server::Submit` /// and then serialized into a json message that is sent to the Upstream via /// `sender_outgoing`. - pub(crate) async fn connect(client_id: u32) { - let stream = std::sync::Arc::new(TcpStream::connect(ADDR).await.unwrap()); + 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); // `sender_incoming` listens on socket for incoming messages from the Upstream and sends diff --git a/roles/test-utils/sv1-mining-device/src/lib.rs b/roles/test-utils/sv1-mining-device/src/lib.rs new file mode 100644 index 0000000000..4a3dd2a1e3 --- /dev/null +++ b/roles/test-utils/sv1-mining-device/src/lib.rs @@ -0,0 +1,3 @@ +pub mod client; +pub mod job; +pub mod miner; diff --git a/roles/test-utils/sv1-mining-device/src/main.rs b/roles/test-utils/sv1-mining-device/src/main.rs index 97d43664ed..f34df28d54 100644 --- a/roles/test-utils/sv1-mining-device/src/main.rs +++ b/roles/test-utils/sv1-mining-device/src/main.rs @@ -1,9 +1,16 @@ pub(crate) mod client; pub(crate) mod job; pub(crate) mod miner; +use std::{net::SocketAddr, str::FromStr}; + pub(crate) use client::Client; #[async_std::main] async fn main() { - Client::connect(80).await + const ADDR: &str = "127.0.0.1:34255"; + Client::connect( + 80, + SocketAddr::from_str(ADDR).expect("Invalid upstream address"), + ) + .await }