Skip to content

Commit

Permalink
Merge pull request #46 from Foundation-Devices/MIN-270_Stratum_v1_Rus…
Browse files Browse the repository at this point in the history
…t_no_std_no_alloc_Client

MIN-270: stratum v1 rust no std no alloc client
  • Loading branch information
georgesFoundation authored Nov 20, 2024
2 parents 5a73653 + 11e7e81 commit 9f2b35b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ minicbor = { version = "0.24", features = ["derive"] }
nom = { version = "7", default-features = false }
phf = { version = "0.11", features = ["macros"], default-features = false }
rand_xoshiro = "0.6"
rustversion = "1.0"
secp256k1 = { version = "0.29", default-features = false }
serde = { version = "1.0.156", features = ["derive"], default-features = false }
serde_json = "1"
Expand Down
3 changes: 2 additions & 1 deletion stratum-v1/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ embedded-io-async = { workspace = true }
faster-hex = { version = "0.10", default-features = false }
heapless = { workspace = true, features = ["serde"] }
log = { workspace = true, optional = true }
rustversion = { workspace = true }
serde = { workspace = true }
serde-json-core = { workspace = true, features = ["custom-error-messages"] }

[features]
defmt-03 = [
"dep:defmt",
"embedded-io-async/defmt-03",
# "faster-hex/defmt-03", # will enable it after faster-hex publish PR#54
# "faster-hex/defmt-03", # will enable it after faster-hex publish 0.11
"heapless/defmt-03",
"serde-json-core/defmt",
]
Expand Down
10 changes: 3 additions & 7 deletions stratum-v1/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,16 +189,12 @@ impl<C: Read + ReadReady + Write, const RX_BUF_SIZE: usize, const TX_BUF_SIZE: u
self.rx_buf.copy_within(start..self.rx_free_pos, 0);
self.rx_free_pos -= start;
}
if self
.network_conn
.read_ready()
.map_err(|_| Error::NetworkError)?
{
if self.network_conn.read_ready().map_err(|_| Error::Network)? {
let n = self
.network_conn
.read(self.rx_buf[self.rx_free_pos..].as_mut())
.await
.map_err(|_| Error::NetworkError)?;
.map_err(|_| Error::Network)?;
debug!("read {} bytes @{}", n, self.rx_free_pos);
trace!("{:?}", &self.rx_buf[self.rx_free_pos..self.rx_free_pos + n]);
self.rx_free_pos += n;
Expand All @@ -220,7 +216,7 @@ impl<C: Read + ReadReady + Write, const RX_BUF_SIZE: usize, const TX_BUF_SIZE: u
self.network_conn
.write_all(&self.tx_buf[..req_len + 1])
.await
.map_err(|_| Error::NetworkError)
.map_err(|_| Error::Network)
}

/// # Configure Client
Expand Down
8 changes: 5 additions & 3 deletions stratum-v1/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ pub enum Error {

/// Network error
// #[from]
// NetworkError(embedded_io::ErrorKind),
NetworkError,
// Network(embedded_io::ErrorKind),
Network,

IdNotFound(u64),

Expand All @@ -73,8 +73,10 @@ pub enum Error {
HexError(faster_hex::Error),
}

// impl core::error::Error for Error {}
#[rustversion::since(1.81)]
impl core::error::Error for Error {}

#[rustversion::since(1.81)]
impl core::fmt::Display for Error {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{self:?}")
Expand Down

0 comments on commit 9f2b35b

Please sign in to comment.