@@ -17,11 +17,11 @@ use crate::{KeychainKind, Update, Wallet};
1717/// The funded wallet contains a tx with a 76_000 sats input and two outputs, one spending 25_000
1818/// to a foreign address and one returning 50_000 back to the wallet. The remaining 1000
1919/// sats are the transaction fee.
20- pub fn get_funded_wallet ( descriptor : & str , change_descriptor : & str ) -> ( Wallet , bitcoin :: Txid ) {
20+ pub fn get_funded_wallet ( descriptor : & str , change_descriptor : & str ) -> ( Wallet , Txid ) {
2121 new_funded_wallet ( descriptor, Some ( change_descriptor) )
2222}
2323
24- fn new_funded_wallet ( descriptor : & str , change_descriptor : Option < & str > ) -> ( Wallet , bitcoin :: Txid ) {
24+ fn new_funded_wallet ( descriptor : & str , change_descriptor : Option < & str > ) -> ( Wallet , Txid ) {
2525 let params = if let Some ( change_desc) = change_descriptor {
2626 Wallet :: create ( descriptor. to_string ( ) , change_desc. to_string ( ) )
2727 } else {
@@ -40,34 +40,20 @@ fn new_funded_wallet(descriptor: &str, change_descriptor: Option<&str>) -> (Wall
4040 . unwrap ( ) ;
4141
4242 let tx0 = Transaction {
43- version : transaction:: Version :: ONE ,
44- lock_time : bitcoin:: absolute:: LockTime :: ZERO ,
45- input : vec ! [ TxIn {
46- previous_output: OutPoint {
47- txid: Txid :: all_zeros( ) ,
48- vout: 0 ,
49- } ,
50- script_sig: Default :: default ( ) ,
51- sequence: Default :: default ( ) ,
52- witness: Default :: default ( ) ,
53- } ] ,
5443 output : vec ! [ TxOut {
5544 value: Amount :: from_sat( 76_000 ) ,
5645 script_pubkey: receive_address. script_pubkey( ) ,
5746 } ] ,
47+ ..new_tx ( 0 )
5848 } ;
5949
6050 let tx1 = Transaction {
61- version : transaction:: Version :: ONE ,
62- lock_time : bitcoin:: absolute:: LockTime :: ZERO ,
6351 input : vec ! [ TxIn {
6452 previous_output: OutPoint {
6553 txid: tx0. compute_txid( ) ,
6654 vout: 0 ,
6755 } ,
68- script_sig: Default :: default ( ) ,
69- sequence: Default :: default ( ) ,
70- witness: Default :: default ( ) ,
56+ ..Default :: default ( )
7157 } ] ,
7258 output : vec ! [
7359 TxOut {
@@ -79,28 +65,32 @@ fn new_funded_wallet(descriptor: &str, change_descriptor: Option<&str>) -> (Wall
7965 script_pubkey: sendto_address. script_pubkey( ) ,
8066 } ,
8167 ] ,
68+ ..new_tx ( 0 )
8269 } ;
8370
84- wallet
85- . insert_checkpoint ( BlockId {
71+ insert_checkpoint (
72+ & mut wallet,
73+ BlockId {
8674 height : 42 ,
8775 hash : BlockHash :: all_zeros ( ) ,
88- } )
89- . unwrap ( ) ;
90- wallet
91- . insert_checkpoint ( BlockId {
76+ } ,
77+ ) ;
78+ insert_checkpoint (
79+ & mut wallet,
80+ BlockId {
9281 height : 1_000 ,
9382 hash : BlockHash :: all_zeros ( ) ,
94- } )
95- . unwrap ( ) ;
96- wallet
97- . insert_checkpoint ( BlockId {
83+ } ,
84+ ) ;
85+ insert_checkpoint (
86+ & mut wallet,
87+ BlockId {
9888 height : 2_000 ,
9989 hash : BlockHash :: all_zeros ( ) ,
100- } )
101- . unwrap ( ) ;
90+ } ,
91+ ) ;
10292
103- wallet . insert_tx ( tx0. clone ( ) ) ;
93+ insert_tx ( & mut wallet , tx0. clone ( ) ) ;
10494 insert_anchor (
10595 & mut wallet,
10696 tx0. compute_txid ( ) ,
@@ -113,7 +103,7 @@ fn new_funded_wallet(descriptor: &str, change_descriptor: Option<&str>) -> (Wall
113103 } ,
114104 ) ;
115105
116- wallet . insert_tx ( tx1. clone ( ) ) ;
106+ insert_tx ( & mut wallet , tx1. clone ( ) ) ;
117107 insert_anchor (
118108 & mut wallet,
119109 tx1. compute_txid ( ) ,
@@ -134,12 +124,12 @@ fn new_funded_wallet(descriptor: &str, change_descriptor: Option<&str>) -> (Wall
134124/// The funded wallet contains a tx with a 76_000 sats input and two outputs, one spending 25_000
135125/// to a foreign address and one returning 50_000 back to the wallet. The remaining 1000
136126/// sats are the transaction fee.
137- pub fn get_funded_wallet_single ( descriptor : & str ) -> ( Wallet , bitcoin :: Txid ) {
127+ pub fn get_funded_wallet_single ( descriptor : & str ) -> ( Wallet , Txid ) {
138128 new_funded_wallet ( descriptor, None )
139129}
140130
141131/// Get funded segwit wallet
142- pub fn get_funded_wallet_wpkh ( ) -> ( Wallet , bitcoin :: Txid ) {
132+ pub fn get_funded_wallet_wpkh ( ) -> ( Wallet , Txid ) {
143133 let ( desc, change_desc) = get_test_wpkh_and_change_desc ( ) ;
144134 get_funded_wallet ( desc, change_desc)
145135}
@@ -211,6 +201,16 @@ pub fn get_test_tr_dup_keys() -> &'static str {
211201 "tr(cNJmN3fH9DDbDt131fQNkVakkpzawJBSeybCUNmP1BovpmGQ45xG,{pk(8aee2b8120a5f157f1223f72b5e62b825831a27a9fdf427db7cc697494d4a642),pk(8aee2b8120a5f157f1223f72b5e62b825831a27a9fdf427db7cc697494d4a642)})"
212202}
213203
204+ /// A new empty transaction with the given locktime
205+ pub fn new_tx ( locktime : u32 ) -> Transaction {
206+ Transaction {
207+ version : transaction:: Version :: ONE ,
208+ lock_time : absolute:: LockTime :: from_consensus ( locktime) ,
209+ input : vec ! [ ] ,
210+ output : vec ! [ ] ,
211+ }
212+ }
213+
214214/// Construct a new [`FeeRate`] from the given raw `sat_vb` feerate. This is
215215/// useful in cases where we want to create a feerate from a `f64`, as the
216216/// traditional [`FeeRate::from_sat_per_vb`] method will only accept an integer.
@@ -267,7 +267,7 @@ pub fn receive_output_to_address(
267267 } ;
268268
269269 let txid = tx. compute_txid ( ) ;
270- wallet . insert_tx ( tx) ;
270+ insert_tx ( wallet , tx) ;
271271
272272 match pos {
273273 ChainPosition :: Confirmed ( anchor) => {
0 commit comments