bitcoindevkit / bdk-cli

A CLI wallet library and REPL tool to demo and test the BDK library
Other
111 stars 65 forks source link

Add 'compile' sub-command, minor cleanup #21

Closed notmandatory closed 3 years ago

notmandatory commented 3 years ago

Description

Closes issue #20

Add to library CliSubCommand::Compile enum variant and handle_compile_subcommand() function.

Add to bdk-cli tool a new top level command "Compile" to compile a miniscript policy to an output descriptor.

Help output:

$ cargo run --features=repl,electrum,compiler help compile
...
bdk-cli-compile 0.2.1-dev
Miniscript policy compiler

USAGE:
    bdk-cli compile [OPTIONS] <POLICY>

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
    -t, --type <TYPE>    Sets the script type used to embed the compiled policy [default: wsh]  [possible values: sh,
                         wsh, sh-wsh]

ARGS:
    <POLICY>    Sets the spending policy to compile

Example usage:

$ cargo run --features=repl,electrum,compiler compile --type sh-wsh "thresh(3,pk($ALICE_XPUB),pk($BOB_XPUB),pk($CAROL_XPUB),older(2))"
...
{
  "descriptor": "sh(wsh(thresh(3,pk([0da98f81/84'/1'/0']tpubDD3Fqx9RKeKUqwGSJpdQTAD1kN1misu4CW4zDNFKPphGJJ5K841B58aGHDFxSo65zDttffmLTSTLgwPPyqRVkhqE6D8JWZzm85K1sZ4A85N/0/*),s:pk([65aac7d2/84'/1'/0']tpubDDmA13CwXYp2ocpSGiiF1YKZK9BVVe9go898of7mYuBfwhmXX3GeYoGMHewk9J1b1xurQFJEQTvc2nSsEmYHwL4wdnNdgXRqvs57DYXjHbp/0/*),s:pk([0b7402df/84'/1'/0']tpubDCJWHKMgzMaT8i8wHzRq73wTmRJMzAyEaRsRBRrQfBxQC949jgkiBw1GqtCFunWVVxkmxs8ZuWt6GrPYrcZyHEDRTnozaxKMGXaAkBtAzTo/0/*),sdv:older(2))))#xmglnxx7"

Notes to the reviewers

This command requires the compiler feature be enabled. I didn't add an option to parse the policy since this can already be done with the wallet policies sub-command.

I also renamed the cli arg parsing tests.

Checklists

All Submissions:

New Features: