Skip to content

Commit 9d80f23

Browse files
committed
Allow get_address_txns to get more than the first 25 txns
1 parent 9942f16 commit 9d80f23

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

src/async.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
//! Esplora by way of `reqwest` HTTP client.
1313
1414
use async_std::task;
15-
use bitcoin::Address;
1615
use std::collections::HashMap;
1716
use std::str::FromStr;
1817

1918
use bitcoin::consensus::{deserialize, serialize, Decodable, Encodable};
2019
use bitcoin::hashes::{sha256, Hash};
2120
use bitcoin::hex::{DisplayHex, FromHex};
21+
use bitcoin::Address;
2222
use bitcoin::{
2323
block::Header as BlockHeader, Block, BlockHash, MerkleBlock, Script, Transaction, Txid,
2424
};
@@ -389,8 +389,17 @@ impl AsyncClient {
389389

390390
/// Get transaction history for the specified address/scripthash, sorted with newest first.
391391
/// Returns up to 50 mempool transactions plus the first 25 confirmed transactions.
392-
pub async fn get_address_txns(&self, address: &Address) -> Result<Vec<Tx>, Error> {
393-
let path = format!("/address/{address}/txs");
392+
/// You can request more confirmed transactions using an after_txid parameter.
393+
pub async fn get_address_txns(
394+
&self,
395+
address: &Address,
396+
after_txid: Option<Txid>,
397+
) -> Result<Vec<Tx>, Error> {
398+
let path = match after_txid {
399+
Some(after_txid) => format!("/address/{address}/txs/chain/{after_txid}"),
400+
None => format!("/address/{address}/txs"),
401+
};
402+
394403
self.get_response_json(&path).await
395404
}
396405

src/blocking.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,17 @@ impl BlockingClient {
328328

329329
/// Get transaction history for the specified address/scripthash, sorted with newest first.
330330
/// Returns up to 50 mempool transactions plus the first 25 confirmed transactions.
331-
pub fn get_address_txns(&self, address: &Address) -> Result<Vec<Tx>, Error> {
332-
let path = format!("/address/{address}/txs");
331+
/// You can request more confirmed transactions using an after_txid parameter.
332+
pub fn get_address_txns(
333+
&self,
334+
address: &Address,
335+
after_txid: Option<Txid>,
336+
) -> Result<Vec<Tx>, Error> {
337+
let path = match after_txid {
338+
Some(after_txid) => format!("/address/{address}/txs/chain/{after_txid}"),
339+
None => format!("/address/{address}/txs"),
340+
};
341+
333342
self.get_response_json(&path)
334343
}
335344

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,8 +1061,8 @@ mod test {
10611061
let _miner = MINER.lock().await;
10621062
generate_blocks_and_wait(1);
10631063

1064-
let address_txns_blocking = blocking_client.get_address_txns(&address).unwrap();
1065-
let address_txns_async = async_client.get_address_txns(&address).await.unwrap();
1064+
let address_txns_blocking = blocking_client.get_address_txns(&address, None).unwrap();
1065+
let address_txns_async = async_client.get_address_txns(&address, None).await.unwrap();
10661066

10671067
assert_eq!(address_txns_blocking, address_txns_async);
10681068
assert_eq!(address_txns_async[0].txid, txid);

0 commit comments

Comments
 (0)