Skip to content

Commit 603b1cf

Browse files
committed
refactor!: remove policy module and related code
As policy is anyway being phased out in 3.0
1 parent 16d6f8c commit 603b1cf

File tree

6 files changed

+2073
-1991
lines changed

6 files changed

+2073
-1991
lines changed

examples/policy.rs

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
extern crate bdk_wallet;
1313
use std::error::Error;
1414

15-
use bdk_wallet::bitcoin::Network;
16-
use bdk_wallet::descriptor::{policy::BuildSatisfaction, ExtractPolicy, IntoWalletDescriptor};
17-
use bdk_wallet::signer::SignersContainer;
15+
// use bdk_wallet::bitcoin::Network;
16+
// use bdk_wallet::descriptor::{policy::BuildSatisfaction, ExtractPolicy, IntoWalletDescriptor};
17+
// use bdk_wallet::signer::SignersContainer;
1818

1919
/// This example describes the use of the BDK's [`bdk_wallet::descriptor::policy`] module.
2020
///
@@ -27,34 +27,38 @@ use bdk_wallet::signer::SignersContainer;
2727
/// wallet holds one of the Extend Private key.
2828
#[allow(clippy::print_stdout)]
2929
fn main() -> Result<(), Box<dyn Error>> {
30-
let secp = bitcoin::secp256k1::Secp256k1::new();
31-
32-
// The descriptor used in the example
33-
// The form is "wsh(multi(2, <privkey>, <pubkey>))"
34-
let desc = "wsh(multi(2,tprv8ZgxMBicQKsPdpkqS7Eair4YxjcuuvDPNYmKX3sCniCf16tHEVrjjiSXEkFRnUH77yXc6ZcwHHcLNfjdi5qUvw3VDfgYiH5mNsj5izuiu2N/1/*,tpubD6NzVbkrYhZ4XHndKkuB8FifXm8r5FQHwrN6oZuWCz13qb93rtgKvD4PQsqC4HP4yhV3tA2fqr2RbY5mNXfM7RxXUoeABoDtsFUq2zJq6YK/1/*))";
35-
36-
// Use the descriptor string to derive the full descriptor and a keymap.
37-
// The wallet descriptor can be used to create a new bdk_wallet::wallet.
38-
// While the `keymap` can be used to create a `SignerContainer`.
39-
//
40-
// The `SignerContainer` can sign for `PSBT`s.
41-
// a `bdk_wallet::Wallet` internally uses these to handle transaction signing.
42-
// But they can be used as independent tools also.
43-
let (wallet_desc, keymap) = desc.into_wallet_descriptor(&secp, Network::Testnet)?;
44-
45-
println!("Example Descriptor for policy analysis : {wallet_desc}");
46-
47-
// Create the signer with the keymap and descriptor.
48-
let signers_container = SignersContainer::build(keymap, &wallet_desc, &secp);
49-
50-
// Extract the Policy from the given descriptor and signer.
51-
// Note that Policy is a wallet specific structure. It depends on the the descriptor, and
52-
// what the concerned wallet with a given signer can sign for.
53-
let policy = wallet_desc
54-
.extract_policy(&signers_container, BuildSatisfaction::None, &secp)?
55-
.expect("We expect a policy");
56-
57-
println!("Derived Policy for the descriptor {policy:#?}");
30+
// let secp = bitcoin::secp256k1::Secp256k1::new();
31+
32+
// // The descriptor used in the example
33+
// // The form is "wsh(multi(2, <privkey>, <pubkey>))"
34+
// let desc =
35+
// "wsh(multi(2,
36+
// tprv8ZgxMBicQKsPdpkqS7Eair4YxjcuuvDPNYmKX3sCniCf16tHEVrjjiSXEkFRnUH77yXc6ZcwHHcLNfjdi5qUvw3VDfgYiH5mNsj5izuiu2N/
37+
// 1/*,tpubD6NzVbkrYhZ4XHndKkuB8FifXm8r5FQHwrN6oZuWCz13qb93rtgKvD4PQsqC4HP4yhV3tA2fqr2RbY5mNXfM7RxXUoeABoDtsFUq2zJq6YK/
38+
// 1/*))";
39+
40+
// // Use the descriptor string to derive the full descriptor and a keymap.
41+
// // The wallet descriptor can be used to create a new bdk_wallet::wallet.
42+
// // While the `keymap` can be used to create a `SignerContainer`.
43+
// //
44+
// // The `SignerContainer` can sign for `PSBT`s.
45+
// // a `bdk_wallet::Wallet` internally uses these to handle transaction signing.
46+
// // But they can be used as independent tools also.
47+
// let (wallet_desc, keymap) = desc.into_wallet_descriptor(&secp, Network::Testnet)?;
48+
49+
// println!("Example Descriptor for policy analysis : {wallet_desc}");
50+
51+
// // Create the signer with the keymap and descriptor.
52+
// let signers_container = SignersContainer::build(keymap, &wallet_desc, &secp);
53+
54+
// // Extract the Policy from the given descriptor and signer.
55+
// // Note that Policy is a wallet specific structure. It depends on the the descriptor, and
56+
// // what the concerned wallet with a given signer can sign for.
57+
// let policy = wallet_desc
58+
// .extract_policy(&signers_container, BuildSatisfaction::None, &secp)?
59+
// .expect("We expect a policy");
60+
61+
// println!("Derived Policy for the descriptor {policy:#?}");
5862

5963
Ok(())
6064
}

