Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add wallet option to select which blockchain client to use #37

Closed

Conversation

notmandatory
Copy link
Member

Description

Added the --blockchain_client or -b wallet option so the user can explicitly select which blockchain client to use if multiple are available in the build. This will make adding new blockchain clients (such as #36) easier. Currently electrum is the default.
I also added a default esplora server url so the user doesn't need to specify one if selecting that client, which is how the electrum and compact_filters clients work.

The new wallet options looks like this (when all optional clients are enabled --features esplora,compact_filters):

bdk-cli-wallet 0.2.1-dev
Wallet mode

USAGE:
    bdk-cli wallet [FLAGS] [OPTIONS] --descriptor <DESCRIPTOR> <SUBCOMMAND>

FLAGS:
    -v, --verbose    Adds verbosity, returns PSBT in JSON format alongside serialized
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
    -n, --node <ADDRESS:PORT>...
            Compact filters blockchain client peer full node IP address:port [default: 127.0.0.1:18444]

    -b, --blockchain_client <BLOCKCHAIN_CLIENT>
            Blockchain client protocol [default: electrum]  [possible values: electrum, esplora, compact_filters]

    -c, --change_descriptor <CHANGE_DESCRIPTOR>        Sets the descriptor to use for internal addresses
        --conn_count <CONNECTIONS>
            Compact filters blockchain client number of parallel node connections [default: 4]

    -d, --descriptor <DESCRIPTOR>                      Sets the descriptor to use for the external addresses
        --esplora_concurrency <ESPLORA_CONCURRENCY>    Esplora blockchain client request concurrency [default: 4]
    -e, --esplora <ESPLORA_URL>
            Esplora blockchain client server url [default: https://blockstream.info/api/]

    -p, --proxy <PROXY_ADDRS:PORT>                     Blockchain client SOCKS5 proxy
    -r, --retries <PROXY_RETRIES>                      Blockchain client SOCKS5 proxy retries [default: 5]
    -t, --timeout <PROXY_TIMEOUT>                      Electrum blockchain client SOCKS5 proxy timeout
    -a, --proxy_auth <PROXY_USER:PASSWD>               Blockchain client SOCKS5 proxy credential
    -s, --server <SERVER:PORT>
            Electrum blockchain client server url [default: ssl://electrum.blockstream.info:60002]

    -k, --skip_blocks <SKIP_BLOCKS>
            Compact filters blockchain client skip initial blocks [default: 0]

    -w, --wallet <WALLET_NAME>                         Selects the wallet to use [default: main]

Notes to the reviewers

In the docs for the blockchain_client option it displays the default [electrum] even if that feature is not enabled and all possible blockchain clients are displayed even if only some are enabled. I couldn't find a nice way to fix this, but the cli will throw an error if a blockchain client is selected that wasn't configured as a feature in the build.

I also simplified the CHANGELOG to focus on what a user would see as a change while using the bin.

Checklists

All Submissions:

  • I've signed all my commits
  • I followed the contribution guidelines
  • I ran cargo fmt and cargo clippy before committing

New Features:

  • I've added tests for the new feature
  • I've added docs for the new feature
  • I've updated CHANGELOG.md

Bugfixes:

  • This pull request breaks the existing API
  • I've added tests to reproduce the issue which are now passing
  • I'm linking the issue being fixed by this PR

@notmandatory notmandatory force-pushed the blockchain_client_opt branch from a0e3d61 to 73707ff Compare August 4, 2021 04:34
@notmandatory notmandatory force-pushed the blockchain_client_opt branch from 73707ff to 3c8b51f Compare August 4, 2021 04:54
@rajarshimaitra
Copy link
Contributor

Thanks @notmandatory . This is a possible way to do it, but unfortunately, this also doesn't reduce our option arg namespace. So you will get the same conflicts with -b flag, as without it. Because electrum is on by default ( that turns on ProxyOpts too) even if we don't need it at all.

I think the blockchain selection flag is kinda redundant because we are selecting blockchain backend at the build time itself with --features flag.

I have tried around a few things and it seems to me that the easiest thing to do to solve all of our problems, is if we drop the default blockchain, and just specify a backend each time we build bdk-cli.

We can have the repl feature as default.

Without any blockchain feature bdk-cli will just do the repl things.

To have a full wallet we will specify a backend with --feature flag.

This will allow us to have the same arg option names for different blockchins. Because using feature guard removes the codes from the binary, so clap won't complain because for it those options don't exist.

And I think we can reasonably explain this in the usage docs too.

I have tried this manually, and it produces nice compact --help doc also only with the blockchain that is enabled. like this

--features rpc

OPTIONS:
    -n, --rpc-node <ADDRESS:PORT>
            Sets the full node address for rpc connection [default: 127.0.0.1:18443]

    -c, --change_descriptor <CHANGE_DESCRIPTOR>    
            Sets the descriptor to use for internal addresses

    -d, --descriptor <DESCRIPTOR>                  
            Sets the descriptor to use for the external addresses

    -x, --skip-blocks <SKIP_BLOCKS>                
            Optionally skip initial `skip_blocks` blocks

    -A, --rpc-auth <USER:PASSWD>
            Sets the rpc authentication username:password [default: admin:password]

    -w, --wallet <WALLET_NAME>                     
            Selects the wallet to use [default: main]

--features electrum

OPTIONS:
    -c, --change_descriptor <CHANGE_DESCRIPTOR>    
            Sets the descriptor to use for internal addresses

    -d, --descriptor <DESCRIPTOR>                  
            Sets the descriptor to use for the external addresses

    -p, --proxy <PROXY_ADDRS:PORT>                 
            Sets the SOCKS5 proxy for Blockchain backend

    -r, --retries <PROXY_RETRIES>                  
            Sets the SOCKS5 proxy retries for the Electrum client [default: 5]

    -t, --timeout <PROXY_TIMEOUT>                  
            Sets the SOCKS5 proxy timeout for the Electrum client

    -a, --proxy-auth <PROXY_USER:PASSWD>           
            Sets the SOCKS5 proxy credential

    -s, --server <SERVER:PORT>
            Sets the Electrum server to use [default: ssl://electrum.blockstream.info:60002]

    -w, --wallet <WALLET_NAME>                     
            Selects the wallet to use [default: main]    

If this is something we wanna do, I can add it to my open PR. It's not a big change set.

@notmandatory
Copy link
Member Author

@rajarshimaitra OK if this doesn't solve the conflicting params issue I'll close it and open a new one with your one blockchain client at a time solution. I'll add some docs and a compile error if users try building with two blockchain client features enabled. I'd rather keep this change as a separate PR to keep it simple to review.

@notmandatory notmandatory deleted the blockchain_client_opt branch August 4, 2021 22:57
@rajarshimaitra
Copy link
Contributor

Yes that makes sense. Better to do it via separate PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants