@@ -18,6 +18,7 @@ use std::str::FromStr;
1818use bitcoin:: consensus:: { deserialize, serialize, Decodable , Encodable } ;
1919use bitcoin:: hashes:: { sha256, Hash } ;
2020use bitcoin:: hex:: { DisplayHex , FromHex } ;
21+ use bitcoin:: Address ;
2122use bitcoin:: {
2223 block:: Header as BlockHeader , Block , BlockHash , MerkleBlock , Script , Transaction , Txid ,
2324} ;
@@ -27,6 +28,7 @@ use log::{debug, error, info, trace};
2728
2829use reqwest:: { header, Client , Response } ;
2930
31+ use crate :: api:: AddressStats ;
3032use crate :: {
3133 BlockStatus , BlockSummary , Builder , Error , MerkleProof , OutputStatus , Tx , TxStatus ,
3234 BASE_BACKOFF_MILLIS , RETRYABLE_ERROR_CODES ,
@@ -378,6 +380,30 @@ impl AsyncClient {
378380 . map ( |block_hash| BlockHash :: from_str ( & block_hash) . map_err ( Error :: HexToArray ) ) ?
379381 }
380382
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+
381407 /// Get confirmed transaction history for the specified address/scripthash,
382408 /// sorted with newest first. Returns 25 transactions per page.
383409 /// More can be requested by specifying the last txid seen by the previous
0 commit comments