src/descriptor/error.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ pub enum Error {
2626
MultiPath,
2727
/// Error thrown while working with [`keys`](crate::keys)
2828
Key(crate::keys::KeyError),
29-
/// Error while extracting and manipulating policies
30-
Policy(crate::descriptor::policy::PolicyError),
29+
// /// Error while extracting and manipulating policies
30+
// Policy(crate::descriptor::policy::PolicyError),
3131

3232
/// Invalid byte found in the descriptor checksum
3333
InvalidDescriptorCharacter(u8),
@@ -72,7 +72,7 @@ impl fmt::Display for Error {
7272
"The descriptor contains multipath keys with invalid number of paths (must have exactly 2 paths for receive and change)"
7373
),
7474
Self::Key(err) => write!(f, "Key error: {err}"),
75-
Self::Policy(err) => write!(f, "Policy error: {err}"),
75+
// Self::Policy(err) => write!(f, "Policy error: {err}"),
7676
Self::InvalidDescriptorCharacter(char) => {
7777
write!(f, "Invalid descriptor character: {char}")
7878
}
@@ -120,9 +120,3 @@ impl From<bitcoin::hex::HexToBytesError> for Error {
120120
Error::Hex(err)
121121
}
122122
}
123-
124-
impl From<crate::descriptor::policy::PolicyError> for Error {
125-
fn from(err: crate::descriptor::policy::PolicyError) -> Self {
126-
Error::Policy(err)
127-
}
128-
}

src/descriptor/mod.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,18 @@ pub use miniscript::{
3333
};
3434
use miniscript::{ForEachKey, MiniscriptKey, TranslatePk};
3535

36-
use crate::descriptor::policy::BuildSatisfaction;
36+
// use crate::descriptor::policy::BuildSatisfaction;
3737

3838
pub mod checksum;
3939
#[doc(hidden)]
4040
pub mod dsl;
4141
pub mod error;
42-
pub mod policy;
42+
// pub mod policy;
4343
pub mod template;
4444

4545
pub use self::checksum::calc_checksum;
4646
pub use self::error::Error as DescriptorError;
47-
pub use self::policy::Policy;
47+
// pub use self::policy::Policy;
4848
use self::template::DescriptorTemplateOut;
4949
use crate::keys::{IntoDescriptorKey, KeyError};
5050
use crate::wallet::signer::SignersContainer;
@@ -343,16 +343,16 @@ impl<Ctx: miniscript::ScriptContext, Pk: miniscript::MiniscriptKey> CheckMiniscr
343343
}
344344
}
345345

346-
/// Trait implemented on [`Descriptor`]s to add a method to extract the spending [`policy`]
347-
pub trait ExtractPolicy {
348-
/// Extract the spending [`policy`]
349-
fn extract_policy(
350-
&self,
351-
signers: &SignersContainer,
352-
psbt: BuildSatisfaction,
353-
secp: &SecpCtx,
354-
) -> Result<Option<Policy>, DescriptorError>;
355-
}
346+
// /// Trait implemented on [`Descriptor`]s to add a method to extract the spending [`policy`]
347+
// pub trait ExtractPolicy {
348+
// /// Extract the spending [`policy`]
349+
// fn extract_policy(
350+
// &self,
351+
// signers: &SignersContainer,
352+
// psbt: BuildSatisfaction,
353+
// secp: &SecpCtx,
354+
// ) -> Result<Option<Policy>, DescriptorError>;
355+
// }
356356

357357
pub(crate) trait XKeyUtils {
358358
fn root_fingerprint(&self, secp: &SecpCtx) -> Fingerprint;

0 commit comments

Comments
 (0)