Skip to content

Commit 6249eac

Browse files
committed
wip(refactor(wallet))!: remove signers and APIs
1 parent 0683fb3 commit 6249eac

File tree

2 files changed

+11
-125
lines changed

2 files changed

+11
-125
lines changed

wallet/src/wallet/mod.rs

Lines changed: 0 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,44 +1129,6 @@ impl Wallet {
11291129
)
11301130
}
11311131

1132-
/// Add an external signer
1133-
///
1134-
/// See [the `signer` module](signer) for an example.
1135-
pub fn add_signer(
1136-
&mut self,
1137-
keychain: KeychainKind,
1138-
ordering: SignerOrdering,
1139-
signer: Arc<dyn TransactionSigner>,
1140-
) {
1141-
let signers = match keychain {
1142-
KeychainKind::External => Arc::make_mut(&mut self.signers),
1143-
KeychainKind::Internal => Arc::make_mut(&mut self.change_signers),
1144-
};
1145-
1146-
signers.add_external(signer.id(&self.secp), ordering, signer);
1147-
}
1148-
1149-
/// Set the keymap for a given keychain.
1150-
///
1151-
/// Note this does nothing if the given keychain has no descriptor because we won't
1152-
/// know the context (segwit, taproot, etc) in which to create signatures.
1153-
pub fn set_keymap(&mut self, keychain: KeychainKind, keymap: KeyMap) {
1154-
let wallet_signers = match keychain {
1155-
KeychainKind::External => Arc::make_mut(&mut self.signers),
1156-
KeychainKind::Internal => Arc::make_mut(&mut self.change_signers),
1157-
};
1158-
if let Some(descriptor) = self.indexed_graph.index.get_descriptor(keychain) {
1159-
*wallet_signers = SignersContainer::build(keymap, descriptor, &self.secp)
1160-
}
1161-
}
1162-
1163-
/// Set the keymap for each keychain.
1164-
pub fn set_keymaps(&mut self, keymaps: impl IntoIterator<Item = (KeychainKind, KeyMap)>) {
1165-
for (keychain, keymap) in keymaps {
1166-
self.set_keymap(keychain, keymap);
1167-
}
1168-
}
1169-
11701132
/// Get the signers
11711133
///
11721134
/// ## Example
@@ -1744,82 +1706,6 @@ impl Wallet {
17441706
})
17451707
}
17461708

