refactor(wallet_policy): follow up on BIP-388 review - #1031
Open
trevarj wants to merge 6 commits into
Open
Conversation
- add an infallible constructor for the single-path case
- the fields and validate() are now private to the submodule, so every construction path validates - the TryFrom<&str> template branch goes through a private from_template instead of a struct literal
With `translate_pk` now walking the descriptor in left-to-right order, `from_descriptor` no longer needs a separate `iter_pk` pass to number the keys in textual order. - drop the `iter_pk` pre-pass in `from_descriptor` - number each distinct key at its first occurrence in the translator
Every construction and mutation of a `WalletPolicy` now runs through the same checker. - replace `validate` with a `check_policy` fn that the constructors call before building the struct - `set_key_info` drops its own count check, rejects an empty argument and revalidates through `check_policy` before assigning
apoelstra
reviewed
Aug 22, 2026
| } | ||
| } | ||
|
|
||
| struct WalletPolicyTranslator { |
Member
There was a problem hiding this comment.
In 4974394:
I would suggest going further than this:
- Make
WalletPolicy::from_templatepub(super) - Similarly add
as_templateandinto_templatemethods which are alsopub(super)
Then you can move WalletPolicyTranslator, both your existing public constructors, n_keys, and the Display/FromStr/TryFrom impls, all out of policy.rs and up to mod.rs.
This will leave policy.rs very small and easy for a reviewer to determine that every single constructor obeys the invariants. It would have only the pub(super) methods, key_info and set_key_info, and the private check_* methods in it.
Contributor
Author
There was a problem hiding this comment.
Looks better when reviewing all commits at once now.
- keep validated state construction and mutation in the private policy module - move translation and public API implementations to the parent module
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow up to #1019 with incorporated feedback.
DerivPaths::singleconstructorWalletPolicyandKeyInfointo their own private modulescheck_policy