11#![ allow( unused) ]
2+
23use bdk:: { wallet:: AddressIndex , Wallet } ;
34use bdk_chain:: { BlockId , ConfirmationTime } ;
45use bitcoin:: hashes:: Hash ;
5- use bitcoin:: { BlockHash , Network , Transaction , TxOut } ;
6+ use bitcoin:: { Address , BlockHash , Network , OutPoint , Transaction , TxIn , TxOut } ;
7+ use std:: str:: FromStr ;
68
79/// Return a fake wallet that appears to be funded for testing.
810pub fn get_funded_wallet_with_change (
911 descriptor : & str ,
1012 change : Option < & str > ,
1113) -> ( Wallet , bitcoin:: Txid ) {
1214 let mut wallet = Wallet :: new_no_persist ( descriptor, change, Network :: Regtest ) . unwrap ( ) ;
13- let address = wallet. get_address ( AddressIndex :: New ) . address ;
15+ let change_address = wallet. get_address ( AddressIndex :: New ) . address ;
16+ let sendto_address =
17+ Address :: from_str ( "tb1qeua3n9t076zntxj64cz7qywwtwxd0lwvmtcmtd" ) . expect ( "address" ) ;
1418
15- let tx = Transaction {
19+ let tx0 = Transaction {
1620 version : 1 ,
1721 lock_time : bitcoin:: PackedLockTime ( 0 ) ,
1822 input : vec ! [ ] ,
1923 output : vec ! [ TxOut {
20- value: 50_000 ,
21- script_pubkey: address. script_pubkey( ) ,
24+ value: 76_000 ,
25+ script_pubkey: change_address. script_pubkey( ) ,
26+ } ] ,
27+ } ;
28+
29+ let tx1 = Transaction {
30+ version : 1 ,
31+ lock_time : bitcoin:: PackedLockTime ( 0 ) ,
32+ input : vec ! [ TxIn {
33+ previous_output: OutPoint {
34+ txid: tx0. txid( ) ,
35+ vout: 0 ,
36+ } ,
37+ script_sig: Default :: default ( ) ,
38+ sequence: Default :: default ( ) ,
39+ witness: Default :: default ( ) ,
2240 } ] ,
41+ output : vec ! [
42+ TxOut {
43+ value: 50_000 ,
44+ script_pubkey: change_address. script_pubkey( ) ,
45+ } ,
46+ TxOut {
47+ value: 25_000 ,
48+ script_pubkey: sendto_address. script_pubkey( ) ,
49+ } ,
50+ ] ,
2351 } ;
2452
2553 wallet
@@ -28,17 +56,32 @@ pub fn get_funded_wallet_with_change(
2856 hash : BlockHash :: all_zeros ( ) ,
2957 } )
3058 . unwrap ( ) ;
59+ wallet
60+ . insert_checkpoint ( BlockId {
61+ height : 2_000 ,
62+ hash : BlockHash :: all_zeros ( ) ,
63+ } )
64+ . unwrap ( ) ;
3165 wallet
3266 . insert_tx (
33- tx . clone ( ) ,
67+ tx0 ,
3468 ConfirmationTime :: Confirmed {
3569 height : 1_000 ,
3670 time : 100 ,
3771 } ,
3872 )
3973 . unwrap ( ) ;
74+ wallet
75+ . insert_tx (
76+ tx1. clone ( ) ,
77+ ConfirmationTime :: Confirmed {
78+ height : 2_000 ,
79+ time : 200 ,
80+ } ,
81+ )
82+ . unwrap ( ) ;
4083
41- ( wallet, tx . txid ( ) )
84+ ( wallet, tx1 . txid ( ) )
4285}
4386
4487pub fn get_funded_wallet ( descriptor : & str ) -> ( Wallet , bitcoin:: Txid ) {
0 commit comments