Skip to content

Commit 9f7e9b3

Browse files
committed
chore(api): remove BlockSummary in favor of BlockInfo
1 parent e0f7985 commit 9f7e9b3

4 files changed

Lines changed: 14 additions & 29 deletions

File tree

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.
@@ -564,12 +564,12 @@ impl<S: Sleeper> AsyncClient<S> {
564564
///
565565
/// The maximum number of summaries returned depends on the backend itself:
566566
/// esplora returns `10` while [mempool.space](https://mempool.space/docs/api) returns `15`.
567-
pub async fn get_blocks(&self, height: Option<u32>) -> Result<Vec<BlockSummary>, Error> {
567+
pub async fn get_blocks(&self, height: Option<u32>) -> Result<Vec<BlockInfo>, Error> {
568568
let path = match height {
569569
Some(height) => format!("/blocks/{height}"),
570570
None => "/blocks".to_string(),
571571
};
572-
let blocks: Vec<BlockSummary> = self.get_response_json(&path).await?;
572+
let blocks: Vec<BlockInfo> = self.get_response_json(&path).await?;
573573
if blocks.is_empty() {
574574
return Err(Error::InvalidResponse);
575575
}

src/blocking.rs

Lines changed: 7 additions & 7 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.
@@ -494,17 +494,17 @@ impl BlockingClient {
494494
self.get_response_json(&path)
495495
}
496496

497-
/// Gets some recent block summaries starting at the tip or at `height` if
498-
/// provided.
497+
/// Get recent block summaries starting at the tip,
498+
/// or at `height` if provided.
499499
///
500500
/// The maximum number of summaries returned depends on the backend itself:
501501
/// esplora returns `10` while [mempool.space](https://mempool.space/docs/api) returns `15`.
502-
pub fn get_blocks(&self, height: Option<u32>) -> Result<Vec<BlockSummary>, Error> {
502+
pub fn get_blocks(&self, height: Option<u32>) -> Result<Vec<BlockInfo>, Error> {
503503
let path = match height {
504504
Some(height) => format!("/blocks/{height}"),
505505
None => "/blocks".to_string(),
506506
};
507-
let blocks: Vec<BlockSummary> = self.get_response_json(&path)?;
507+
let blocks: Vec<BlockInfo> = self.get_response_json(&path)?;
508508
if blocks.is_empty() {
509509
return Err(Error::InvalidResponse);
510510
}

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,7 @@ mod test {
10131013
let start_height = BITCOIND.client.get_block_count().unwrap().0;
10141014
let blocks1 = blocking_client.get_blocks(None).unwrap();
10151015
let blocks_async1 = async_client.get_blocks(None).await.unwrap();
1016-
assert_eq!(blocks1[0].time.height, start_height as u32);
1016+
assert_eq!(blocks1[0].height, start_height as u32);
10171017
assert_eq!(blocks1, blocks_async1);
10181018
generate_blocks_and_wait(10);
10191019
let blocks2 = blocking_client.get_blocks(None).unwrap();
@@ -1028,7 +1028,7 @@ mod test {
10281028
.await
10291029
.unwrap();
10301030
assert_eq!(blocks3, blocks_async3);
1031-
assert_eq!(blocks3[0].time.height, start_height as u32);
1031+
assert_eq!(blocks3[0].height, start_height as u32);
10321032
assert_eq!(blocks3, blocks1);
10331033
let blocks_genesis = blocking_client.get_blocks(Some(0)).unwrap();
10341034
let blocks_genesis_async = async_client.get_blocks(Some(0)).await.unwrap();

0 commit comments

Comments
 (0)