You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Merge #730: Update compiler example to a Policy example
97b6fb0 Add a policy example (rajarshimaitra)
da76708 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 97b6fb0
Tree-SHA512: 8e3719fdad308a347d22377050b2f29e02a884ff7d4e57a05a06d078de0709b5bf70bbcb1a696d1e1cdfe02cdb470e5af643da7c775b67fe318046bd6b80f440
let policy_str = matches.value_of("POLICY").unwrap();
71
-
info!("Compiling policy: {}", policy_str);
44
+
// We start with a generic miniscript policy string
45
+
let policy_str = "or(10@thresh(4,pk(029ffbe722b147f3035c87cb1c60b9a5947dd49c774cc31e94773478711a929ac0),pk(025f05815e3a1a8a83bfbb03ce016c9a2ee31066b98f567f6227df1d76ec4bd143),pk(025625f41e4a065efc06d5019cbbd56fe8c07595af1231e7cbc03fafb87ebb71ec),pk(02a27c8b850a00f67da3499b60562673dcf5fdfb82b7e17652a7ac54416812aefd),pk(03e618ec5f384d6e19ca9ebdb8e2119e5bef978285076828ce054e55c4daf473e2)),1@and(older(4209713),thresh(2,pk(03deae92101c790b12653231439f27b8897264125ecb2f46f48278603102573165),pk(033841045a531e1adf9910a6ec279589a90b3b8a904ee64ffd692bd08a8996c1aa),pk(02aebf2d10b040eb936a6f02f44ee82f8b34f5c1ccb20ff3949c2b28206b7c1068))))";
46
+
info!("Compiling policy: \n{}", policy_str);
72
47
48
+
// Parse the string as a [`Concrete`] type miniscript policy.
73
49
let policy = Concrete::<String>::from_str(policy_str)?;
74
50
75
-
let descriptor = match matches.value_of("TYPE").unwrap(){
// The form is "wsh(multi(2, <privkey>, <pubkey>))"
40
+
let desc = "wsh(multi(2,tprv8ZgxMBicQKsPdpkqS7Eair4YxjcuuvDPNYmKX3sCniCf16tHEVrjjiSXEkFRnUH77yXc6ZcwHHcLNfjdi5qUvw3VDfgYiH5mNsj5izuiu2N/1/*,tpubD6NzVbkrYhZ4XHndKkuB8FifXm8r5FQHwrN6oZuWCz13qb93rtgKvD4PQsqC4HP4yhV3tA2fqr2RbY5mNXfM7RxXUoeABoDtsFUq2zJq6YK/1/*))";
41
+
42
+
// Use the descriptor string to derive the full descriptor and a keymap.
43
+
// The wallet descriptor can be used to create a new bdk::wallet.
44
+
// While the `keymap` can be used to create a `SignerContainer`.
45
+
//
46
+
// The `SignerContainer` can sign for `PSBT`s.
47
+
// a bdk::wallet internally uses these to handle transaction signing.
48
+
// But they can be used as independent tools also.
0 commit comments