Skip to content

Commit aa3707b

Browse files
tchardingafilini
authored andcommitted
Use Psbt instead of PSBT
Idiomatic Rust uses lowercase for acronyms for all characters after the first e.g. `std::net::TcpStream`. PSBT (Partially Signed Bitcoin Transaction) should be rendered `Psbt` in Rust code if we want to write idiomatic Rust. Use `Psbt` instead of `PSBT` when aliasing the import of `PartiallySignedTransaction` from `bitcoin` library.
1 parent f6631e3 commit aa3707b

File tree

4 files changed

+26
-26
lines changed

4 files changed

+26
-26
lines changed

src/descriptor/policy.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ use crate::wallet::utils::{self, After, Older, SecpCtx};
6161
use super::checksum::get_checksum;
6262
use super::error::Error;
6363
use super::XKeyUtils;
64-
use bitcoin::util::psbt::PartiallySignedTransaction as PSBT;
64+
use bitcoin::util::psbt::PartiallySignedTransaction as Psbt;
6565
use miniscript::psbt::PsbtInputSatisfier;
6666

6767
/// Raw public key or extended key fingerprint
@@ -760,7 +760,7 @@ fn signature(
760760
policy
761761
}
762762

763-
fn signature_in_psbt(psbt: &PSBT, key: &DescriptorPublicKey, secp: &SecpCtx) -> bool {
763+
fn signature_in_psbt(psbt: &Psbt, key: &DescriptorPublicKey, secp: &SecpCtx) -> bool {
764764
//TODO check signature validity
765765
psbt.inputs.iter().all(|input| match key {
766766
DescriptorPublicKey::SinglePub(key) => input.partial_sigs.contains_key(&key.key),
@@ -923,7 +923,7 @@ impl<Ctx: ScriptContext> ExtractPolicy for Miniscript<DescriptorPublicKey, Ctx>
923923
}
924924
}
925925

926-
fn psbt_inputs_sat(psbt: &PSBT) -> impl Iterator<Item = PsbtInputSatisfier> {
926+
fn psbt_inputs_sat(psbt: &Psbt) -> impl Iterator<Item = PsbtInputSatisfier> {
927927
(0..psbt.inputs.len()).map(move |i| PsbtInputSatisfier::new(psbt, i))
928928
}
929929

@@ -933,11 +933,11 @@ pub enum BuildSatisfaction<'a> {
933933
/// Don't generate `satisfaction` field
934934
None,
935935
/// Analyze the given PSBT to check for existing signatures
936-
Psbt(&'a PSBT),
936+
Psbt(&'a Psbt),
937937
/// Like `Psbt` variant and also check for expired timelocks
938938
PsbtTimelocks {
939939
/// Given PSBT
940-
psbt: &'a PSBT,
940+
psbt: &'a Psbt,
941941
/// Current blockchain height
942942
current_height: u32,
943943
/// The highest confirmation height between the inputs
@@ -946,7 +946,7 @@ pub enum BuildSatisfaction<'a> {
946946
},
947947
}
948948
impl<'a> BuildSatisfaction<'a> {
949-
fn psbt(&self) -> Option<&'a PSBT> {
949+
fn psbt(&self) -> Option<&'a Psbt> {
950950
match self {
951951
BuildSatisfaction::None => None,
952952
BuildSatisfaction::Psbt(psbt) => Some(psbt),
@@ -1475,7 +1475,7 @@ mod test {
14751475

14761476
let signers_container = Arc::new(SignersContainer::from(keymap));
14771477

1478-
let psbt: PSBT = deserialize(&base64::decode(ALICE_SIGNED_PSBT).unwrap()).unwrap();
1478+
let psbt: Psbt = deserialize(&base64::decode(ALICE_SIGNED_PSBT).unwrap()).unwrap();
14791479

14801480
let policy_alice_psbt = wallet_desc
14811481
.extract_policy(&signers_container, BuildSatisfaction::Psbt(&psbt), &secp)
@@ -1490,7 +1490,7 @@ mod test {
14901490
)
14911491
);
14921492

1493-
let psbt: PSBT = deserialize(&base64::decode(BOB_SIGNED_PSBT).unwrap()).unwrap();
1493+
let psbt: Psbt = deserialize(&base64::decode(BOB_SIGNED_PSBT).unwrap()).unwrap();
14941494
let policy_bob_psbt = wallet_desc
14951495
.extract_policy(&signers_container, BuildSatisfaction::Psbt(&psbt), &secp)
14961496
.unwrap()
@@ -1504,7 +1504,7 @@ mod test {
15041504
)
15051505
);
15061506

1507-
let psbt: PSBT = deserialize(&base64::decode(ALICE_BOB_SIGNED_PSBT).unwrap()).unwrap();
1507+
let psbt: Psbt = deserialize(&base64::decode(ALICE_BOB_SIGNED_PSBT).unwrap()).unwrap();
15081508
let policy_alice_bob_psbt = wallet_desc
15091509
.extract_policy(&signers_container, BuildSatisfaction::Psbt(&psbt), &secp)
15101510
.unwrap()
@@ -1545,7 +1545,7 @@ mod test {
15451545
addr.to_string()
15461546
);
15471547

1548-
let psbt: PSBT =
1548+
let psbt: Psbt =
15491549
deserialize(&base64::decode(PSBT_POLICY_CONSIDER_TIMELOCK_EXPIRED).unwrap()).unwrap();
15501550

15511551
let build_sat = BuildSatisfaction::PsbtTimelocks {
@@ -1584,7 +1584,7 @@ mod test {
15841584
);
15851585
//println!("{}", serde_json::to_string(&policy_expired).unwrap());
15861586

1587-
let psbt_signed: PSBT =
1587+
let psbt_signed: Psbt =
15881588
deserialize(&base64::decode(PSBT_POLICY_CONSIDER_TIMELOCK_EXPIRED_SIGNED).unwrap())
15891589
.unwrap();
15901590

src/psbt/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
// You may not use this file except in accordance with one or both of these
1010
// licenses.
1111

12-
use bitcoin::util::psbt::PartiallySignedTransaction as PSBT;
12+
use bitcoin::util::psbt::PartiallySignedTransaction as Psbt;
1313
use bitcoin::TxOut;
1414

1515
pub trait PsbtUtils {
1616
fn get_utxo_for(&self, input_index: usize) -> Option<TxOut>;
1717
}
1818

19-
impl PsbtUtils for PSBT {
19+
impl PsbtUtils for Psbt {
2020
fn get_utxo_for(&self, input_index: usize) -> Option<TxOut> {
2121
let tx = &self.global.unsigned_tx;
2222

@@ -42,7 +42,7 @@ impl PsbtUtils for PSBT {
4242
mod test {
4343
use crate::bitcoin::consensus::deserialize;
4444
use crate::bitcoin::TxIn;
45-
use crate::psbt::PSBT;
45+
use crate::psbt::Psbt;
4646
use crate::wallet::test::{get_funded_wallet, get_test_wpkh};
4747
use crate::wallet::AddressIndex;
4848
use crate::SignOptions;
@@ -53,7 +53,7 @@ mod test {
5353
#[test]
5454
#[should_panic(expected = "InputIndexOutOfRange")]
5555
fn test_psbt_malformed_psbt_input_legacy() {
56-
let psbt_bip: PSBT = deserialize(&base64::decode(PSBT_STR).unwrap()).unwrap();
56+
let psbt_bip: Psbt = deserialize(&base64::decode(PSBT_STR).unwrap()).unwrap();
5757
let (wallet, _, _) = get_funded_wallet(get_test_wpkh());
5858
let send_to = wallet.get_address(AddressIndex::New).unwrap();
5959
let mut builder = wallet.build_tx();
@@ -70,7 +70,7 @@ mod test {
7070
#[test]
7171
#[should_panic(expected = "InputIndexOutOfRange")]
7272
fn test_psbt_malformed_psbt_input_segwit() {
73-
let psbt_bip: PSBT = deserialize(&base64::decode(PSBT_STR).unwrap()).unwrap();
73+
let psbt_bip: Psbt = deserialize(&base64::decode(PSBT_STR).unwrap()).unwrap();
7474
let (wallet, _, _) = get_funded_wallet(get_test_wpkh());
7575
let send_to = wallet.get_address(AddressIndex::New).unwrap();
7676
let mut builder = wallet.build_tx();
@@ -102,7 +102,7 @@ mod test {
102102

103103
#[test]
104104
fn test_psbt_sign_with_finalized() {
105-
let psbt_bip: PSBT = deserialize(&base64::decode(PSBT_STR).unwrap()).unwrap();
105+
let psbt_bip: Psbt = deserialize(&base64::decode(PSBT_STR).unwrap()).unwrap();
106106
let (wallet, _, _) = get_funded_wallet(get_test_wpkh());
107107
let send_to = wallet.get_address(AddressIndex::New).unwrap();
108108
let mut builder = wallet.build_tx();

src/wallet/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use bitcoin::consensus::encode::serialize;
2525
use bitcoin::util::base58;
2626
use bitcoin::util::psbt::raw::Key as PSBTKey;
2727
use bitcoin::util::psbt::Input;
28-
use bitcoin::util::psbt::PartiallySignedTransaction as PSBT;
28+
use bitcoin::util::psbt::PartiallySignedTransaction as Psbt;
2929
use bitcoin::{Address, Network, OutPoint, Script, SigHashType, Transaction, TxOut, Txid};
3030

3131
use miniscript::descriptor::DescriptorTrait;
@@ -371,7 +371,7 @@ where
371371
&self,
372372
coin_selection: Cs,
373373
params: TxParams,
374-
) -> Result<(PSBT, TransactionDetails), Error> {
374+
) -> Result<(Psbt, TransactionDetails), Error> {
375375
let external_policy = self
376376
.descriptor
377377
.extract_policy(&self.signers, BuildSatisfaction::None, &self.secp)?
@@ -857,7 +857,7 @@ where
857857
/// let finalized = wallet.sign(&mut psbt, SignOptions::default())?;
858858
/// assert!(finalized, "we should have signed all the inputs");
859859
/// # Ok::<(), bdk::Error>(())
860-
pub fn sign(&self, psbt: &mut PSBT, sign_options: SignOptions) -> Result<bool, Error> {
860+
pub fn sign(&self, psbt: &mut Psbt, sign_options: SignOptions) -> Result<bool, Error> {
861861
// this helps us doing our job later
862862
self.add_input_hd_keypaths(psbt)?;
863863

@@ -927,7 +927,7 @@ where
927927
/// Try to finalize a PSBT
928928
///
929929
/// The [`SignOptions`] can be used to tweak the behavior of the finalizer.
930-
pub fn finalize_psbt(&self, psbt: &mut PSBT, sign_options: SignOptions) -> Result<bool, Error> {
930+
pub fn finalize_psbt(&self, psbt: &mut Psbt, sign_options: SignOptions) -> Result<bool, Error> {
931931
let tx = &psbt.global.unsigned_tx;
932932
let mut finished = true;
933933

@@ -1228,10 +1228,10 @@ where
12281228
tx: Transaction,
12291229
selected: Vec<Utxo>,
12301230
params: TxParams,
1231-
) -> Result<PSBT, Error> {
1231+
) -> Result<Psbt, Error> {
12321232
use bitcoin::util::psbt::serialize::Serialize;
12331233

1234-
let mut psbt = PSBT::from_unsigned_tx(tx)?;
1234+
let mut psbt = Psbt::from_unsigned_tx(tx)?;
12351235

12361236
if params.add_global_xpubs {
12371237
let mut all_xpubs = self.descriptor.get_extended_keys()?;
@@ -1371,7 +1371,7 @@ where
13711371
Ok(psbt_input)
13721372
}
13731373

1374-
fn add_input_hd_keypaths(&self, psbt: &mut PSBT) -> Result<(), Error> {
1374+
fn add_input_hd_keypaths(&self, psbt: &mut Psbt) -> Result<(), Error> {
13751375
let mut input_utxos = Vec::with_capacity(psbt.inputs.len());
13761376
for n in 0..psbt.inputs.len() {
13771377
input_utxos.push(psbt.get_utxo_for(n).clone());

src/wallet/tx_builder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use std::collections::HashSet;
4141
use std::default::Default;
4242
use std::marker::PhantomData;
4343

44-
use bitcoin::util::psbt::{self, PartiallySignedTransaction as PSBT};
44+
use bitcoin::util::psbt::{self, PartiallySignedTransaction as Psbt};
4545
use bitcoin::{OutPoint, Script, SigHashType, Transaction};
4646

4747
use miniscript::descriptor::DescriptorTrait;
@@ -521,7 +521,7 @@ impl<'a, B, D: BatchDatabase, Cs: CoinSelectionAlgorithm<D>, Ctx: TxBuilderConte
521521
/// Returns the [`BIP174`] "PSBT" and summary details about the transaction.
522522
///
523523
/// [`BIP174`]: https://github.com/bitcoin/bips/blob/master/bip-0174.mediawiki
524-
pub fn finish(self) -> Result<(PSBT, TransactionDetails), Error> {
524+
pub fn finish(self) -> Result<(Psbt, TransactionDetails), Error> {
525525
self.wallet.create_tx(self.coin_selection, self.params)
526526
}
527527

0 commit comments

Comments
 (0)