Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MIN-270: stratum v1 rust no std no alloc client #46

Merged
Merged
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
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