Skip to content

Commit 0a8f069

Browse files
committed
feat!: get_blocks now returns BlockInfo instead of BlockSummary
1 parent 7138749 commit 0a8f069

File tree

4 files changed

+12
-27
lines changed

4 files changed

+12
-27
lines changed

src/api.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use serde::Deserialize;
1818
use std::collections::HashMap;
1919

2020
pub use bitcoin::consensus::{deserialize, serialize};
21-
use bitcoin::hash_types::TxMerkleNode;
2221
pub use bitcoin::hex::FromHex;
2322
pub use bitcoin::{
2423
absolute, block, transaction, Address, Amount, Block, BlockHash, CompactTarget, FeeRate,
@@ -204,20 +203,6 @@ pub struct BlockTime {
204203
pub height: u32,
205204
}
206205

207-
/// Summary about a [`Block`].
208-
#[derive(Debug, Clone, Deserialize, PartialEq, Eq)]
209-
pub struct BlockSummary {
210-
/// The [`Block`]'s hash.
211-
pub id: BlockHash,
212-
/// The [`Block`]'s timestamp and height.
213-
#[serde(flatten)]
214-
pub time: BlockTime,
215-
/// The [`BlockHash`] of the previous [`Block`] (`None` for the genesis [`Block`]).
216-
pub previousblockhash: Option<BlockHash>,
217-
/// The Merkle root of the [`Block`]'s [`Transaction`]s.
218-
pub merkle_root: TxMerkleNode,
219-
}
220-
221206
/// Statistics about an [`Address`].
222207
#[derive(Debug, Clone, Deserialize, PartialEq, Eq)]
223208
pub struct AddressStats {

src/async.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ use log::{debug, error, info, trace};
2929
use reqwest::{header, Body, Client, Response};
3030

3131
use crate::{
32-
AddressStats, BlockInfo, BlockStatus, BlockSummary, Builder, Error, MempoolRecentTx,
33-
MempoolStats, MerkleProof, OutputStatus, ScriptHashStats, SubmitPackageResult, Tx, TxStatus,
34-
Utxo, BASE_BACKOFF_MILLIS, RETRYABLE_ERROR_CODES,
32+
AddressStats, BlockInfo, BlockStatus, Builder, Error, MempoolRecentTx, MempoolStats,
33+
MerkleProof, OutputStatus, ScriptHashStats, SubmitPackageResult, Tx, TxStatus, Utxo,
34+
BASE_BACKOFF_MILLIS, RETRYABLE_ERROR_CODES,
3535
};
3636

3737
/// An async client for interacting with an Esplora API server.
@@ -563,12 +563,12 @@ impl<S: Sleeper> AsyncClient<S> {
563563
///
564564
/// The maximum number of summaries returned depends on the backend itself:
565565
/// esplora returns `10` while [mempool.space](https://mempool.space/docs/api) returns `15`.
566-
pub async fn get_blocks(&self, height: Option<u32>) -> Result<Vec<BlockSummary>, Error> {
566+
pub async fn get_blocks(&self, height: Option<u32>) -> Result<Vec<BlockInfo>, Error> {
567567
let path = match height {
568568
Some(height) => format!("/blocks/{height}"),
569569
None => "/blocks".to_string(),
570570
};
571-
let blocks: Vec<BlockSummary> = self.get_response_json(&path).await?;
571+
let blocks: Vec<BlockInfo> = self.get_response_json(&path).await?;
572572
if blocks.is_empty() {
573573
return Err(Error::InvalidResponse);
574574
}

src/blocking.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ use bitcoin::hex::{DisplayHex, FromHex};
2929
use bitcoin::{Address, Block, BlockHash, MerkleBlock, Script, Transaction, Txid};
3030

3131
use crate::{
32-
AddressStats, BlockInfo, BlockStatus, BlockSummary, Builder, Error, MempoolRecentTx,
33-
MempoolStats, MerkleProof, OutputStatus, ScriptHashStats, SubmitPackageResult, Tx, TxStatus,
34-
Utxo, BASE_BACKOFF_MILLIS, RETRYABLE_ERROR_CODES,
32+
AddressStats, BlockInfo, BlockStatus, Builder, Error, MempoolRecentTx, MempoolStats,
33+
MerkleProof, OutputStatus, ScriptHashStats, SubmitPackageResult, Tx, TxStatus, Utxo,
34+
BASE_BACKOFF_MILLIS, RETRYABLE_ERROR_CODES,
3535
};
3636

3737
/// A blocking client for interacting with an Esplora API server.
@@ -501,12 +501,12 @@ impl BlockingClient {
501501
///
502502
/// The maximum number of summaries returned depends on the backend itself:
503503
/// esplora returns `10` while [mempool.space](https://mempool.space/docs/api) returns `15`.
504-
pub fn get_blocks(&self, height: Option<u32>) -> Result<Vec<BlockSummary>, Error> {
504+
pub fn get_blocks(&self, height: Option<u32>) -> Result<Vec<BlockInfo>, Error> {
505505
let path = match height {
506506
Some(height) => format!("/blocks/{height}"),
507507
None => "/blocks".to_string(),
508508
};
509-
let blocks: Vec<BlockSummary> = self.get_response_json(&path)?;
509+
let blocks: Vec<BlockInfo> = self.get_response_json(&path)?;
510510
if blocks.is_empty() {
511511
return Err(Error::InvalidResponse);
512512
}

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,7 @@ mod test {
10161016
let start_height = BITCOIND.client.get_block_count().unwrap().0;
10171017
let blocks1 = blocking_client.get_blocks(None).unwrap();
10181018
let blocks_async1 = async_client.get_blocks(None).await.unwrap();
1019-
assert_eq!(blocks1[0].time.height, start_height as u32);
1019+
assert_eq!(blocks1[0].height, start_height as u32);
10201020
assert_eq!(blocks1, blocks_async1);
10211021
generate_blocks_and_wait(10);
10221022
let blocks2 = blocking_client.get_blocks(None).unwrap();
@@ -1031,7 +1031,7 @@ mod test {
10311031
.await
10321032
.unwrap();
10331033
assert_eq!(blocks3, blocks_async3);
1034-
assert_eq!(blocks3[0].time.height, start_height as u32);
1034+
assert_eq!(blocks3[0].height, start_height as u32);
10351035
assert_eq!(blocks3, blocks1);
10361036
let blocks_genesis = blocking_client.get_blocks(Some(0)).unwrap();
10371037
let blocks_genesis_async = async_client.get_blocks(Some(0)).await.unwrap();

0 commit comments

Comments
 (0)