Skip to content

refactor: move Credentials out of wallet implementation#455

Merged
jackstar12 merged 2 commits into
masterfrom
refactor/wallet-credentials
May 30, 2025
Merged

refactor: move Credentials out of wallet implementation#455
jackstar12 merged 2 commits into
masterfrom
refactor/wallet-credentials

Conversation

@jackstar12

@jackstar12 jackstar12 commented May 30, 2025

Copy link
Copy Markdown
Member

in preparation for lwk

Summary by CodeRabbit

  • New Features

    • Introduced enhanced wallet management capabilities, including new structures for wallet balances, transactions, and credentials, as well as support for credential encryption and decryption.
  • Refactor

    • Updated wallet credential handling across the app for consistency, replacing previous types with unified wallet credential structures and interfaces.
    • Improved separation of wallet and blockchain logic for clearer organization.
  • Bug Fixes

    • Corrected field and parameter names to ensure proper wallet credential assignment and usage.
  • Tests

    • Updated test cases to use the new wallet credential structures and interfaces.

@coderabbitai

coderabbitai Bot commented May 30, 2025

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@jackstar12 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 0 minutes and 58 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 0df8269 and e0158dd.

📒 Files selected for processing (1)
  • internal/onchain/wallet.go (1 hunks)

Walkthrough

This change migrates wallet credential structures and related interfaces from the internal/onchain/wallet package to a new internal/onchain package. All type references, imports, and method signatures across the codebase are updated accordingly. Wallet management interfaces and types are centralized in internal/onchain, and redundant or outdated code is removed.

Changes

File(s) Change Summary
internal/onchain/onchain.go Removed all wallet-related structs and the Wallet interface from this file.
internal/onchain/wallet.go Introduced new wallet-related structs and the Wallet interface, including credential encryption/decryption logic.
internal/onchain/wallet/wallet.go Removed local Credentials struct and methods; updated to use onchain.WalletCredentials in the Login function.
internal/database/wallet.go Updated imports and all references to use onchain.WalletCredentials instead of the previous type and import alias.
internal/onchain/encrypt.go, encrypt_test.go Changed package declaration from wallet to onchain.
internal/onchain/wallet/wallet_test.go Updated all test type references from onchainWallet.Credentials to onchain.WalletCredentials.
internal/rpcserver/router.go Updated all method signatures and type usages from wallet.Credentials to onchain.WalletCredentials.
internal/rpcserver/serializer.go Changed function parameter type from *wallet.Credentials to *onchain.WalletCredentials.
internal/rpcserver/rpcserver_test.go Changed struct field assignment from Credentials to WalletCredentials in test code.
internal/test/test.go Changed factory function return type from *wallet.Credentials to *onchain.WalletCredentials.

Sequence Diagram(s)

sequenceDiagram
    participant RPCServer
    participant Database
    participant Onchain

    RPCServer->>Onchain: ImportWallet(credentials: *WalletCredentials)
    Onchain->>Onchain: Encrypt/Decrypt credentials
    RPCServer->>Database: Store/Retrieve WalletCredentials
    Database-->>RPCServer: Return WalletCredentials
    RPCServer->>Onchain: Login(credentials: *WalletCredentials)
    Onchain-->>RPCServer: Wallet instance or error
Loading

Suggested reviewers

  • michael1011

Poem

In burrows deep, credentials leap
From wallet’s warren, a tidy sweep.
Now Onchain’s home for every key,
With structs and methods hopping free.
Encryption, tests, and types align—
This code refactor’s simply fine!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 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.
    • @coderabbitai modularize this function.
  • 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.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

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 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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5e25a2f and 0df8269.

📒 Files selected for processing (11)
  • internal/database/wallet.go (5 hunks)
  • internal/onchain/encrypt.go (1 hunks)
  • internal/onchain/encrypt_test.go (1 hunks)
  • internal/onchain/onchain.go (0 hunks)
  • internal/onchain/wallet.go (1 hunks)
  • internal/onchain/wallet/wallet.go (1 hunks)
  • internal/onchain/wallet/wallet_test.go (7 hunks)
  • internal/rpcserver/router.go (7 hunks)
  • internal/rpcserver/rpcserver_test.go (1 hunks)
  • internal/rpcserver/serializer.go (1 hunks)
  • internal/test/test.go (1 hunks)
💤 Files with no reviewable changes (1)
  • internal/onchain/onchain.go
🧰 Additional context used
🧬 Code Graph Analysis (4)
internal/rpcserver/serializer.go (2)
internal/onchain/wallet.go (1)
  • WalletCredentials (67-74)
pkg/boltzrpc/boltzrpc.pb.go (3)
  • WalletCredentials (4309-4320)
  • WalletCredentials (4335-4335)
  • WalletCredentials (4350-4352)
internal/rpcserver/rpcserver_test.go (3)
internal/onchain/wallet.go (1)
  • WalletCredentials (67-74)
internal/test/test.go (1)
  • WalletCredentials (52-63)
pkg/boltzrpc/boltzrpc.pb.go (3)
  • WalletCredentials (4309-4320)
  • WalletCredentials (4335-4335)
  • WalletCredentials (4350-4352)
internal/rpcserver/router.go (7)
internal/onchain/wallet.go (2)
  • WalletCredentials (67-74)
  • Wallet (47-57)
internal/test/test.go (1)
  • WalletCredentials (52-63)
pkg/boltzrpc/boltzrpc.pb.go (6)
  • WalletCredentials (4309-4320)
  • WalletCredentials (4335-4335)
  • WalletCredentials (4350-4352)
  • Wallet (5777-5788)
  • Wallet (5803-5803)
  • Wallet (5818-5820)
