Skip to content

descriptor: expose WalletPolicy template + key_info accessors#936

Closed
bg002h wants to merge 1 commit intorust-bitcoin:masterfrom
bg002h:feat/wallet-policy-template-accessor
Closed

descriptor: expose WalletPolicy template + key_info accessors#936
bg002h wants to merge 1 commit intorust-bitcoin:masterfrom
bg002h:feat/wallet-policy-template-accessor

Conversation

@bg002h
Copy link
Copy Markdown

@bg002h bg002h commented Apr 30, 2026

Read accessors for WalletPolicy's private template and key_info fields. Motivating case: multipath-shared @N placeholders (e.g. sh(multi(1,@0/**,@0/<2;3>/*))) where into_descriptor() erases placeholder identity but the template's KeyExpression::index preserves it. Re-exports KeyExpression and KeyIndex so the return type is namable.

Found while building md-codec, a BIP 388 wallet-policy encoder. Cross-link: #934 (about set_key_info AST-order correspondence; not a blocker for this PR).

Authored by Claude Opus 4.7 under my direction.

bg002h pushed a commit to bg002h/descriptor-mnemonic that referenced this pull request Apr 30, 2026
…iscript#936

apoelstra's PR #2 closed in favor of rust-bitcoin/rust-miniscript#936
(true upstream). Same branch head, same content. Issue #934's
cross-link to PR #2 was updated in the same maneuver to reference
the new location, which removed the constraint that had previously
held PR #2 in apoelstra's fork.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@trevarj trevarj left a comment

Choose a reason for hiding this comment

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

Seems reasonable.

ACK a95a61a

Comment thread src/descriptor/wallet_policy/mod.rs Outdated
/// `(AST position) -> (placeholder index)` mapping can iterate
/// `policy.template().iter_pk()` and read `ke.index.0` for each
/// yielded `KeyExpression`. For the resolved descriptor with
/// concrete keys, see [`Self::into_descriptor`] (consumes `self`).
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Lol, why did the LLM feel the need to say this here?

Suggested change
/// concrete keys, see [`Self::into_descriptor`] (consumes `self`).
/// concrete keys, see [`Self::into_descriptor`].

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Lol, why did the LLM feel the need to say this here?

Maybe a prohibition against self consumption :)

@bg002h
Copy link
Copy Markdown
Author

bg002h commented May 1, 2026

#932

I’m not sure if there is a use case outside of shared @n index, which 932 is addressing (https://github.com/rust-bitcoin/rust-miniscript/pull/932)…

@apoelstra
Copy link
Copy Markdown
Member

Can you dramatically reduce the amount of text in the commit description, PR description, and doccomments for the new methods?

Concept ACK having these accessors.

@bg002h bg002h force-pushed the feat/wallet-policy-template-accessor branch from a95a61a to 83e8d36 Compare May 3, 2026 06:24
@bg002h
Copy link
Copy Markdown
Author

bg002h commented May 3, 2026

Thanks. Trimmed:

  • Doccomments on template() and key_info() cut to a sentence each, dropping the formula-style guidance for callers.
  • Commit message and PR description trimmed; assumed expert reader.
  • Tests left as-is — three of them, each pinning a specific invariant. Happy to collapse if you'd prefer.

cargo test --lib 155 / --all-features 173 / clippy -D warnings / fmt --check / build --no-default-features all clean locally.

— Brian (with Claude Opus 4.7)

@apoelstra
Copy link
Copy Markdown
Member

83e8d36 needs rebase

Read accessors for the two private fields. The motivating use case is
multipath-shared `@N` placeholders, e.g. `sh(multi(1,@0/**,@0/<2;3>/*))`,
where `into_descriptor()` erases placeholder identity but the template's
`KeyExpression::index` preserves it.

Re-exports `KeyExpression` and `KeyIndex` so the accessor's return type
is namable from outside the crate, and adds rustdoc on `KeyIndex` and
`KeyExpression::is_disjoint` to satisfy `missing_docs`.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@bg002h bg002h force-pushed the feat/wallet-policy-template-accessor branch from 83e8d36 to 489e799 Compare May 3, 2026 20:31
@apoelstra
Copy link
Copy Markdown
Member

Heh, thanks for the short and clear motivation. But as you say, #932 eliminates the proposed usecase.

I think we should either

  • close this; or
  • update the motivation to "these might be useful"

I'm happy to go in either direction. Though I guess we should lean toward closing, to avoid constraining our API.

@bg002h
Copy link
Copy Markdown
Author

bg002h commented May 5, 2026

(Brian says): Theoretically these accessors could be useful for template inspection without specified keys, but my use case doesn't actually require that — #932 closed the concrete gap I was worried about. Perhaps it's wise to not expose these methods until a genuine use case arises from a real programmer, as their needs may hint at a better form or way of accomplishing the same goal than what I've sketched. Confirm closing as the wisest move at this stage of the game?

@trevarj
Copy link
Copy Markdown
Contributor

trevarj commented May 5, 2026

+1 for closing if no immediate use-case

@bg002h bg002h closed this May 6, 2026
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.

3 participants