Skip to content

Commit 725510d

Browse files
author
Gyan Ranjan Panda
committed
fix: minimize PR changes, return BuilderResult
1 parent 45506e0 commit 725510d

10 files changed

Lines changed: 246 additions & 98 deletions

File tree

examples/electrum.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ fn main() -> Result<(), anyhow::Error> {
124124
let mut builder = wallet.build_fee_bump(txid).expect("failed to bump tx");
125125
builder.fee_rate(feerate);
126126
let mut bumped_psbt = builder.finish().unwrap();
127-
let finalize_btx = wallet.sign(&mut bumped_psbt, SignOptions::default())?;
127+
let finalize_btx = wallet.sign(&mut bumped_psbt.psbt, SignOptions::default())?;
128128
assert!(finalize_btx);
129129
let new_fee = bumped_psbt.psbt.fee_amount().unwrap();
130130
let bumped_tx = bumped_psbt.psbt.extract_tx()?;

examples/esplora_async.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ async fn main() -> Result<(), anyhow::Error> {
117117
let mut builder = wallet.build_fee_bump(txid).expect("failed to bump tx");
118118
builder.fee_rate(feerate);
119119
let mut bumped_psbt = builder.finish().unwrap();
120-
let finalize_btx = wallet.sign(&mut bumped_psbt, SignOptions::default())?;
120+
let finalize_btx = wallet.sign(&mut bumped_psbt.psbt, SignOptions::default())?;
121121
assert!(finalize_btx);
122122
let new_fee = bumped_psbt.psbt.fee_amount().unwrap();
123123
let bumped_tx = bumped_psbt.psbt.extract_tx()?;

examples/esplora_blocking.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ fn main() -> Result<(), anyhow::Error> {
113113
let mut builder = wallet.build_fee_bump(txid).unwrap();
114114
builder.fee_rate(feerate);
115115
let mut new_psbt = builder.finish().unwrap();
116-
let finalize_tx = wallet.sign(&mut new_psbt, SignOptions::default())?;
116+
let finalize_tx = wallet.sign(&mut new_psbt.psbt, SignOptions::default())?;
117117
assert!(finalize_tx);
118118
let new_fee = new_psbt.psbt.fee_amount().unwrap();
119119
let bumped_tx = new_psbt.psbt.extract_tx()?;

src/wallet/mod.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,10 +1679,7 @@ impl Wallet {
16791679
}
16801680
}
16811681

1682-
Ok(tx_builder::BuilderResult {
1683-
psbt,
1684-
fee_rate,
1685-
})
1682+
Ok(tx_builder::BuilderResult { psbt, fee_rate })
16861683
}
16871684

16881685
/// Bump the fee of a transaction previously created with this wallet.
@@ -1710,8 +1707,8 @@ impl Wallet {
17101707
/// .add_recipient(to_address.script_pubkey(), Amount::from_sat(50_000));
17111708
/// builder.finish()?
17121709
/// };
1713-
/// let _ = wallet.sign(&mut psbt, SignOptions::default())?;
1714-
/// let tx = psbt.clone().extract_tx().expect("tx");
1710+
/// let _ = wallet.sign(&mut psbt.psbt, SignOptions::default())?;
1711+
/// let tx = psbt.psbt.clone().extract_tx().expect("tx");
17151712
/// // broadcast tx but it's taking too long to confirm so we want to bump the fee
17161713
/// let mut psbt = {
17171714
/// let mut builder = wallet.build_fee_bump(tx.compute_txid())?;
@@ -1720,8 +1717,8 @@ impl Wallet {
17201717
/// builder.finish()?
17211718
/// };
17221719
///
1723-
/// let _ = wallet.sign(&mut psbt, SignOptions::default())?;
1724-
/// let fee_bumped_tx = psbt.extract_tx();
1720+
/// let _ = wallet.sign(&mut psbt.psbt, SignOptions::default())?;
1721+
/// let fee_bumped_tx = psbt.psbt.extract_tx();
17251722
/// // broadcast fee_bumped_tx to replace original
17261723
/// # Ok::<(), anyhow::Error>(())
17271724
/// ```
@@ -1886,7 +1883,7 @@ impl Wallet {
18861883
/// builder.add_recipient(to_address.script_pubkey(), Amount::from_sat(50_000));
18871884
/// builder.finish()?
18881885
/// };
1889-
/// let finalized = wallet.sign(&mut psbt, SignOptions::default())?;
1886+
/// let finalized = wallet.sign(&mut psbt.psbt, SignOptions::default())?;
18901887
/// assert!(finalized, "we should have signed all the inputs");
18911888
/// # Ok::<(),anyhow::Error>(())
18921889
pub fn sign(&self, psbt: &mut Psbt, sign_options: SignOptions) -> Result<bool, SignerError> {

src/wallet/tx_builder.rs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ use crate::{KeychainKind, LocalOutput, Utxo, WeightedUtxo};
9595
/// builder.finish()?
9696
/// };
9797
///
98-
/// assert_eq!(psbt1.unsigned_tx.output[..2], psbt2.unsigned_tx.output[..2]);
98+
/// assert_eq!(psbt1.psbt.unsigned_tx.output[..2], psbt2.psbt.unsigned_tx.output[..2]);
9999
/// # Ok::<(), anyhow::Error>(())
100100
/// ```
101101
///
@@ -773,7 +773,10 @@ impl<Cs: CoinSelectionAlgorithm> TxBuilder<'_, Cs> {
773773
///
774774
/// **WARNING**: To avoid change address reuse you must persist the changes resulting from one
775775
/// or more calls to this method before closing the wallet. See [`Wallet::reveal_next_address`].
776-
pub fn finish_with_aux_rand(self, rng: &mut impl RngCore) -> Result<BuilderResult, CreateTxError> {
776+
pub fn finish_with_aux_rand(
777+
self,
778+
rng: &mut impl RngCore,
779+
) -> Result<BuilderResult, CreateTxError> {
777780
self.wallet.create_tx(self.coin_selection, self.params, rng)
778781
}
779782
}
@@ -1235,7 +1238,12 @@ mod test {
12351238
.drain_wallet()
12361239
.drain_to(recipient.script_pubkey());
12371240
let tx = builder.finish().unwrap();
1238-
let output = tx.unsigned_tx.output.first().expect("must have one output");
1241+
let output = tx
1242+
.psbt
1243+
.unsigned_tx
1244+
.output
1245+
.first()
1246+
.expect("must have one output");
12391247
assert_eq!(output.value, Amount::ONE_BTC * 6);
12401248
}
12411249

@@ -1248,7 +1256,12 @@ mod test {
12481256
.drain_wallet()
12491257
.drain_to(recipient.script_pubkey());
12501258
let tx = builder.finish().unwrap();
1251-
let output = tx.unsigned_tx.output.first().expect("must have one output");
1259+
let output = tx
1260+
.psbt
1261+
.unsigned_tx
1262+
.output
1263+
.first()
1264+
.expect("must have one output");
12521265
assert_eq!(output.value, Amount::ONE_BTC * 3);
12531266
}
12541267

@@ -1261,7 +1274,12 @@ mod test {
12611274
.drain_wallet()
12621275
.drain_to(recipient.script_pubkey());
12631276
let tx = builder.finish().unwrap();
1264-
let output = tx.unsigned_tx.output.first().expect("must have one output");
1277+
let output = tx
1278+
.psbt
1279+
.unsigned_tx
1280+
.output
1281+
.first()
1282+
.expect("must have one output");
12651283
assert_eq!(output.value, Amount::ONE_BTC);
12661284
}
12671285
}
@@ -1297,7 +1315,7 @@ mod test {
12971315
builder.fee_absolute(Amount::from_sat(1_000));
12981316
let psbt = builder.finish().unwrap();
12991317

1300-
let tx = psbt.extract_tx().unwrap();
1318+
let tx = psbt.psbt.extract_tx().unwrap();
13011319
let txid = tx.compute_txid();
13021320
let feerate = wallet.calculate_fee_rate(&tx).unwrap().to_sat_per_kwu();
13031321
insert_tx(&mut wallet, tx);

tests/add_foreign_utxo.rs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,13 @@ fn test_add_foreign_utxo() {
3838
let mut psbt = builder.finish().unwrap();
3939
wallet1.insert_txout(utxo.outpoint, utxo.txout);
4040
let fee = check_fee!(wallet1, psbt);
41-
let (sent, received) =
42-
wallet1.sent_and_received(&psbt.clone().psbt.extract_tx().expect("failed to extract tx"));
41+
let (sent, received) = wallet1.sent_and_received(
42+
&psbt
43+
.psbt
44+
.clone()
45+
.extract_tx()
46+
.expect("failed to extract tx"),
47+
);
4348

4449
assert_eq!(
4550
(sent - received),
@@ -48,7 +53,8 @@ fn test_add_foreign_utxo() {
4853
);
4954

5055
assert!(
51-
psbt.psbt.unsigned_tx
56+
psbt.psbt
57+
.unsigned_tx
5258
.input
5359
.iter()
5460
.any(|input| input.previous_output == utxo.outpoint),
@@ -57,7 +63,7 @@ fn test_add_foreign_utxo() {
5763

5864
let finished = wallet1
5965
.sign(
60-
&mut psbt,
66+
&mut psbt.psbt,
6167
SignOptions {
6268
trust_witness_utxo: true,
6369
..Default::default()
@@ -72,7 +78,7 @@ fn test_add_foreign_utxo() {
7278

7379
let finished = wallet2
7480
.sign(
75-
&mut psbt,
81+
&mut psbt.psbt,
7682
SignOptions {
7783
trust_witness_utxo: true,
7884
..Default::default()
@@ -271,8 +277,13 @@ fn test_taproot_foreign_utxo() {
271277
.add_foreign_utxo(utxo.outpoint, psbt_input, foreign_utxo_satisfaction)
272278
.unwrap();
273279
let psbt = builder.finish().unwrap();
274-
let (sent, received) =
275-
wallet1.sent_and_received(&psbt.clone().psbt.extract_tx().expect("failed to extract tx"));
280+
let (sent, received) = wallet1.sent_and_received(
281+
&psbt
282+
.psbt
283+
.clone()
284+
.extract_tx()
285+
.expect("failed to extract tx"),
286+
);
276287
wallet1.insert_txout(utxo.outpoint, utxo.txout);
277288
let fee = check_fee!(wallet1, psbt);
278289

@@ -283,7 +294,8 @@ fn test_taproot_foreign_utxo() {
283294
);
284295

285296
assert!(
286-
psbt.psbt.unsigned_tx
297+
psbt.psbt
298+
.unsigned_tx
287299
.input
288300
.iter()
289301
.any(|input| input.previous_output == utxo.outpoint),

0 commit comments

Comments
 (0)