Skip to content

Commit

Permalink
Create a lib for sv1_mining_device
Browse files Browse the repository at this point in the history
  • Loading branch information
jbesraa committed Nov 14, 2024
1 parent b900d0a commit c528dc2
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 21 deletions.
28 changes: 14 additions & 14 deletions roles/Cargo.lock

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

6 changes: 5 additions & 1 deletion roles/test-utils/sv1-mining-device/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "sv1-mining-device"
name = "sv1_mining_device"
version = "0.1.0"
authors = ["The Stratum V2 Developers"]
edition = "2021"
Expand All @@ -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"
Expand Down
8 changes: 3 additions & 5 deletions roles/test-utils/sv1-mining-device/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Extranonce<'static>>,
extranonce2_size: Option<usize>,
Expand Down Expand Up @@ -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: std::net::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
Expand Down
3 changes: 3 additions & 0 deletions roles/test-utils/sv1-mining-device/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod client;
pub mod job;
pub mod miner;
9 changes: 8 additions & 1 deletion roles/test-utils/sv1-mining-device/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
pub(crate) mod client;
pub(crate) mod job;
pub(crate) mod miner;
use std::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,
std::net::SocketAddr::from_str(ADDR).expect("Invalid upstream address"),
)
.await
}

0 comments on commit c528dc2

Please sign in to comment.