Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions stratum-core/stratum-translation/src/sv1_to_sv2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub fn build_sv2_open_extended_mining_channel(
nominal_hash_rate: f32,
max_target: Target,
min_extranonce_size: u16,
) -> Result<OpenExtendedMiningChannel<'static>> {
) -> Result<OpenExtendedMiningChannel> {
Ok(OpenExtendedMiningChannel {
request_id,
user_identity: user_identity
Expand All @@ -48,12 +48,12 @@ pub fn build_sv2_open_extended_mining_channel(
/// * `Ok(SubmitSharesExtended)` if the conversion is successful.
/// * `Err(())` if any required field is missing or conversion fails.
pub fn build_sv2_submit_shares_extended_from_sv1_submit(
submit: &client_to_server::Submit<'_>,
submit: &client_to_server::Submit,
channel_id: u32,
sequence_number: u32,
job_version: u32,
version_rolling_mask: Option<HexU32Be>,
) -> Result<SubmitSharesExtended<'static>> {
) -> Result<SubmitSharesExtended> {
let version = match (submit.version_bits.clone(), version_rolling_mask) {
(Some(version_bits), Some(rolling_mask)) => {
(job_version & !rolling_mask.0) | (version_bits.0 & rolling_mask.0)
Expand Down Expand Up @@ -85,7 +85,7 @@ mod tests {
use super::*;
use v1::{client_to_server::Submit, utils::HexU32Be};

fn submit_template() -> Submit<'static> {
fn submit_template() -> Submit {
Submit {
user_name: "w".to_string(),
job_id: "1".to_string(),
Expand Down
10 changes: 5 additions & 5 deletions stratum-core/stratum-translation/src/sv2_to_sv1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ use v1::{
/// block is found).
///
/// # Returns
/// * `Ok(server_to_client::Notify<'static>)` - The constructed SV1 mining.notify message.
/// * `Ok(server_to_client::Notify)` - The constructed SV1 mining.notify message.
/// * `Err(StratumTranslationError)` - If BIP141 stripping or serialization fails.
///
/// # Errors
/// * `FailedToTryToStripBip141` - When BIP141 data stripping fails
/// * `FailedToSerializeToB064K` - When serializing stripped data to B064K format fails
pub fn build_sv1_notify_from_sv2(
new_prev_hash: SetNewPrevHash<'static>,
new_job: NewExtendedMiningJob<'static>,
new_prev_hash: SetNewPrevHash,
new_job: NewExtendedMiningJob,
clean_jobs: bool,
) -> Result<server_to_client::Notify<'static>> {
) -> Result<server_to_client::Notify> {
let new_job = match try_strip_bip141(
new_job.coinbase_tx_prefix.inner_as_ref(),
new_job.coinbase_tx_suffix.inner_as_ref(),
Expand Down Expand Up @@ -99,7 +99,7 @@ pub fn build_sv1_notify_from_sv2(
/// # Returns
/// * `Ok(json_rpc::Message)` - The constructed SV1 mining.set_difficulty message.
pub fn build_sv1_set_difficulty_from_sv2_set_target(
set_target: SetTarget<'_>,
set_target: SetTarget,
) -> Result<json_rpc::Message> {
build_sv1_set_difficulty_from_sv2_target(Target::from_le_bytes(
set_target
Expand Down
64 changes: 32 additions & 32 deletions sv1/examples/client_and_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ use sv1_api::{
ClientStatus, IsClient, IsServer, Message,
};

fn new_extranonce<'a>() -> Extranonce<'a> {
fn new_extranonce() -> Extranonce {
extranonce_from_hex("08000002")
}

fn extranonce_from_hex<'a>(hex: &str) -> Extranonce<'a> {
fn extranonce_from_hex(hex: &str) -> Extranonce {
let data = utils::decode_hex(hex).unwrap();
Extranonce::try_from(data).expect("Failed to convert hex to U256")
}

fn merklenode_from_hex<'a>(hex: &str) -> MerkleNode<'a> {
fn merklenode_from_hex(hex: &str) -> MerkleNode {
let data = utils::decode_hex(hex).unwrap();
let len = data.len();
if hex.len() >= 64 {
Expand All @@ -46,7 +46,7 @@ fn merklenode_from_hex<'a>(hex: &str) -> MerkleNode<'a> {
}
}

fn prevhash_from_hex<'a>(hex: &str) -> PrevHash<'a> {
fn prevhash_from_hex(hex: &str) -> PrevHash {
let data = utils::decode_hex(hex).unwrap();
let len = data.len();
if hex.len() >= 64 {
Expand All @@ -72,9 +72,9 @@ fn new_version_rolling_min() -> HexU32Be {
HexU32Be(0x00000000)
}

struct Server<'a> {
struct Server {
authorized_names: Vec<String>,
extranonce1: Extranonce<'a>,
extranonce1: Extranonce,
extranonce2_size: usize,
version_rolling_mask: Option<HexU32Be>,
version_rolling_min_bit: Option<HexU32Be>,
Expand All @@ -98,8 +98,8 @@ fn server_pool_listen(listener: TcpListener) {
}
}

impl Server<'_> {
pub fn new(stream: TcpStream) -> Arc<Mutex<Server<'static>>> {
impl Server {
pub fn new(stream: TcpStream) -> Arc<Mutex<Server>> {
let (sender_incoming, receiver_incoming) = mpsc::channel::<String>();
let (sender_outgoing, receiver_outgoing) = mpsc::channel::<String>();

Expand Down Expand Up @@ -184,7 +184,7 @@ impl Server<'_> {
fn handle_message(
&mut self,
_message: json_rpc::Message,
) -> Result<Option<json_rpc::Response>, Error<'static>> {
) -> Result<Option<json_rpc::Response>, Error> {
Ok(None)
}

Expand All @@ -194,7 +194,7 @@ impl Server<'_> {
}
}

impl<'a> IsServer<'a> for Server<'a> {
impl IsServer for Server {
fn handle_configure(
&mut self,
_client_id: Option<usize>,
Expand Down Expand Up @@ -253,13 +253,13 @@ impl<'a> IsServer<'a> for Server<'a> {
fn set_extranonce1(
&mut self,
_client_id: Option<usize>,
extranonce1: Option<Extranonce<'a>>,
) -> Extranonce<'a> {
extranonce1: Option<Extranonce>,
) -> Extranonce {
self.extranonce1 = extranonce1.unwrap_or_else(new_extranonce);
self.extranonce1.clone()
}

fn extranonce1(&self, _client_id: Option<usize>) -> Extranonce<'a> {
fn extranonce1(&self, _client_id: Option<usize>) -> Extranonce {
self.extranonce1.clone()
}

Expand Down Expand Up @@ -289,7 +289,7 @@ impl<'a> IsServer<'a> for Server<'a> {
self.version_rolling_min_bit = mask
}

fn notify(&mut self, _client_id: Option<usize>) -> Result<json_rpc::Message, Error<'a>> {
fn notify(&mut self, _client_id: Option<usize>) -> Result<json_rpc::Message, Error> {
let hex = "ffff";
Ok(server_to_client::Notify {
job_id: "ciao".to_string(),
Expand All @@ -306,22 +306,22 @@ impl<'a> IsServer<'a> for Server<'a> {
}
}

struct Client<'a> {
struct Client {
client_id: u32,
extranonce1: Extranonce<'a>,
extranonce1: Extranonce,
extranonce2_size: usize,
version_rolling_mask: Option<HexU32Be>,
version_rolling_min_bit: Option<HexU32Be>,
status: ClientStatus,
last_notify: Option<server_to_client::Notify<'a>>,
last_notify: Option<server_to_client::Notify>,
sented_authorize_request: Vec<(u64, String)>, // (id, user_name)
authorized: Vec<String>,
receiver_incoming: Receiver<String>,
sender_outgoing: Sender<String>,
}

impl Client<'static> {
pub fn new(client_id: u32, socket: SocketAddr) -> Arc<Mutex<Client<'static>>> {
impl Client {
pub fn new(client_id: u32, socket: SocketAddr) -> Arc<Mutex<Client>> {
loop {
thread::sleep(Duration::from_secs(1));
match TcpStream::connect(socket) {
Expand Down Expand Up @@ -450,36 +450,36 @@ impl Client<'static> {
}
}

impl<'a> IsClient<'a> for Client<'a> {
impl IsClient for Client {
fn handle_set_difficulty(
&mut self,
_server_id: Option<usize>,
_conf: &mut server_to_client::SetDifficulty,
) -> Result<(), Error<'a>> {
) -> Result<(), Error> {
Ok(())
}

fn handle_set_extranonce(
&mut self,
_server_id: Option<usize>,
_conf: &mut server_to_client::SetExtranonce,
) -> Result<(), Error<'a>> {
) -> Result<(), Error> {
Ok(())
}

fn handle_set_version_mask(
&mut self,
_server_id: Option<usize>,
_conf: &mut server_to_client::SetVersionMask,
) -> Result<(), Error<'a>> {
) -> Result<(), Error> {
Ok(())
}

fn handle_notify(
&mut self,
_server_id: Option<usize>,
notify: server_to_client::Notify<'a>,
) -> Result<(), Error<'a>> {
notify: server_to_client::Notify,
) -> Result<(), Error> {
self.last_notify = Some(notify);
Ok(())
}
Expand All @@ -488,23 +488,23 @@ impl<'a> IsClient<'a> for Client<'a> {
&mut self,
_server_id: Option<usize>,
_conf: &mut server_to_client::Configure,
) -> Result<(), Error<'a>> {
) -> Result<(), Error> {
Ok(())
}

fn handle_subscribe(
&mut self,
_server_id: Option<usize>,
_subscribe: &server_to_client::Subscribe<'a>,
) -> Result<(), Error<'a>> {
_subscribe: &server_to_client::Subscribe,
) -> Result<(), Error> {
Ok(())
}

fn set_extranonce1(&mut self, _server_id: Option<usize>, extranonce1: Extranonce<'a>) {
fn set_extranonce1(&mut self, _server_id: Option<usize>, extranonce1: Extranonce) {
self.extranonce1 = extranonce1;
}

fn extranonce1(&self, _server_id: Option<usize>) -> Extranonce<'a> {
fn extranonce1(&self, _server_id: Option<usize>) -> Extranonce {
self.extranonce1.clone()
}

Expand Down Expand Up @@ -592,13 +592,13 @@ impl<'a> IsClient<'a> for Client<'a> {
&mut self,
_server_id: Option<usize>,
message: Message,
) -> Result<Option<json_rpc::Message>, Error<'a>> {
) -> Result<Option<json_rpc::Message>, Error> {
println!("{message:?}");
Ok(None)
}
}

fn initialize_client(client: Arc<Mutex<Client<'static>>>) {
fn initialize_client(client: Arc<Mutex<Client>>) {
loop {
{
let mut client_ = client.lock().unwrap();
Expand Down
18 changes: 9 additions & 9 deletions sv1/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{

#[derive(Debug)]
#[non_exhaustive]
pub enum Error<'a> {
pub enum Error {
BadBytesConvert(binary_sv2::Error),
BTCHashError(bitcoin_hashes::Error),
/// Errors on bad hex decode/encode.
Expand All @@ -22,11 +22,11 @@ pub enum Error<'a> {
/// Errors if the client receives an invalid message that was intended to be sent from the
/// client to the server, NOT from the server to the client.
#[allow(clippy::upper_case_acronyms)]
InvalidReceiver(Box<Method<'a>>),
InvalidReceiver(Box<Method>),
/// Errors if server receives and invalid `mining.submit` from the client.
InvalidSubmission,
/// Errors encountered during conversion between valid `json_rpc` messages and SV1 messages.
Method(Box<MethodError<'a>>),
Method(Box<MethodError>),
/// Errors if action is attempted that requires the client to be authorized, but it is
/// unauthorized. The client username is given in the error message.
UnauthorizedClient(String),
Expand All @@ -37,7 +37,7 @@ pub enum Error<'a> {
UnexpectedMessage(String),
}

impl std::fmt::Display for Error<'_> {
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Error::BadBytesConvert(ref e) => write!(
Expand Down Expand Up @@ -80,25 +80,25 @@ impl std::fmt::Display for Error<'_> {
}
}

impl From<bitcoin_hashes::Error> for Error<'_> {
impl From<bitcoin_hashes::Error> for Error {
fn from(e: bitcoin_hashes::Error) -> Self {
Error::BTCHashError(e)
}
}

impl From<std::convert::Infallible> for Error<'_> {
impl From<std::convert::Infallible> for Error {
fn from(e: std::convert::Infallible) -> Self {
Error::Infallible(e)
}
}

impl<'a> From<MethodError<'a>> for Error<'a> {
fn from(inner: MethodError<'a>) -> Self {
impl From<MethodError> for Error {
fn from(inner: MethodError) -> Self {
Error::Method(Box::new(inner))
}
}

impl From<binary_sv2::Error> for Error<'_> {
impl From<binary_sv2::Error> for Error {
fn from(inner: binary_sv2::Error) -> Self {
Error::BadBytesConvert(inner)
}
Expand Down
Loading
Loading