Skip to content

refactor: return DerivationResult from derive_at_index#946

Open
trevarj wants to merge 1 commit into
rust-bitcoin:masterfrom
trevarj:derive_at_index-ergo
Open

refactor: return DerivationResult from derive_at_index#946
trevarj wants to merge 1 commit into
rust-bitcoin:masterfrom
trevarj:derive_at_index-ergo

Conversation

@trevarj
Copy link
Copy Markdown
Contributor

@trevarj trevarj commented May 13, 2026

This allows a caller of derive_at_index to fall back on the original
descriptor (as a Descriptor<DefiniteDescriptorKey>) without having to match
or if-let on the Result when there is no wildcard.

We introduce a new result type called DerivationResult to handle this, but
since the Try trait is not stabilized in our MSRV we cannot have ? and must
use into_result()? instead.

Closes #918

I ultimately settled on or_fallback cause I feel that it reads nicely with
derive_at_index(0).

Not sure if I really like this solution when we can't use Try and then just
derive_at_index(0)?

@trevarj trevarj force-pushed the derive_at_index-ergo branch 2 times, most recently from 05cbda9 to 7431081 Compare May 13, 2026 20:05
@trevarj trevarj changed the title fix: improve ergonomics of derive_at_index refactor: return DerivationResult from derive_at_index May 13, 2026
@apoelstra
Copy link
Copy Markdown
Member

Yeah, concept ACK. I was skeptical of this design at first but I think it leads to pretty nice-looking code.

Comment thread src/descriptor/mod.rs Outdated
@tcharding
Copy link
Copy Markdown
Member

Is deprecated used differently in this repo @apoelstra? is the derive_at_index function going to be deleted or is it going to stay and just be made private? For my understanding also, how long is the deprecation cycle in miniscript?

@trevarj trevarj force-pushed the derive_at_index-ergo branch from 7431081 to 84dd4df Compare May 14, 2026 05:11
@trevarj
Copy link
Copy Markdown
Contributor Author

trevarj commented May 14, 2026

is the derive_at_index function going to be deleted

this is the new function that was recently added in #911. at_derivation_index is the deprecated one.

@trevarj trevarj marked this pull request as ready for review May 14, 2026 13:45
@apoelstra
Copy link
Copy Markdown
Member

For my understanding also, how long is the deprecation cycle in miniscript?

Things stay for at least two versions, but maybe (much) longer if they never get in the way of anything.

Comment thread src/descriptor/mod.rs
Comment on lines +663 to +666
/// The descriptor has no wildcard. Carries the original for fallback.
WithoutWildcard(Descriptor<DescriptorPublicKey>),
/// An error other than NoWildcard.
Error(NonDefiniteKeyError),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Either doc or variant name needs changing, right?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In docs below also.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's referring to NonDefiniteKeyError::NoWildcard, so I think it's correct still.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated all NoWildcard references to full name - NonDefiniteKeyError::NoWildcard

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah my bad, hard to get good reviews huh.

Comment thread src/descriptor/mod.rs
/// Result of [`Descriptor::derive_at_index`].
///
/// When the source descriptor has no wildcard,
/// [`or_fallback`](DerivationResult::or_fallback) recovers the definite
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
/// [`or_fallback`](DerivationResult::or_fallback) recovers the definite
/// [`or_fallback`](DerivationResult::or_fallback) recovers the original

I think?

Copy link
Copy Markdown
Contributor Author

@trevarj trevarj May 21, 2026

Choose a reason for hiding this comment

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

It returns the DefiniteDescriptor derived from the original descriptor (Descriptor<DescriptorPublicKey>)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No worries, thanks.

@tcharding
Copy link
Copy Markdown
Member

Everything else looks good to me. I raised #956 while reviewing this, please holla at me if I was confused in writing it.

Reviewed: 84dd4df

This allows a caller of `derive_at_index` to fall back on the original
descriptor (as a `Descriptor<DefiniteDescriptorKey>`) without having to `match`
or `if-let` on the `Result` when there is no wildcard.

We introduce a new result type called `DerivationResult` to handle this, but
since the `Try` trait is not stabilized in our MSRV we cannot have `?` and must
use `into_result()?` instead.
@trevarj trevarj force-pushed the derive_at_index-ergo branch from 84dd4df to a15ce35 Compare May 21, 2026 03:56
Copy link
Copy Markdown
Member

@tcharding tcharding left a comment

Choose a reason for hiding this comment

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

ACK a15ce35

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.

Have better ergonomics for derive_at_index on a descriptor with no wildcards

3 participants