Skip to content

Commit

Permalink
more defmt
Browse files Browse the repository at this point in the history
  • Loading branch information
georgesFoundation committed Aug 6, 2024
1 parent 7d8ae6f commit fce694b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ rand_xoshiro = "0.6"
secp256k1 = { version = "0.29", default-features = false }
serde = { version = "1.0.156", features = ["derive"], default-features = false }
serde_json = "1"
serde-json-core = { version = "0.5" }
uuid = { version = "1", default-features = false }

# The crates in this workspace.
Expand Down
6 changes: 4 additions & 2 deletions stratum-v1/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ faster-hex = { version = "0.9", default-features = false, git = "https://github.
heapless = { workspace = true, features = ["serde"] }
log = { workspace = true, optional = true }
serde = { workspace = true }
serde-json-core = { workspace = true, features = ["custom-error-messages"] }
serde-json-core = { features = ["custom-error-messages"], git = "https://github.com/rust-embedded-community/serde-json-core.git", branch = "master" }

[features]
default = []
defmt-03 = [
"dep:defmt",
"embedded-io-async/defmt-03",
"heapless/defmt-03"
"faster-hex/defmt-03",
"heapless/defmt-03",
"serde-json-core/defmt"
]

[dev-dependencies]
Expand Down
24 changes: 22 additions & 2 deletions stratum-v1/src/client/job.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// SPDX-FileCopyrightText: © 2024 Foundation Devices, Inc. <[email protected]>
// SPDX-License-Identifier: GPL-3.0-or-later

use crate::{Error, Result, Work};

use bitcoin::{
Expand All @@ -9,14 +12,31 @@ use bitcoin::{
use heapless::{String, Vec};

#[derive(Debug)]
// #[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
pub struct Job {
pub job_id: u64,
pub extranonce2: Vec<u8, 8>,
pub version_bits: i32,
pub header: Header,
}
//TODO: implement defmt::Format manually because Header does not implement it

#[cfg(feature = "defmt-03")]
impl defmt::Format for Job {
fn format(&self, fmt: defmt::Formatter) {
defmt::write!(
fmt,
"Job {{ job_id: {}, extranonce2: {:?}, version_bits: {}, header: {{ version: {:x}, prev_block_hash: {:x}, merkle_root: {:x}, time: {:x}, bits: {:x}, nonce: {:x} }} }}",
self.job_id,
self.extranonce2,
self.version_bits,
self.header.version.to_consensus(),
self.header.prev_blockhash.to_byte_array(),
self.header.merkle_root.to_byte_array(),
self.header.time,
self.header.bits.to_consensus(),
self.header.nonce
);
}
}

#[derive(Debug, Default)]
#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
Expand Down
2 changes: 1 addition & 1 deletion stratum-v1/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use heapless::String;
pub type Result<T> = core::result::Result<T, Error>;

#[derive(Debug, Clone, From, PartialEq)]
// #[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
pub enum Error {
/// Client is already configured against the Pool
AlreadyConfigured,
Expand Down

0 comments on commit fce694b

Please sign in to comment.