@@ -18,6 +18,7 @@ use std::str::FromStr;
18
18
use bitcoin:: consensus:: { deserialize, serialize, Decodable , Encodable } ;
19
19
use bitcoin:: hashes:: { sha256, Hash } ;
20
20
use bitcoin:: hex:: { DisplayHex , FromHex } ;
21
+ use bitcoin:: Address ;
21
22
use bitcoin:: {
22
23
block:: Header as BlockHeader , Block , BlockHash , MerkleBlock , Script , Transaction , Txid ,
23
24
} ;
@@ -27,6 +28,7 @@ use log::{debug, error, info, trace};
27
28
28
29
use reqwest:: { header, Client , Response } ;
29
30
31
+ use crate :: api:: AddressStats ;
30
32
use crate :: {
31
33
BlockStatus , BlockSummary , Builder , Error , MerkleProof , OutputStatus , Tx , TxStatus ,
32
34
BASE_BACKOFF_MILLIS , RETRYABLE_ERROR_CODES ,
@@ -378,6 +380,30 @@ impl AsyncClient {
378
380
. map ( |block_hash| BlockHash :: from_str ( & block_hash) . map_err ( Error :: HexToArray ) ) ?
379
381
}
380
382
383
+ /// Get information about a specific address, includes confirmed balance and transactions in
384
+ /// the mempool.
385
+ pub async fn get_address_stats ( & self , address : & Address ) -> Result < AddressStats , Error > {
386
+ let path = format ! ( "/address/{address}" ) ;
387
+ self . get_response_json ( & path) . await
388
+ }
389
+
390
+ /// Get transaction history for the specified address/scripthash, sorted with newest first.
391
+ ///
392
+ /// Returns up to 50 mempool transactions plus the first 25 confirmed transactions.
393
+ /// More can be requested by specifying the last txid seen by the previous query.
394
+ pub async fn get_address_txs (
395
+ & self ,
396
+ address : & Address ,
397
+ last_seen : Option < Txid > ,
398
+ ) -> Result < Vec < Tx > , Error > {
399
+ let path = match last_seen {
400
+ Some ( last_seen) => format ! ( "/address/{address}/txs/chain/{last_seen}" ) ,
401
+ None => format ! ( "/address/{address}/txs" ) ,
402
+ } ;
403
+
404
+ self . get_response_json ( & path) . await
405
+ }
406
+
381
407
/// Get confirmed transaction history for the specified address/scripthash,
382
408
/// sorted with newest first. Returns 25 transactions per page.
383
409
/// More can be requested by specifying the last txid seen by the previous
0 commit comments