feat: expose Wallet::keychains#1031
Conversation
There was a problem hiding this comment.
This is great! I'm surprised we didn't have this one in before.
My one suggestion would be to consider returning the full Descriptor type instead of a string. This would allow users to then call methods like Descriptor::descriptor_id and Descriptor::desc_type and whatnot.
The trick is to populate the key_map type with an empty keymap, which is what happens on the constructors of Descriptor when the provided string is a public descriptor. I convinced myself of this by hacking on the Descriptor::new method and adding things like
eprintln!("The keymap at this point is: {:?}", &key_map);
if key_map.is_empty() {
eprintln!("####### The key_map is empty! #######")
}Trying this locally and fixing the tests, I realized that our current method Wallet::public_descriptor does return a string, but rather than matching this behaviour I would suggest we modify the Wallet::public_descriptor to return the full type on our next major release (it'd be a breaking change).
Tests had to be modified:
assert_eq!(
external.public_descriptor.to_string(),
wallet.public_descriptor(KeychainKind::External).to_string()
);
assert_eq!(
internal.public_descriptor.to_string(),
wallet.public_descriptor(KeychainKind::Internal).to_string()
);
assert!(!external.public_descriptor.to_string().contains("tprv"));
assert!(!internal.public_descriptor.to_string().contains("tprv"));I would also suggest we derive/write the Display trait for this new struct.
/// A wallet keychain and its public descriptor.
#[derive(uniffi::Record)]
pub struct WalletKeychain {
/// Type of keychain.
pub keychain: KeychainKind,
/// Public descriptor for the keychain.
pub public_descriptor: Arc<Descriptor>,
}| /// Type of keychain. | ||
| pub keychain: KeychainKind, | ||
| /// Public descriptor for the keychain. | ||
| pub public_descriptor: String, |
There was a problem hiding this comment.
Suggestion: we could use the full Descriptor type here (expanded upon in my main comment).
There was a problem hiding this comment.
totally, I can't believe I still do this old String thing sometimes, good call out, should be fixed now
| .keychains() | ||
| .map(|(keychain, descriptor)| WalletKeychain { | ||
| keychain, | ||
| public_descriptor: descriptor.to_string(), |
There was a problem hiding this comment.
These lines would become
.map(|(keychain, descriptor)| WalletKeychain {
keychain,
public_descriptor: Arc::new(Descriptor {
extended_descriptor: descriptor.clone(),
key_map: KeyMap::default(),
}),
})
Yes! Great call. Let me update Pr for them |
|
All great comments @thunderbiscuit , v good review, I think I fixed them all so this should be good to go (other than rebase, I've got a bunch of prs to rebase though and not sure which order I'll merge them in so I'll wait to rebase this atm) |
thunderbiscuit
left a comment
There was a problem hiding this comment.
Just one last little thing.
|
|
||
| /// A wallet keychain and its public descriptor. | ||
| #[derive(uniffi::Record)] | ||
| pub struct WalletKeychain { |
There was a problem hiding this comment.
The Display trait is defined on line 221 but not actually exported to the bindings. We need to add #[uniffi::export(Display)].
In this case for Kotlin the WalletKeychain type is a data class and so gets a toString() implementation for free so we get a nice display, but it's not exactly the string you defined in the Display trait implementation on line 221, and I don't think all languages produce this sort of automated toString for simple data types like this one.
// Without exporting Display
[WalletKeychain(keychain=EXTERNAL, publicDescriptor=wpkh([9122d9e0/84'/1'/0']tpubDCYVtmaSaDzTxcgvoP5AHZNbZKZzrvoNH9KARep88vESc6MxRqAp4LmePc2eeGX6XUxBcdhAmkthWTDqygPz2wLAyHWisD299Lkdrj5egY6/0/*)#zpaanzgu), WalletKeychain(keychain=INTERNAL, publicDescriptor=wpkh([9122d9e0/84'/1'/0']tpubDCYVtmaSaDzTxcgvoP5AHZNbZKZzrvoNH9KARep88vESc6MxRqAp4LmePc2eeGX6XUxBcdhAmkthWTDqygPz2wLAyHWisD299Lkdrj5egY6/1/*)#n4cuwhcy)]
// After exporting Display
[External: wpkh([9122d9e0/84'/1'/0']tpubDCYVtmaSaDzTxcgvoP5AHZNbZKZzrvoNH9KARep88vESc6MxRqAp4LmePc2eeGX6XUxBcdhAmkthWTDqygPz2wLAyHWisD299Lkdrj5egY6/0/*)#zpaanzgu, Internal: wpkh([9122d9e0/84'/1'/0']tpubDCYVtmaSaDzTxcgvoP5AHZNbZKZzrvoNH9KARep88vESc6MxRqAp4LmePc2eeGX6XUxBcdhAmkthWTDqygPz2wLAyHWisD299Lkdrj5egY6/1/*)#n4cuwhcy]There was a problem hiding this comment.
really nice catch, making a mental note to make sure this doesnt get missed in future prs, fixing
|
Ready for rebase + merge. |
Description
Exposes
Wallet::keychainsso users can inspect each wallet keychain and its public descriptorNotes to the reviewers
Documentation
bdk_wallethttps://docs.rs/bdk_wallet/3.0.0/src/bdk_wallet/wallet/mod.rs.html#592-594
bitcoinuniffiChangelog
Checklists
All Submissions:
cargo fmtandcargo clippybefore committingchangelog:*labelNew Features:
Bugfixes: