Skip to content

Conversation

@aarmoa
Copy link
Collaborator

@aarmoa aarmoa commented Aug 6, 2025

  • added back the function to create a TxConfig with configurable signing modes

Summary by CodeRabbit

  • Refactor

    • Improved modularity and organization of transaction and codec configuration, resulting in a cleaner and more maintainable client context setup.
  • Bug Fixes

    • Enhanced error handling when retrieving keys by address or name.

End-users may notice improved reliability and maintainability in transaction processing features. No changes to visible functionality.

@aarmoa aarmoa requested a review from Copilot August 6, 2025 13:50
@coderabbitai
Copy link

coderabbitai bot commented Aug 6, 2025

Walkthrough

The update refactors the Cosmos SDK client context setup by introducing helper functions for creating a protobuf codec and transaction configuration. Codec and registry initialization logic is modularized into a new function, and transaction configuration is encapsulated in another. The main context creation function is streamlined to use these helpers, with improved error handling.

Changes

Cohort / File(s) Change Summary
Client Context Refactor
client/chain/context.go
Introduces createInjectiveProtoCodec and NewTxConfig helper functions, refactors NewClientContext to use these helpers for codec, registry, and TxConfig setup, and improves error handling for key lookups.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant ClientContext
    participant CodecHelper
    participant Keyring

    Caller->>ClientContext: NewClientContext(chainId, fromSpec, kb)
    ClientContext->>CodecHelper: createInjectiveProtoCodec()
    CodecHelper-->>ClientContext: (codec, interfaceRegistry)
    ClientContext->>ClientContext: NewTxConfig([SIGN_MODE_DIRECT])
    ClientContext->>Keyring: Lookup key by Bech32 or name
    Keyring-->>ClientContext: keyInfo / error
    ClientContext-->>Caller: client.Context or error
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Poem

In the warren of code, a new path is found,
Helpers for codecs now hop all around.
Contexts refactored, with errors in check,
Transactions configured—no detail a wreck.
With every new function, the toolkit grows bright,
A rabbit’s delight in the soft morning light! 🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9ccb3b7 and 258341a.

📒 Files selected for processing (1)
  • client/chain/context.go (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: lint
  • GitHub Check: run-tests
🔇 Additional comments (3)
client/chain/context.go (3)

81-85: Successfully recovered the NewTxConfig function!

The function correctly creates a TxConfig with configurable signing modes as intended. This aligns with the PR objective to restore this previously removed functionality.

Minor consideration: The interface registry returned by createInjectiveProtoCodec() is discarded. While this works, you might consider adding a comment explaining why only the marshaler is needed here, or potentially creating a separate helper that only returns the marshaler if this pattern becomes common.


90-135: Excellent refactoring of NewClientContext!

The refactoring improves code maintainability by:

  • Extracting codec/registry initialization into a reusable helper function
  • Adding descriptive error wrapping for both address and key name lookups
  • Creating a clear EncodingConfig structure

The error handling improvements at lines 112 and 120 provide better context for debugging keyring issues.


137-187: Well-structured helper function for codec creation!

The createInjectiveProtoCodec function effectively consolidates all interface registrations in a single, reusable location. This modular approach benefits both NewTxConfig and NewClientContext functions and makes future maintenance easier.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/recover_new_tx_config_function

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR recovers a previously removed function that allows creating a TxConfig with configurable signing modes. The change refactors the existing code by extracting codec creation logic into a separate function and reintroducing the NewTxConfig utility function.

  • Adds back the NewTxConfig function for creating TxConfig with custom signing modes
  • Refactors codec creation logic into a reusable createInjectiveProtoCodec function
  • Maintains existing functionality while improving code reusability
Comments suppressed due to low confidence (1)

client/chain/context.go:137

  • [nitpick] The parameter name 'injectiveCodec' in the return signature is unnecessarily specific. Consider using 'marshaler' to be consistent with how it's used throughout the codebase.
func createInjectiveProtoCodec() (injectiveCodec *codec.ProtoCodec, interfaceRegistry types.InterfaceRegistry) {

@aarmoa aarmoa merged commit 97aaaf4 into master Aug 6, 2025
6 checks passed
@aarmoa aarmoa deleted the fix/recover_new_tx_config_function branch August 6, 2025 13:57
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