Skip to content

rpc: make z_importkey generic over Chain#505

Closed
oxarbitrage wants to merge 1 commit into
mainfrom
fix-import-key-generic-chain
Closed

rpc: make z_importkey generic over Chain#505
oxarbitrage wants to merge 1 commit into
mainfrom
fix-import-key-generic-chain

Conversation

@oxarbitrage

Copy link
Copy Markdown
Contributor

Fixes the main build, which broke after #400 (z_importkey/z_exportkey) merged.

#400's CI last ran 2026-06-08, before the "make the JSON-RPC layer generic over Chain" refactor landed on main (2026-06-19 … 06-22, #492). That refactor turned self.chain() into a generic C: Chain, but #400's import_key::call and its fetch_account_birthday helper still took a concrete FetchServiceSubscriber. The two were textually mergeable but type-incompatible, so once both were on main the build failed with:

error[E0308]: `?` operator has incompatible types
 --> zallet/src/components/json_rpc/methods.rs:1009:13
1009 |     self.chain().await?,
     expected `FetchServiceSubscriber`, found type parameter `C`

This migrates import_key::call and fetch_account_birthday to the generic Chain/ChainView API, mirroring the pattern the refactor applied to the other RPC methods (e.g. get_new_account): fetch_account_birthday now snapshots the chain and reads the treestate via ChainView::tree_state_as_of, building the birthday from the resulting ChainState.

Verified locally on current main: cargo build -p zallet, cargo clippy -p zallet --all-targets, cargo fmt --check, and cargo test -p zallet import_key all pass.

🤖 Generated with Claude Code

Comment on lines +156 to +163
LegacyCode::Database.with_message(format!(
"Failed to get treestate at height {treestate_height}: {e}"
))
})?
.ok_or_else(|| {
LegacyCode::Database.with_message(format!(
"Failed to get treestate at height {treestate_height}: above chain tip"
))

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.

#506 seems like it does a better thing with the error types here; this isn't a database error. Otherwise this and #506 are functionally identical.

@oxarbitrage

Copy link
Copy Markdown
Contributor Author

Closing in favor of #506

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.

2 participants