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

CreateWallet update+ListWallets+GetWalletInfo #121

Conversation

Tibo-lg
Copy link
Contributor

@Tibo-lg Tibo-lg commented Jul 30, 2020

Originally I was only planning on updating create_wallet with the extra parameters (mainly wanted the passphrase), but as I wanted to test that it was working properly I ended up needing list_wallets and get_wallet_info as well.

Some notes:

  • list_wallets and get_wallet_info are implicitly tested through the create_wallet test, I hope that's ok.
  • in GetWalletInfoResult I had to make unlocked_until optional even though it is not marked as optional in the docs (https://bitcoincore.org/en/doc/0.19.0/rpc/wallet/getwalletinfo/). I checked manually with bitcoin-cli and I could see that it was not always present, not sure why.
  • I skipped scanning from the wallet info result because I was not sure how to represent something that can be false or an object.
  • Made a small refactor to extract get_rpc_url and get_auth in the integration tests so that it can be reused to create clients for the "sub" wallets.
  • I dont have so much rust experience so apologies in advance if there are some rookie mistakes.

@Tibo-lg Tibo-lg force-pushed the create-wallet-options-and-listwallets branch 2 times, most recently from 9548c67 to 3616145 Compare July 30, 2020 06:11
@Tibo-lg
Copy link
Contributor Author

Tibo-lg commented Jul 30, 2020

Fixed for version 18 (and also fixed defaults).

Copy link
Contributor

@justinmoon justinmoon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides my one comment this looks very good!

#[serde(rename = "hdmasterkeyid")]
pub hd_master_key_id: Option<String>,
pub private_keys_enabled: bool,
pub avoid_reuse: Option<bool>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does hd_master_key_id exist? I don't see it in docs or source ...

Seems like avoid_reuse can just be a bool, right?

This implementation is also missing the scanning field:

  "scanning" : {                          (json object) current scanning details, or false if no scan is in progress
    "duration" : n,                       (numeric) elapsed seconds since scan start
    "progress" : n                        (numeric) scanning progress percentage [0.0, 1.0]
  }

But I'm not sure how to implement that because it could be either a bool or a struct. Similar scenario to #124 where you have mixed content. We could always add this later, too.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those are possible to implement, but not easy. I don't know if serde does it automatically if you create an enum. I don't think it does because there is an implied false. I can try do a custom serde implementation after this is merged if you want. (I'll create a ticket for it when we merge this.)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hdmasterkeyid field seems to have been removed in 0.18. Since we only support 0.18 and 0.19, we shouldn't have it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does hd_master_key_id exist? I don't see it in docs or source ...

Thanks, as @stevenroose pointed out it was removed so I deleted it.

Seems like avoid_reuse can just be a bool, right?

It didn't exist in v0.18 which is why I put it as an Option<>, but if there is a better way of handling this let me know (IIRC CI fails for v0.18 if it's not an option).

This implementation is also missing the scanning field:

I was curious so I gave it a try and it seems to work. It cannot be properly tested through CI though because rescanning in regtest is too fast. I gave it a try on testnet and it seems to work as expected. I put it as a separate commit for now, so if you're not happy with the implementation I'll just drop it and someone else can take care of it later. If you're happy with it I can squash it. One downside with this implementation is that it's not really explicit about the fact that the boolean part of the enum can only be false, not sure if there is a better way.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah it's unfortunate that it has this bool that is always false. But well. I'm ok with this.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps add a line of documentation on "NotScanning(bool)" that the bool will always be false?

Copy link
Collaborator

@stevenroose stevenroose left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

#[serde(rename = "hdmasterkeyid")]
pub hd_master_key_id: Option<String>,
pub private_keys_enabled: bool,
pub avoid_reuse: Option<bool>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those are possible to implement, but not easy. I don't know if serde does it automatically if you create an enum. I don't think it does because there is an implied false. I can try do a custom serde implementation after this is merged if you want. (I'll create a ticket for it when we merge this.)

avoid_reuse: Option<bool>,
}

fn build_wallet_params<'a>(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a little bit of a silly utility method that I'd personally not have created, but I don't bother because it's test stuff :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed, didn't have very strong feelings about it :)


assert_eq!(wallet_info.wallet_name, wallet_param.name);

fn option_to_bool(option: Option<bool>) -> bool {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this just .unwrap_or(false)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes thanks fixed.

}

for param in wallet_params {
test_create_single_wallet(&cl, param);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is only used here, right? I wouldn't mind just having it expanded inside this for loop. Than the WalletParams type can also be made method-local. It's just a suggestion won't be blocking for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expanded in loop and put WalletParams as method-local.

#[serde(rename = "hdmasterkeyid")]
pub hd_master_key_id: Option<String>,
pub private_keys_enabled: bool,
pub avoid_reuse: Option<bool>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hdmasterkeyid field seems to have been removed in 0.18. Since we only support 0.18 and 0.19, we shouldn't have it.

@Tibo-lg Tibo-lg force-pushed the create-wallet-options-and-listwallets branch from 3616145 to 1240252 Compare August 3, 2020 04:24
@sgeisler
Copy link
Contributor

sgeisler commented Aug 3, 2020

@stevenroose @Tibo-lg do you consider this PR ready for another round of review?

@Tibo-lg
Copy link
Contributor Author

Tibo-lg commented Aug 3, 2020

@sgeisler I think I addressed all the comments so I would say yes. If I missed something let me know.

Copy link
Contributor

@sgeisler sgeisler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, some minor nits, but if someone is annoyed by these there can be a separate PR I guess. We don't need to block on these imo, but feel free to fix them if you want and I'll re-ACK.

json/src/lib.rs Outdated
pub keypool_size: usize,
#[serde(rename = "keypoolsize_hd_internal")]
pub keypool_size_hd_internal: usize,
pub unlocked_until: Option<usize>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would SystemTime make more sense here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I double checked but all the timestamps seem to be either usize or u64. Changed to u64 as it might be better and I don't mind changing to SystemTime but I feel it might be inconsistent.

json/src/lib.rs Outdated
#[serde(rename = "paytxfee", with = "bitcoin::util::amount::serde::as_btc")]
pub pay_tx_fee: Amount,
#[serde(rename = "hdseedid")]
pub hd_seed_id: Option<String>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do we handle binary data elsewhere? Should this be decoded to [u8; 20]?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing this out, I checked and actually there was already a hd_seed_id field defined for GetAddressInfoResult so I reused the type (bitcoin::XpubIdentifier).

@Tibo-lg Tibo-lg force-pushed the create-wallet-options-and-listwallets branch from 0244b98 to 0e203cf Compare August 6, 2020 12:38
Copy link
Collaborator

@stevenroose stevenroose left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I'll add the line of comment.

@stevenroose stevenroose merged commit f394b7a into rust-bitcoin:master Aug 23, 2020
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.

4 participants