@@ -48,6 +48,9 @@ pub(crate) mod utils;
4848#[ cfg_attr( docsrs, doc( cfg( feature = "verify" ) ) ) ]
4949pub mod verify;
5050
51+ #[ cfg( feature = "hardware-signer" ) ]
52+ pub mod hardwaresigner;
53+
5154pub use utils:: IsDust ;
5255
5356#[ allow( deprecated) ]
@@ -1867,8 +1870,9 @@ where
18671870}
18681871
18691872/// Return a fake wallet that appears to be funded for testing.
1870- pub fn get_funded_wallet (
1873+ pub fn get_funded_wallet_with_coinbase (
18711874 descriptor : & str ,
1875+ coinbase : bool ,
18721876) -> ( Wallet < AnyDatabase > , ( String , Option < String > ) , bitcoin:: Txid ) {
18731877 let descriptors = testutils ! ( @descriptors ( descriptor) ) ;
18741878 let wallet = Wallet :: new (
@@ -1882,7 +1886,7 @@ pub fn get_funded_wallet(
18821886 let funding_address_kix = 0 ;
18831887
18841888 let tx_meta = testutils ! {
1885- @tx ( ( @external descriptors, funding_address_kix) => 50_000 ) ( @confirmations 1 )
1889+ @tx ( ( @external descriptors, funding_address_kix) => 50_000 ) ( @confirmations 100 )
18861890 } ;
18871891
18881892 wallet
@@ -1902,11 +1906,17 @@ pub fn get_funded_wallet(
19021906 . set_last_index ( KeychainKind :: External , funding_address_kix)
19031907 . unwrap ( ) ;
19041908
1905- let txid = crate :: populate_test_db!( wallet. database. borrow_mut( ) , tx_meta, Some ( 100 ) ) ;
1909+ let txid = crate :: populate_test_db!( wallet. database. borrow_mut( ) , tx_meta, Some ( 100 ) , ( @coinbase coinbase ) ) ;
19061910
19071911 ( wallet, descriptors, txid)
19081912}
19091913
1914+ /// Return a fake wallet that appears to be funded for testing.
1915+ pub fn get_funded_wallet (
1916+ descriptor : & str ,
1917+ ) -> ( Wallet < AnyDatabase > , ( String , Option < String > ) , bitcoin:: Txid ) {
1918+ get_funded_wallet_with_coinbase ( descriptor, false )
1919+ }
19101920#[ cfg( test) ]
19111921pub ( crate ) mod test {
19121922 use bitcoin:: { util:: psbt, Network } ;
@@ -5414,4 +5424,40 @@ pub(crate) mod test {
54145424 // ...and checking that everything is fine
54155425 assert_fee_rate ! ( psbt, details. fee. unwrap_or( 0 ) , fee_rate) ;
54165426 }
5427+
5428+ #[ cfg( feature = "test-hardware-signer" ) ]
5429+ #[ test]
5430+ fn test_create_signer ( ) {
5431+ use hwi:: { types, HWIClient } ;
5432+
5433+ use crate :: wallet:: hardwaresigner:: HWISigner ;
5434+
5435+ let devices = HWIClient :: enumerate ( ) . unwrap ( ) ;
5436+ let client = HWIClient :: get_client (
5437+ devices. first ( ) . expect (
5438+ "No devices found. Either plug in a hardware wallet, or start a simulator." ,
5439+ ) ,
5440+ true ,
5441+ types:: HWIChain :: Regtest ,
5442+ )
5443+ . unwrap ( ) ;
5444+ let descriptors = client. get_descriptors ( None ) . unwrap ( ) ;
5445+ let custom_signer =
5446+ HWISigner :: from_device ( devices. first ( ) . unwrap ( ) , types:: HWIChain :: Regtest ) . unwrap ( ) ;
5447+
5448+ let ( mut wallet, _, _) = get_funded_wallet_with_coinbase ( & descriptors. internal [ 0 ] , true ) ;
5449+ wallet. add_signer (
5450+ KeychainKind :: External ,
5451+ SignerOrdering ( 200 ) ,
5452+ Arc :: new ( custom_signer) ,
5453+ ) ;
5454+
5455+ let addr = wallet. get_address ( LastUnused ) . unwrap ( ) ;
5456+ let mut builder = wallet. build_tx ( ) ;
5457+ builder. drain_to ( addr. script_pubkey ( ) ) . drain_wallet ( ) ;
5458+ let ( mut psbt, _) = builder. finish ( ) . unwrap ( ) ;
5459+
5460+ let finalized = wallet. sign ( & mut psbt, Default :: default ( ) ) . unwrap ( ) ;
5461+ assert ! ( finalized) ;
5462+ }
54175463}
0 commit comments