@@ -17,11 +17,11 @@ use crate::{KeychainKind, Update, Wallet};
17
17
/// The funded wallet contains a tx with a 76_000 sats input and two outputs, one spending 25_000
18
18
/// to a foreign address and one returning 50_000 back to the wallet. The remaining 1000
19
19
/// 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 ) {
21
21
new_funded_wallet ( descriptor, Some ( change_descriptor) )
22
22
}
23
23
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 ) {
25
25
let params = if let Some ( change_desc) = change_descriptor {
26
26
Wallet :: create ( descriptor. to_string ( ) , change_desc. to_string ( ) )
27
27
} else {
@@ -40,34 +40,20 @@ fn new_funded_wallet(descriptor: &str, change_descriptor: Option<&str>) -> (Wall
40
40
. unwrap ( ) ;
41
41
42
42
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
- } ] ,
54
43
output : vec ! [ TxOut {
55
44
value: Amount :: from_sat( 76_000 ) ,
56
45
script_pubkey: receive_address. script_pubkey( ) ,
57
46
} ] ,
47
+ ..new_tx ( 0 )
58
48
} ;
59
49
60
50
let tx1 = Transaction {
61
- version : transaction:: Version :: ONE ,
62
- lock_time : bitcoin:: absolute:: LockTime :: ZERO ,
63
51
input : vec ! [ TxIn {
64
52
previous_output: OutPoint {
65
53
txid: tx0. compute_txid( ) ,
66
54
vout: 0 ,
67
55
} ,
68
- script_sig: Default :: default ( ) ,
69
- sequence: Default :: default ( ) ,
70
- witness: Default :: default ( ) ,
56
+ ..Default :: default ( )
71
57
} ] ,
72
58
output : vec ! [
73
59
TxOut {
@@ -79,28 +65,32 @@ fn new_funded_wallet(descriptor: &str, change_descriptor: Option<&str>) -> (Wall
79
65
script_pubkey: sendto_address. script_pubkey( ) ,
80
66
} ,
81
67
] ,
68
+ ..new_tx ( 0 )
82
69
} ;
83
70
84
- wallet
85
- . insert_checkpoint ( BlockId {
71
+ insert_checkpoint (
72
+ & mut wallet,
73
+ BlockId {
86
74
height : 42 ,
87
75
hash : BlockHash :: all_zeros ( ) ,
88
- } )
89
- . unwrap ( ) ;
90
- wallet
91
- . insert_checkpoint ( BlockId {
76
+ } ,
77
+ ) ;
78
+ insert_checkpoint (
79
+ & mut wallet,
80
+ BlockId {
92
81
height : 1_000 ,
93
82
hash : BlockHash :: all_zeros ( ) ,
94
- } )
95
- . unwrap ( ) ;
96
- wallet
97
- . insert_checkpoint ( BlockId {
83
+ } ,
84
+ ) ;
85
+ insert_checkpoint (
86
+ & mut wallet,
87
+ BlockId {
98
88
height : 2_000 ,
99
89
hash : BlockHash :: all_zeros ( ) ,
100
- } )
101
- . unwrap ( ) ;
90
+ } ,
91
+ ) ;
102
92
103
- wallet . insert_tx ( tx0. clone ( ) ) ;
93
+ insert_tx ( & mut wallet , tx0. clone ( ) ) ;
104
94
insert_anchor (
105
95
& mut wallet,
106
96
tx0. compute_txid ( ) ,
@@ -113,7 +103,7 @@ fn new_funded_wallet(descriptor: &str, change_descriptor: Option<&str>) -> (Wall
113
103
} ,
114
104
) ;
115
105
116
- wallet . insert_tx ( tx1. clone ( ) ) ;
106
+ insert_tx ( & mut wallet , tx1. clone ( ) ) ;
117
107
insert_anchor (
118
108
& mut wallet,
119
109
tx1. compute_txid ( ) ,
@@ -134,12 +124,12 @@ fn new_funded_wallet(descriptor: &str, change_descriptor: Option<&str>) -> (Wall
134
124
/// The funded wallet contains a tx with a 76_000 sats input and two outputs, one spending 25_000
135
125
/// to a foreign address and one returning 50_000 back to the wallet. The remaining 1000
136
126
/// 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 ) {
138
128
new_funded_wallet ( descriptor, None )
139
129
}
140
130
141
131
/// Get funded segwit wallet
142
- pub fn get_funded_wallet_wpkh ( ) -> ( Wallet , bitcoin :: Txid ) {
132
+ pub fn get_funded_wallet_wpkh ( ) -> ( Wallet , Txid ) {
143
133
let ( desc, change_desc) = get_test_wpkh_and_change_desc ( ) ;
144
134
get_funded_wallet ( desc, change_desc)
145
135
}
@@ -211,6 +201,16 @@ pub fn get_test_tr_dup_keys() -> &'static str {
211
201
"tr(cNJmN3fH9DDbDt131fQNkVakkpzawJBSeybCUNmP1BovpmGQ45xG,{pk(8aee2b8120a5f157f1223f72b5e62b825831a27a9fdf427db7cc697494d4a642),pk(8aee2b8120a5f157f1223f72b5e62b825831a27a9fdf427db7cc697494d4a642)})"
212
202
}
213
203
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
+
214
214
/// Construct a new [`FeeRate`] from the given raw `sat_vb` feerate. This is
215
215
/// useful in cases where we want to create a feerate from a `f64`, as the
216
216
/// traditional [`FeeRate::from_sat_per_vb`] method will only accept an integer.
@@ -267,7 +267,7 @@ pub fn receive_output_to_address(
267
267
} ;
268
268
269
269
let txid = tx. compute_txid ( ) ;
270
- wallet . insert_tx ( tx) ;
270
+ insert_tx ( wallet , tx) ;
271
271
272
272
match pos {
273
273
ChainPosition :: Confirmed ( anchor) => {
0 commit comments