Skip to content

Commit 45e5f9f

Browse files
committed
Add MempoolClient::get_difficulty_adjustment
1 parent 240f45b commit 45e5f9f

2 files changed

Lines changed: 45 additions & 3 deletions

File tree

src/client.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use reqwest::{Client, Response};
44
use url::Url;
55

66
use crate::error::Error;
7-
use crate::response::Prices;
7+
use crate::response::{DifficultyAdjustment, Prices};
88

99
/// Mempool Space client
1010
pub struct MempoolClient {
@@ -31,7 +31,14 @@ impl MempoolClient {
3131
}
3232
}
3333

34-
/// Returns bitcoin latest price denominated in main currencies.
34+
/// Get details about difficulty adjustment.
35+
pub async fn get_difficulty_adjustment(&self) -> Result<DifficultyAdjustment, Error> {
36+
let url: Url = self.url.join("/api/v1/difficulty-adjustment")?;
37+
let response: Response = self.client.get(url).send().await?;
38+
Ok(response.json().await?)
39+
}
40+
41+
/// Get bitcoin latest price denominated in main currencies.
3542
pub async fn get_prices(&self) -> Result<Prices, Error> {
3643
let url: Url = self.url.join("/api/v1/prices")?;
3744
let response: Response = self.client.get(url).send().await?;

src/response.rs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use serde::{Deserialize, Serialize};
44

55
/// Prices
6-
#[derive(Debug, Serialize, Deserialize)]
6+
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
77
pub struct Prices {
88
/// Timestamp
99
pub time: u64,
@@ -29,3 +29,38 @@ pub struct Prices {
2929
#[serde(rename = "JPY")]
3030
pub jpy: u32,
3131
}
32+
33+
/// Bitcoin difficulty adjustment information
34+
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Serialize, Deserialize)]
35+
pub struct DifficultyAdjustment {
36+
/// Progress percentage towards next difficulty adjustment
37+
#[serde(rename = "progressPercent")]
38+
pub progress_percent: f64,
39+
/// Difficulty change percentage
40+
#[serde(rename = "difficultyChange")]
41+
pub difficulty_change: f64,
42+
/// Estimated timestamp for next retarget
43+
#[serde(rename = "estimatedRetargetDate")]
44+
pub estimated_retarget_date: u64,
45+
/// Number of blocks remaining until retarget
46+
#[serde(rename = "remainingBlocks")]
47+
pub remaining_blocks: u32,
48+
/// Estimated time remaining in seconds
49+
#[serde(rename = "remainingTime")]
50+
pub remaining_time: u64,
51+
/// Previous retarget percentage change
52+
#[serde(rename = "previousRetarget")]
53+
pub previous_retarget: f64,
54+
/// Block height of next retarget
55+
#[serde(rename = "nextRetargetHeight")]
56+
pub next_retarget_height: u32,
57+
/// Average time between blocks
58+
#[serde(rename = "timeAvg")]
59+
pub time_avg: u64,
60+
/// Adjusted average time between blocks
61+
#[serde(rename = "adjustedTimeAvg")]
62+
pub adjusted_time_avg: u64,
63+
/// Time offset
64+
#[serde(rename = "timeOffset")]
65+
pub time_offset: i64,
66+
}

0 commit comments

Comments
 (0)