refactor(solana): single definition for account and program display strings - #438
Open
shahan-khatchadourian-anchorage wants to merge 1 commit into
Conversation
…trings Three presets hand-roll the same three-arm match that `core::InstructionView` already performs, and each diverges on the out-of-bounds arm: they render `unknown` where the canonical form is `unresolved(oob:N)`. The duplicated logic is what let them drift. Extract `resolve_program_display` and `resolve_account_display` in `core`, have `InstructionView::from_context` build on them, and route the three presets through them: - `jupiter_swap` needs every account, so it takes `InstructionView::from_context(context).accounts`. - `system` names two fixed positions, so it calls `resolve_account_display` directly. - `unknown_program` drops both of its local copies (`resolve_account_str`, `resolve_program_id_str`). `unknown` disappears from account resolution and the placeholder vocabulary has one definition. No output changes for in-bounds indices, which is every index a well-formed instruction produces. Cover the previously-untested out-of-bounds arm, asserting that position-addressed resolution agrees with `InstructionView`. Closes #435
shahan-khatchadourian-anchorage
requested review from
pepe-anchor and
prasanna-anchorage
August 4, 2026 22:45
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.
Summary
Closes #435. Stacked on #436 (
worktree-434-fmt-preset-tree).core::InstructionViewowns the placeholder vocabulary for resolving account and program indices to display strings. Three presets hand-roll the same three-arm match instead of using it, and all three diverge on the out-of-bounds arm -- renderingunknownwhere the canonical form isunresolved(oob:N):presets/jupiter_swap/mod.rs:94None => "unknown".to_string()presets/system/mod.rs:123None => "unknown".to_string()presets/system/mod.rs:128None => "unknown".to_string()presets/unknown_program/mod.rs:67None => "unknown".to_string()unknowncarries no index, so it is strictly less diagnosable than the canonical form, and a signer comparing two transactions sees different vocabulary for the same condition.Approach
Extract the two resolution rules in
coreand buildInstructionViewon top of them, so there is one definition rather than one-per-caller:Then route each preset through the shape that fits how it reads accounts:
jupiter_swapneeds every account, so it takesInstructionView::from_context(context).accounts-- the closure disappears entirely.systemnames two fixed positions, so it callsresolve_account_display(context, 1)/(context, 0).unknown_programdrops both of its local copies (resolve_account_strandresolve_program_id_str-- the latter duplicated the program arm the same way) and calls the shared functions.Behavior
No output changes for in-bounds indices, which is every index a well-formed instruction produces. The
Nonearm is reachable only when a preset names a fixed position and the instruction carries fewer accounts than the layout expects; that case now rendersunresolved(oob:N)instead ofunknown.Test plan
cargo test -p visualsign-solana-- 270 passed, 0 failed (269 before; +1 new)make -C src lint-- clippy clean with-D warningstest_resolve_account_display_matches_instruction_viewasserts position-addressed resolution agrees withInstructionViewfor both resolved and unresolved indices, and covers the out-of-bounds arm that nothing exercised beforegrep '=> "unknown"'across the crate leaves only the twoswig_walletenum-name helpers andspl_token(see below)Scope
Two
"unknown"sites are deliberately untouched:presets/swig_wallet/mod.rs:2037,2047--program_scope_type_name/numeric_type_namemap unrecognized discriminants to a name. Unrelated to account resolution.presets/spl_token/mod.rs-- carries the same stale arm inside its own privateInstructionView, which PR fix(solana/spl_token): migrate to shared core::InstructionView, drop data clone #381 removes. This branch does not touch that file, so the two do not conflict and can merge in either order. Once both land,core/mod.rsholds the only copy of the resolution logic in the crate.Stacking
Based on #436 rather than
main: #436 makes the CI fmt gate coverpresets/*/, so the preset edits here are format-checked. There is no file overlap between the two branches.🤖 Generated with Claude Code