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 @@ -1275,6 +1275,36 @@ mod test {
12751275 assert_ne ! ( address_utxos_async. len( ) , 0 ) ;
12761276 assert_eq ! ( address_utxos_blocking, address_utxos_async) ;
12771277 }
1278+
1279+ #[ cfg( all( feature = "blocking" , feature = "async" ) ) ]
1280+ #[ tokio:: test]
1281+ async fn test_get_scripthash_utxos ( ) {
1282+ let ( blocking_client, async_client) = setup_clients ( ) . await ;
1283+
1284+ let address = BITCOIND
1285+ . client
1286+ . new_address_with_type ( AddressType :: Legacy )
1287+ . unwrap ( ) ;
1288+ let script = address. script_pubkey ( ) ;
1289+
1290+ let _txid = BITCOIND
1291+ . client
1292+ . send_to_address ( & address, Amount :: from_sat ( 21000 ) )
1293+ . unwrap ( )
1294+ . txid ( )
1295+ . unwrap ( ) ;
1296+
1297+ let _miner = MINER . lock ( ) . await ;
1298+ generate_blocks_and_wait ( 1 ) ;
1299+
1300+ let scripthash_utxos_blocking = blocking_client. get_scripthash_utxos ( & script) . unwrap ( ) ;
1301+ let scripthash_utxos_async = async_client. get_scripthash_utxos ( & script) . await . unwrap ( ) ;
1302+
1303+ assert_ne ! ( scripthash_utxos_blocking. len( ) , 0 ) ;
1304+ assert_ne ! ( scripthash_utxos_async. len( ) , 0 ) ;
1305+ assert_eq ! ( scripthash_utxos_blocking, scripthash_utxos_async) ;
1306+ }
1307+
12781308 #[ cfg( all( feature = "blocking" , feature = "async" ) ) ]
12791309 #[ tokio:: test]
12801310 async fn test_get_tx_outspends ( ) {
You can’t perform that action at this time.
0 commit comments