1747-
/// Sign a transaction with all the wallet's signers, in the order specified by every signer's
1748-
/// [`SignerOrdering`]. This function returns the `Result` type with an encapsulated `bool` that has the value true if the PSBT was finalized, or false otherwise.
1749-
///
1750-
/// The [`SignOptions`] can be used to tweak the behavior of the software signers, and the way
1751-
/// the transaction is finalized at the end. Note that it can't be guaranteed that *every*
1752-
/// signers will follow the options, but the "software signers" (WIF keys and `xprv`) defined
1753-
/// in this library will.
1754-
///
1755-
/// ## Example
1756-
///
1757-
/// ```
1758-
/// # use std::str::FromStr;
1759-
/// # use bitcoin::*;
1760-
/// # use bdk_wallet::*;
1761-
/// # use bdk_wallet::ChangeSet;
1762-
/// # use bdk_wallet::error::CreateTxError;
1763-
/// # let descriptor = "wpkh(tpubD6NzVbkrYhZ4Xferm7Pz4VnjdcDPFyjVu5K4iZXQ4pVN8Cks4pHVowTBXBKRhX64pkRyJZJN5xAKj4UDNnLPb5p2sSKXhewoYx5GbTdUFWq/*)";
1764-
/// # let mut wallet = doctest_wallet!();
1765-
/// # let to_address = Address::from_str("2N4eQYCbKUHCCTUjBJeHcJp9ok6J2GZsTDt").unwrap().assume_checked();
1766-
/// let mut psbt = {
1767-
/// let mut builder = wallet.build_tx();
1768-
/// builder.add_recipient(to_address.script_pubkey(), Amount::from_sat(50_000));
1769-
/// builder.finish()?
1770-
/// };
1771-
/// let finalized = wallet.sign(&mut psbt, SignOptions::default())?;
1772-
/// assert!(finalized, "we should have signed all the inputs");
1773-
/// # Ok::<(),anyhow::Error>(())
1774-
pub fn sign(&self, psbt: &mut Psbt, sign_options: SignOptions) -> Result<bool, SignerError> {
1775-
// This adds all the PSBT metadata for the inputs, which will help us later figure out how
1776-
// to derive our keys
1777-
self.update_psbt_with_descriptor(psbt)
1778-
.map_err(SignerError::MiniscriptPsbt)?;
1779-
1780-
// If we aren't allowed to use `witness_utxo`, ensure that every input (except p2tr and finalized ones)
1781-
// has the `non_witness_utxo`
1782-
if !sign_options.trust_witness_utxo
1783-
&& psbt
1784-
.inputs
1785-
.iter()
1786-
.filter(|i| i.final_script_witness.is_none() && i.final_script_sig.is_none())
1787-
.filter(|i| i.tap_internal_key.is_none() && i.tap_merkle_root.is_none())
1788-
.any(|i| i.non_witness_utxo.is_none())
1789-
{
1790-
return Err(SignerError::MissingNonWitnessUtxo);
1791-
}
1792-
1793-
// If the user hasn't explicitly opted-in, refuse to sign the transaction unless every input
1794-
// is using `SIGHASH_ALL` or `SIGHASH_DEFAULT` for taproot
1795-
if !sign_options.allow_all_sighashes
1796-
&& !psbt.inputs.iter().all(|i| {
1797-
i.sighash_type.is_none()
1798-
|| i.sighash_type == Some(EcdsaSighashType::All.into())
1799-
|| i.sighash_type == Some(TapSighashType::All.into())
1800-
|| i.sighash_type == Some(TapSighashType::Default.into())
1801-
})
1802-
{
1803-
return Err(SignerError::NonStandardSighash);
1804-
}
1805-
1806-
for signer in self
1807-
.signers
1808-
.signers()
1809-
.iter()
1810-
.chain(self.change_signers.signers().iter())
1811-
{
1812-
signer.sign_transaction(psbt, &sign_options, &self.secp)?;
1813-
}
1814-
1815-
// attempt to finalize
1816-
if sign_options.try_finalize {
1817-
self.finalize_psbt(psbt, sign_options)
1818-
} else {
1819-
Ok(false)
1820-
}
1821-
}
1822-
18231709
/// Return the spending policies for the wallet's descriptor
18241710
pub fn policies(&self, keychain: KeychainKind) -> Result<Option<Policy>, DescriptorError> {
18251711
let signers = match keychain {

wallet/tests/psbt.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -209,17 +209,17 @@ fn test_psbt_multiple_internalkey_signers() {
209209
let unsigned_tx = psbt.unsigned_tx.clone();
210210

211211
// Adds a signer for the wrong internal key, bdk should not use this key to sign
212-
wallet.add_signer(
213-
KeychainKind::External,
214-
// A signerordering lower than 100, bdk will use this signer first
215-
SignerOrdering(0),
216-
Arc::new(SignerWrapper::new(
217-
PrivateKey::from_wif("5J5PZqvCe1uThJ3FZeUUFLCh2FuK9pZhtEK4MzhNmugqTmxCdwE").unwrap(),
218-
SignerContext::Tap {
219-
is_internal_key: true,
220-
},
221-
)),
222-
);
212+
// wallet.add_signer(
213+
// KeychainKind::External,
214+
// // A signerordering lower than 100, bdk will use this signer first
215+
// SignerOrdering(0),
216+
// Arc::new(SignerWrapper::new(
217+
// PrivateKey::from_wif("5J5PZqvCe1uThJ3FZeUUFLCh2FuK9pZhtEK4MzhNmugqTmxCdwE").unwrap(),
218+
// SignerContext::Tap {
219+
// is_internal_key: true,
220+
// },
221+
// )),
222+
// );
223223

224224
// FIXME: (@leonardo) how should we approach the update of this test ?
225225
// considering that there's an additional/external signer, should we still test this scenario ?

0 commit comments

Comments
 (0)