Skip to content

Commit

Permalink
Create a lib for mining_device_sv1
Browse files Browse the repository at this point in the history
  • Loading branch information
jbesraa committed Nov 20, 2024
1 parent 4c9396b commit 88a0513
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
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 @@ -2,7 +2,7 @@
name = "mining_device_sv1"
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"
Expand Down
10 changes: 4 additions & 6 deletions roles/test-utils/mining-device-sv1/src/client.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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: 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
9 changes: 8 additions & 1 deletion roles/test-utils/mining-device-sv1/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::{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
}

0 comments on commit 88a0513

Please sign in to comment.