From: Alekos Filini Date: Mon, 26 Sep 2022 12:13:40 +0000 (+0200) Subject: Merge bitcoindevkit/bdk#730: Update compiler example to a Policy example X-Git-Tag: v0.23.0-rc.1~7 X-Git-Url: http://internal-gitweb-vhost/script/%22https:/struct.CannotConnectError.html?a=commitdiff_plain;h=aff41d6e1c4eecff44dbe45a361fb6542e80cc59;p=bdk Merge bitcoindevkit/bdk#730: Update compiler example to a Policy example 97b6fb06aa6d95d1c8cf1498cc4478d0f27423e4 Add a policy example (rajarshimaitra) da7670801b81e3e67ff776444afc6e6b48fc10bb Update compiler example. (rajarshimaitra) Pull request description: ### Description Fixes #729. There is an "unmaintained" warning in a old version of clap, which triggered the issue. Ideally, we should not have clap in bdk's dependency. It was only used for the `compiler.rs` example, which was a very tiny clap app compiling miniscript policies, and it wasn't really an example for bdk. This PR rewrites the example as a `policy.rs` which demos the BDK's Policy module and policy structures. - Use a `wsh(multi(2, Privkey, Pubkey))` descriptor, which has only one part private and other part public. - use `into_wallet_descriptor()` to turn that into a `Descriptor` and `KeyMap`. - Use the `KeyMap` to create a custom signer. - Extract the descriptor `Policy` structure from the given keymap. I am not very sure on how much this example is helpful. I still find it hard to read the Policy structure visually. But if Policy is something we want the user to know about descriptors and bdk wallets, this shows how to extract it for a simple multisig condition. Note: There is no use of `bdk::wallet` in the example. BDK uses the Policy extraction internally while transaction creation. But all these are exposed publicly, so can be used independently too. ### Questions: - Should we still have a `minscript::policy::compile()` example? Which IIUC is very different from `bdk::policy:Policy`. I didn't include it in this PR, because I am not sure if it fits inside bdk example categories. - Should we expose `extract_policy` as an wallet API? All though its possible to get policy without creating a wallet, why not let the wallet also spit one out for itself, if its useful? ### Checklists #### All Submissions: * [x] I've signed all my commits * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md) * [x] I ran `cargo fmt` and `cargo clippy` before committing ACKs for top commit: afilini: ACK 97b6fb06aa6d95d1c8cf1498cc4478d0f27423e4 Tree-SHA512: 8e3719fdad308a347d22377050b2f29e02a884ff7d4e57a05a06d078de0709b5bf70bbcb1a696d1e1cdfe02cdb470e5af643da7c775b67fe318046bd6b80f440 --- aff41d6e1c4eecff44dbe45a361fb6542e80cc59