bitcoindevkit / bdk-ffi

Please consider this project *experimental*. But we hope to have an official release out soon.
Other
88 stars 39 forks source link

Add miniscript policy compiler function #294

Open notmandatory opened 1 year ago

notmandatory commented 1 year ago

Describe the enhancement

Add function to construct a Descriptor from a miniscript policy string. See the bdk-cli compiler docs for usage and handle_compile_subcommand() for example code.

Use case

Supporting wallets or tools that let a user create a descriptor from a miniscript policy string.

Additional context

This enhancement was inspired by a conversation with @rob1ham who could use this feature with python.

Rob1Ham commented 1 year ago

I have some code that I'm using to do this currently as a basic rust function that @vnprc helped me out with. It takes a policy string as an input like this:


    let policy = Concrete::<String>::from_str(&policy)?;
    let segwit_policy: Miniscript<String, Segwitv0> = policy
        .compile()
        .map_err(|e| Error::Generic(e.to_string()))?;

    let descriptor = Descriptor::new_wsh(segwit_policy).unwrap().to_string();

Its been a few days so I'm fuzzy on the details, were we talking about adding additional functionality around this?

Rob1Ham commented 1 year ago

Ah yes sorry - yes Python bindings that supports this functionality would be great. For now we have a rust binary that we call to execute this code, which provides us with sufficient utility for an MVP. Having python bindings would allow me to have faster iterations in updating code, but I've been tag teaming learning the rust bdk library with @vnrpc to learn how its done in rust.

vnprc commented 1 year ago

Here's the rust script I slapped together for Rob. It's very rough but apparently super useful. https://github.com/vnprc/rob_script

thunderbiscuit commented 1 year ago

Very cool. Wondering if you'd be interested in adding your script to the bitcoindevkit-scripts repo @vnprc?

vnprc commented 1 year ago

Oh cool. It needs some cleanup work but sure!