internal/database/wallet.go (1)
  • Wallet (9-12)
internal/onchain/wallet/wallet.go (1)
  • Wallet (61-68)
internal/onchain/onchain.go (1)
  • Id (19-19)
internal/database/database.go (1)
  • Id (327-327)
internal/onchain/wallet.go (3)
internal/onchain/onchain.go (2)
  • Id (19-19)
  • Currency (71-76)
internal/test/test.go (1)
  • WalletCredentials (52-63)
internal/onchain/wallet/wallet.go (1)
  • Subaccount (53-59)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: CI (ubuntu-latest, 1.24.x)
🔇 Additional comments (14)
internal/onchain/encrypt.go (1)

1-1: LGTM! Package refactoring aligns with PR objectives.

The package declaration change from wallet to onchain is consistent with the refactoring goal of moving Credentials out of the wallet implementation into the broader onchain package.

internal/onchain/encrypt_test.go (1)

1-1: LGTM! Package refactoring with comprehensive test coverage.

The package declaration change from wallet to onchain is consistent with the refactoring objectives. The test provides excellent coverage for the encryption functionality, including both success and failure scenarios.

internal/rpcserver/rpcserver_test.go (1)

1725-1725: LGTM! Field name updated to match new credential structure.

The field name change from Credentials to WalletCredentials correctly reflects the updated database schema that now embeds onchain.WalletCredentials instead of the legacy wallet.Credentials type.

internal/rpcserver/serializer.go (1)

240-240: LGTM! Function signature updated to use new credential type.

The parameter type change from *wallet.Credentials to *onchain.WalletCredentials is consistent with the refactoring effort. The function body remains unchanged, indicating that the field structure between the old and new types is compatible for serialization purposes.

internal/onchain/wallet/wallet_test.go (1)

146-257: LGTM! Consistent type reference updates.

The changes correctly update all references from onchainWallet.Credentials to onchain.WalletCredentials while preserving the test logic and structure. The refactoring is applied consistently across all test cases.

internal/test/test.go (1)

52-54: LGTM! Clean type migration in test utility.

The function signature and return type are correctly updated to use onchain.WalletCredentials while maintaining the same functionality and structure.

internal/database/wallet.go (5)

6-6: LGTM! Import updated correctly.

The import path is properly updated to reference the new onchain package instead of the wallet package.


10-10: LGTM! Embedded struct type updated correctly.

The embedded struct approach is maintained while using the new onchain.WalletCredentials type, preserving the inheritance of credential fields.


31-43: LGTM! Function signature updated consistently.

The UpdateWalletCredentials function parameter type is correctly updated to use onchain.WalletCredentials while maintaining the same functionality.


47-47: LGTM! Struct initialization updated correctly.

The initialization properly creates the new onchain.WalletCredentials type within the embedded struct pattern.


95-116: LGTM! Return type and logic updated consistently.

The QueryWalletCredentials function correctly:

  • Returns the new type []*onchain.WalletCredentials
  • Uses the proper variable declaration
  • Accesses the embedded credential via wallet.WalletCredentials
internal/onchain/wallet/wallet.go (1)

441-508:

Details

✅ Verification successful

LGTM! Login function updated to use new credential type.

The Login function parameter is correctly updated to accept *onchain.WalletCredentials while preserving all the existing logic for credential validation, wallet connection, and subaccount handling.

Let me verify that this refactoring was applied consistently across the entire codebase:


🏁 Script executed:

#!/bin/bash
# Description: Verify that all references to the old credential type have been updated
# Expected: No remaining references to onchainWallet.Credentials or wallet.Credentials in wallet context

echo "Checking for any remaining references to old credential types..."

# Search for old credential type references
rg "onchainWallet\.Credentials" --type go

# Search for wallet.Credentials that might be related to this refactoring
rg "wallet\.Credentials" --type go

# Verify new type is being used
echo -e "\nVerifying new type usage:"
rg "onchain\.WalletCredentials" --type go -C 2

Length of output: 7361


Refactoring of Credential Type Verified

I ran a global search and confirmed there are no remaining references to the old credential types (onchainWallet.Credentials or wallet.Credentials). All authentication and serialization logic now uniformly uses *onchain.WalletCredentials across:

  • internal/rpcserver/serializer.go
  • internal/rpcserver/router.go
  • internal/onchain/wallet/wallet.go & wallet_test.go
  • internal/database/wallet.go

No further changes required.

internal/rpcserver/router.go (1)

1393-1393: LGTM! Consistent refactoring to use onchain.WalletCredentials.

All references to wallet.Credentials have been properly updated to use onchain.WalletCredentials, and the database interactions have been adjusted to use the WalletCredentials field. The variable rename from creds to dbWallet improves code clarity.

Also applies to: 1428-1428, 1451-1461, 1810-1824, 1907-1907, 1924-1924, 2009-2011

internal/onchain/wallet.go (1)

1-118: Well-structured wallet types and interfaces.

The new onchain package provides a clean separation of wallet-related types and interfaces. The WalletCredentials struct properly extends WalletInfo with sensitive data fields, and the encryption/decryption methods handle different credential types appropriately. This refactoring successfully centralizes wallet management functionality.

Comment thread internal/onchain/wallet.go Outdated
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@jackstar12 jackstar12 merged commit 6ec064d into master May 30, 2025
3 checks passed
@jackstar12 jackstar12 deleted the refactor/wallet-credentials branch May 30, 2025 10:29
@coderabbitai coderabbitai Bot mentioned this pull request Oct 18, 2025
@coderabbitai coderabbitai Bot mentioned this pull request Mar 9, 2026
@coderabbitai coderabbitai Bot mentioned this pull request Apr 29, 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.

1 participant