-
Notifications
You must be signed in to change notification settings - Fork 332
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
set coin type based on network #585
Conversation
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.
On the surface this seems to work, but it's actually incomplete: there's nothing preventing a testnet bip44 wallet from being used on mainnet, or vice-versa.
My suggestion is to change the DescriptorTemplate
trait to add a network argument to the build()
method. That method is called when the descriptor template is passed to a wallet constructor, so we basically get the network from that. Which means the user only has to set the network once (in the wallet's constructor) and then everything magically works!
hmm not sure I get that.. pub trait DescriptorTemplate {
/// Build the complete descriptor
fn build(self, network: Network) -> Result<DescriptorTemplateOut, DescriptorError>;
}
Bip44(prvkey, KeychainKind::External).build(Network::Bitcoin)
pub struct Bip44<K: DerivableKey<Legacy>>(pub K, pub KeychainKind);
impl<K: DerivableKey<Legacy>> DescriptorTemplate for Bip44<K> {
fn build(self, network: Network) -> Result<DescriptorTemplateOut, DescriptorError> {
P2Pkh(legacy::make_bipxx_private(44, self.0, self.1, network)?).build(network)
}
} |
Yes, exactly, something like that. This will prevent you from having conflicts, i.e. specifying network |
i see what u mean. |
Yeah I think that's fine, some templates will use the network and some won't |
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.
Concept ACK.. Thanks for working on the bug..
But I feel its still incomplete. The public templates needs to be updated too.. And the docs also needs update.. Not sure if there's some macro problem doing the fix in public part, IIUC the same bug should be active on public templates too..
@rajarshimaitra what do u think about the solution mentioned in prev message(gist)? edit: |
I looked at the diff.. But couldn't apply it.. Probably its on top of a commit not in the tree anymore.. Anyway if the issue is only having to pass unused args I think thats a better next step.. So probably worth to put another commit with the changes.. But something feels off to me. IIUC the network information should be needed for for all kind of keys.. So ideally we should only have one source of it and disperse it evenly through all the macros.. Like how would this macro know which network to derive the key for??
P2PKH mainnet and P2PKH testnet should have different coin types too.. So I think somewhere deeper a fix needs to be made so that we can disperse the network information evenly?? @afilini let me know if I am missing something here. |
This is all handled by the If you look at the If you then try to load that descriptor in a testnet wallet, you'll get an error.
I think you are confusing the address encoding, which is different, with the script, which is the same. The base58 encoding uses different prefixes for mainnet/testnet, so you get a |
Ok I see.. So the underlying macros already knows how to transmit back valid network set..
Yes I was confused here. The I guess then the only work remaining here is to make |
I don't think you can do it for the We will have to update the documentation though, for example for bip44 it says:
This should be updated and contain a note that on testnet the path should be X and on mainnet Y. |
Hi, please rebase to pickup changes in #596. Thanks! |
@jbesraa can you please simplify the commit history by doing In general anytime you wanna rebase your PR just do |
+1 for the rebase, plus i would just squash everything into a single commit for the same reason Raj mentioned I'm also starting the CI so we can see if something is wrong there |
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.
Concept ACK, can you please squash the commits in a single one? You can find a guide here: https://www.git-tower.com/learn/git/faq/git-squash
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.
tACK a8b0058
modulo https://github.com/bitcoindevkit/bdk/pull/585/files#r857772454
Code changes looks good to me.. Few small nits..
This needs rebase to pick up the CI changes :) |
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.
tACK dd14388
@jbesraa I'd love to see https://github.com/bitcoindevkit/bdk/pull/585/files#r857772454 fixed before merging :) |
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.
ACK dd14388
There's still a comment pending about an improvement to get better test coverage, but the code freeze for the release is tomorrow and we'd like to have this merged, so we will go ahead and fix the test later on.
Ah damn, I can't merge this because the commits aren't signed. Could you please fix this @jbesraa ? |
@jbesraa if you need any help setting up signing with github let me know or check out this link: https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits |
Signed-off-by: Esraa Jbara <jbesraa@gmail.com>
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.
re-ACK db9d43e
re-ACK db9d43e |
resolves #578