diff --git a/stratum-v1/examples/tokio-cli.rs b/stratum-v1/examples/tokio-cli.rs index 8e99355..915e101 100644 --- a/stratum-v1/examples/tokio-cli.rs +++ b/stratum-v1/examples/tokio-cli.rs @@ -47,14 +47,14 @@ async fn main() -> Result<(), Box> { tokio::spawn(async move { loop { let mut c = client_rx.lock().await; - match c.receive_message().await { + match c.poll_message().await { Ok(msg) => match msg { - Message::Configured => { + Some(Message::Configured) => { c.send_connect(Some(String::<32>::from_str("demo").unwrap())) .await .unwrap(); } - Message::Connected => { + Some(Message::Connected) => { c.send_authorize( match pool { "Public-Pool" => String::<64>::from_str( @@ -69,27 +69,25 @@ async fn main() -> Result<(), Box> { .await .unwrap(); } - Message::Authorized => { + Some(Message::Authorized) => { authorized_tx.send(true).unwrap(); } - Message::Share { + Some(Message::Share { accepted: _, rejected: _, - } => { + }) => { // TODO update the display if any } - Message::VersionMask(_mask) => { + Some(Message::VersionMask(_mask)) => { // TODO use mask for hardware version rolling is available } - Message::Difficulty(_diff) => { + Some(Message::Difficulty(_diff)) => { // TODO use diff to filter ASIC reported hits } - Message::CleanJobs => { + Some(Message::CleanJobs) => { // TODO clean the job queue and immediately start hashing a new job } - Message::Other => { - debug!("Received Other Message"); - } + None => {} }, Err(e) => { error!("Client receive_message error: {:?}", e); diff --git a/stratum-v1/src/client/mod.rs b/stratum-v1/src/client/mod.rs index 1a65460..7f33f9e 100644 --- a/stratum-v1/src/client/mod.rs +++ b/stratum-v1/src/client/mod.rs @@ -46,7 +46,6 @@ pub enum Message { VersionMask(u32), Difficulty(f64), CleanJobs, - Other, } impl @@ -89,8 +88,8 @@ impl Result { - let mut msg = Message::Other; + pub async fn poll_message(&mut self) -> Result> { + let mut msg = None; let mut start = 0; while let Some(stop) = self.rx_buf[start..self.rx_free_pos] .iter() @@ -111,7 +110,7 @@ impl { let conn = response::parse_connect(line)?; @@ -121,14 +120,14 @@ impl { if response::parse_authorize(line)? { self.authorized = true; self.reqs.remove(&id); info!("Stratum v1 Client Authorized"); - msg = Message::Authorized; + msg = Some(Message::Authorized); } } Some(ReqKind::Submit) => { @@ -154,10 +153,10 @@ impl return Err(e), } self.reqs.remove(&id); - msg = Message::Share { + msg = Some(Message::Share { accepted: self.shares_accepted, rejected: self.shares_rejected, - }; + }); } None => return Err(Error::IdNotFound(id)), } @@ -167,18 +166,18 @@ impl { let mask = notification::parse_set_version_mask(line)?; self.job_creator.set_version_mask(mask); - msg = Message::VersionMask(mask); + msg = Some(Message::VersionMask(mask)); info!("Set Version Mask: 0x{:x}", mask); } Notification::SetDifficulty => { let diff = notification::parse_set_difficulty(line)?; - msg = Message::Difficulty(diff); + msg = Some(Message::Difficulty(diff)); info!("Set Difficulty: {}", diff); } Notification::Notify => { let work = notification::parse_notify(line)?; if work.clean_jobs { - msg = Message::CleanJobs; + msg = Some(Message::CleanJobs); } info!("New Work: {:?}", work); self.job_creator.set_work(work)?;