Return error from at_derivation_index when descriptor has no wildcard#911
Return error from at_derivation_index when descriptor has no wildcard#911febyeji wants to merge 1 commit intorust-bitcoin:masterfrom
Conversation
trevarj
left a comment
There was a problem hiding this comment.
But what should the workflow be if you just want to convert a DescriptorPublicKey descriptor to a DefiniteDescriptorKey one, not touching wildcards if they don't exist?
I'm ok with this as long as we address what Andrew said in the linked issue. I also would like a way to convert from Descriptor<DescriptorPublicKey> into Descriptor<DefiniteDescriptorKey> since I am currently using at_derivation_index as an agnostic translation.
Maybe it can be solved with just adding a helper function into_definite() or something.
|
Thanks for the review! Extracted a public |
6cad2d4 to
cc5bded
Compare
I agree this is a bad and footgunny API.
But nither of these are reasonable API choices. Converting every key requires the user to run |
|
How about we also add a And in the docs for Secondly, because existing users are calling After a couple versions we can rename the method back because I do prefer the old name :/ but I think that the "silent breakage" of returning an error for previously-legitimate use is too much of a problem. |
I like this. Then the
Possibly even |
Oh, nice, I like this name even better than |
Nice, I like this name, too. |
cc5bded to
74075e9
Compare
|
In 74075e9: This Then |
That was my fault, sorry. |
|
Oh, lol, I missed that. Sorry to jerk you around @febyeji. But I do think it's better design to have them split up. |
…and TryFrom - Deprecate at_derivation_index() preserving old behavior (non-wildcard silently works) - Add derive_at_index() that strictly requires wildcards, delegates to at_derivation_index() - Add TryFrom<Descriptor<DescriptorPublicKey>> for Descriptor<DefiniteDescriptorKey> - Split Definitor enum into separate local Translator structs (ToDefinite, AtIndex) - Update internal callers, tests, and examples to use new API
74075e9 to
1062144
Compare
|
No worries, both suggestions made sense in context! The split looks cleaner so I just applied it. |
Closes #829.
at_derivation_index()on a descriptor without wildcards would silently ignore the index and return the descriptor unchanged. This was error-prone because callers would expect different indices to produce different addresses.DefiniteDescriptorKey::new()on individual keys, or checkhas_wildcard()before callingat_derivation_index().at_derivation_indexwildcard check