File tree Expand file tree Collapse file tree 3 files changed +52
-3
lines changed Expand file tree Collapse file tree 3 files changed +52
-3
lines changed Original file line number Diff line number Diff line change @@ -527,8 +527,17 @@ impl<S: Sleeper> AsyncClient<S> {
527527
528528 /// Get all UTXOs locked to an address.
529529 pub async fn get_address_utxos ( & self , address : & Address ) -> Result < Vec < Utxo > , Error > {
530- self . get_response_json ( & format ! ( "/address/{address}/utxo" ) )
531- . await
530+ let path = format ! ( "/address/{address}/utxo" ) ;
531+
532+ self . get_response_json ( & path) . await
533+ }
534+
535+ /// Get all [`TxOut`]s locked to a [`Script`] hash.
536+ pub async fn get_scripthash_utxos ( & self , script : & Script ) -> Result < Vec < Utxo > , Error > {
537+ let script_hash = sha256:: Hash :: hash ( script. as_bytes ( ) ) ;
538+ let path = format ! ( "/scripthash/{script_hash}/utxo" ) ;
539+
540+ self . get_response_json ( & path) . await
532541 }
533542
534543 /// Get the underlying base URL.
Original file line number Diff line number Diff line change @@ -455,7 +455,17 @@ impl BlockingClient {
455455
456456 /// Get all UTXOs locked to an address.
457457 pub fn get_address_utxos ( & self , address : & Address ) -> Result < Vec < Utxo > , Error > {
458- self . get_response_json ( & format ! ( "/address/{address}/utxo" ) )
458+ let path = format ! ( "/address/{address}/utxo" ) ;
459+
460+ self . get_response_json ( & path)
461+ }
462+
463+ /// Get all [`TxOut`]s locked to a [`Script`] hash.
464+ pub fn get_scripthash_utxos ( & self , script : & Script ) -> Result < Vec < Utxo > , Error > {
465+ let script_hash = sha256:: Hash :: hash ( script. as_bytes ( ) ) ;
466+ let path = format ! ( "/scripthash/{script_hash}/utxo" ) ;
467+
468+ self . get_response_json ( & path)
459469 }
460470
461471 /// Sends a GET request to the given `url`, retrying failed attempts
Original file line number Diff line number Diff line change @@ -1278,6 +1278,36 @@ mod test {
12781278 assert_ne ! ( address_utxos_async. len( ) , 0 ) ;
12791279 assert_eq ! ( address_utxos_blocking, address_utxos_async) ;
12801280 }
1281+
1282+ #[ cfg( all( feature = "blocking" , feature = "async" ) ) ]
1283+ #[ tokio:: test]
1284+ async fn test_get_scripthash_utxos ( ) {
1285+ let ( blocking_client, async_client) = setup_clients ( ) . await ;
1286+
1287+ let address = BITCOIND
1288+ . client
1289+ . new_address_with_type ( AddressType :: Legacy )
1290+ . unwrap ( ) ;
1291+ let script = address. script_pubkey ( ) ;
1292+
1293+ let _txid = BITCOIND
1294+ . client
1295+ . send_to_address ( & address, Amount :: from_sat ( 21000 ) )
1296+ . unwrap ( )
1297+ . txid ( )
1298+ . unwrap ( ) ;
1299+
1300+ let _miner = MINER . lock ( ) . await ;
1301+ generate_blocks_and_wait ( 1 ) ;
1302+
1303+ let scripthash_utxos_blocking = blocking_client. get_scripthash_utxos ( & script) . unwrap ( ) ;
1304+ let scripthash_utxos_async = async_client. get_scripthash_utxos ( & script) . await . unwrap ( ) ;
1305+
1306+ assert_ne ! ( scripthash_utxos_blocking. len( ) , 0 ) ;
1307+ assert_ne ! ( scripthash_utxos_async. len( ) , 0 ) ;
1308+ assert_eq ! ( scripthash_utxos_blocking, scripthash_utxos_async) ;
1309+ }
1310+
12811311 #[ cfg( all( feature = "blocking" , feature = "async" ) ) ]
12821312 #[ tokio:: test]
12831313 async fn test_get_tx_outspends ( ) {
You can’t perform that action at this time.
0 commit comments