-
Notifications
You must be signed in to change notification settings - Fork 65
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
Re-organize wallet sub-commands and add key
sub-commands
#14
Conversation
…and handle_online_wallet_subcommand, Add KeySubCommand and handle_key_subcommand
key
sub-commands
e92fcaa
to
9a2c4c2
Compare
9a2c4c2
to
adbc3b6
Compare
ACK. I have tested this locally and everything works well! I have not reviewed the code, however. |
I added a small change to |
2b67326
to
e64696d
Compare
e64696d
to
1cec709
Compare
Reviewing it now :) |
src/bdk_cli.rs
Outdated
let repl_subcommand: Result<ReplOpt, clap::Error> = | ||
ReplOpt::from_iter_safe(split_line); | ||
let split_line: Vec<&str> = | ||
split_regex.find_iter(&line).map(|m| m.as_str()).collect(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... then here you can iterate over the captured groups and remove the quotes at the same time:
split_regex.find_iter(&line).map(|m| m.as_str()).collect(); | |
split_regex.captures_iter(&line).map(|c| c.get(1).or(c.get(2)).unwrap().as_str()).collect(); |
The c.get(1).or(c.get(2))
is necessary because sometimes it's the first capture group that matches and sometimes the second, but since there are only two of them you can safely unwrap()
later because either one or the other always matches.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh cool, I'll give it a try!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes this is much better, I also added the capture group you suggested for single quotes, and fixed it so the double quote and single quote capture groups can take non-alphanumeric characters (other than " or ')
src/lib.rs
Outdated
/// #[cfg(feature = "electrum")] | ||
/// proxy: None, | ||
/// #[cfg(feature = "electrum")] | ||
/// retries: 5, | ||
/// #[cfg(feature = "electrum")] | ||
/// timeout: None, | ||
/// #[cfg(feature = "electrum")] | ||
/// electrum: "ssl://electrum.blockstream.info:60002".to_string(), | ||
/// #[cfg(feature = "esplora")] | ||
/// esplora: None, | ||
/// #[cfg(feature = "esplora")] | ||
/// esplora_concurrency: 4, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you could add another enum called ElectrumOpts
/EsploraOpts
and then use #[structopt(flatten)]
? I think it would keep the same "public" interface, but internally it would be a bit more organized
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes good call, much cleaner this way. I originally had these two structs but took them out when I was trouble shooting some structopt
help issues. Back in now.
src/lib.rs
Outdated
pub fn handle_offline_wallet_subcommand<D>( | ||
wallet: &Wallet<(), D>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could change this to take a generic type T
instead of just ()
, which would allow you to call this with a ref to an online wallet
pub fn handle_offline_wallet_subcommand<D>( | |
wallet: &Wallet<(), D>, | |
pub fn handle_offline_wallet_subcommand<T, D>( | |
wallet: &Wallet<T, D>, |
src/bdk_cli.rs
Outdated
let offline_wallet = new_offline_wallet(network, &wallet_opts, database).unwrap(); | ||
let offline_wallet = Arc::new(offline_wallet); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... then you could remove this and just use the online_wallet
everywhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the generic type to allow handle_offline_wallet_subcommand
to accept an online wallet and works great, removed the offline_wallet
for REPL mode.
I'm going to keep the offline_wallet for the offline commands when not in REPL mode. My goal is to eventually make offline
, online
, and repl
optional cargo features. So someone could make a bdk-cli
build to only do offline CLI commands. Or maybe only offline via CLI or REPL, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, sounds good!
src/bdk_cli.rs
Outdated
let result = match repl_subcommand { | ||
ReplSubCommand::OnlineWalletSubCommand(online_subcommand) => { | ||
bdk_cli::handle_online_wallet_subcommand( | ||
&Arc::clone(&online_wallet), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you could just use &online_wallet
here and in all the other places
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I think you could remove the Arc
stuff entirely.. I don't think we are using them anymore, we are just passing normal references around
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the Arc and it works fine.
Cargo.toml
Outdated
@@ -12,8 +12,8 @@ readme = "README.md" | |||
license = "MIT" | |||
|
|||
[dependencies] | |||
bdk = { version = "^0.3", default-features = false } | |||
bdk-macros = "^0.2" | |||
bdk = { git = "https://github.com/bitcoindevkit/bdk.git", rev = "c4f2179", features = ["all-keys"]} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs default-features = false
, otherwise it'll include electrum
by default which can't be compiled under wasm32
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Had to tweek docs tests a bit but should all work now.
16f80cb
to
7ab78fd
Compare
7ab78fd
to
dc00b80
Compare
Description
Depends on bitcoindevkit/bdk#274
Added in Lib
CliOpts
struct andCliSubCommand
enum representing top level cli options and commandsKeySubCommand
enumhandle_key_subcommand
functionChanged in Lib
WalletOpt
struct toWalletOpts
WalletSubCommand
enum split intoOfflineWalletSubCommand
andOnlineWalletSubCommand
handle_wallet_subcommand
into two functions,handle_offline_wallet_subcommand
andhandle_online_wallet_subcommand
Blockchain
is used when handling offline wallet sub-commandsAdded in
bdk-cli
Changed in
bdk-cli
Notes to the reviewers
There's a little bug in the help / about info while in REPL mode.
I don't think there's a way to work around it but there is aI found a workaround for this issue.structopt
issue for it.Checklists
All Submissions:
cargo fmt
andcargo clippy
before committingNew Features:
CHANGELOG.md