Skip to content

feat: lwk server integration#462

Merged
jackstar12 merged 19 commits into
feat/lwkfrom
feat/lwk-server-integration
Jul 10, 2025
Merged

feat: lwk server integration#462
jackstar12 merged 19 commits into
feat/lwkfrom
feat/lwk-server-integration

Conversation

@jackstar12

@jackstar12 jackstar12 commented Jun 3, 2025

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • New Features

    • Added support for Liquid currency wallets alongside existing Bitcoin wallets.
    • Liquid wallet backend is now initialized and managed by the server.
    • Introduced a method to retrieve outputs (UTXOs) by address in wallets.
    • Added legacy wallet flag support and migration for existing wallets.
  • Bug Fixes

    • Improved transactional consistency when importing wallets and changing wallet passwords.
    • Enhanced error handling in swap output matching logic.
  • Refactor

    • Unified wallet login logic for both Bitcoin and Liquid wallets.
    • Subaccount creation is now restricted to Bitcoin wallets only.
    • Enhanced wallet funding logic in tests to ensure reliability.
    • Deprecated wallet subaccount functionality in API and documentation.
  • Tests

    • Updated test setup to ensure wallets are properly funded and streamlined test wallet management.
    • Added tests validating legacy wallet behavior.
    • Simplified event waiting logic in wallet consolidation tests.
  • Chores

    • Added Makefile target to clear wallet test data before regtest startup.
    • Updated .gitignore to exclude liquid wallet test data directory.

@coderabbitai

coderabbitai Bot commented Jun 3, 2025

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The changes introduce Liquid wallet support to the server, including initialization of a Liquid blockchain backend, new wallet login logic, and transactional improvements for wallet import and credential encryption. Test helpers are refactored to ensure deterministic wallet funding, and subaccount management is now restricted to BTC wallets.

Changes

File(s) Change Summary
internal/onchain/liquid-wallet/wallet.go Added Electrum client support with generic client interface; default sync interval set by network; wallet method GetOutputs added; replaced explicit Esplora client with interface-based client.
internal/rpcserver/router.go Added Liquid backend field; unified wallet login logic for BTC and Liquid; wallet import and credential encryption wrapped in DB transactions; subaccount creation limited to BTC; wallet retrieval broadened in some methods.
internal/rpcserver/rpcserver_test.go Removed TestMain; refactored fundedWallet to fetch/import named wallet and ensure funding; removed unnecessary SetSubaccount call; added TestLegacyWallet for legacy flag behavior.
internal/rpcserver/server.go Initialized Liquid blockchain backend during server start with config and error handling.
internal/cln/cln.go Added stub GetOutputs method returning unsupported error; fixed missing closing brace in SendToAddress.
internal/database/database.go Added legacy boolean column to wallets table with default FALSE.
internal/database/migration.go Incremented schema version to 16; added migration to add legacy column and set it TRUE for existing wallets; added migration logging.
internal/database/wallet.go Updated parseWallet to scan new Legacy field into wallet struct.
internal/lnd/lnd.go Added stub GetOutputs method returning unsupported error.
internal/mocks/lightning/LightningNode_mock.go Added mock method GetOutputs with full mocking support.
internal/mocks/onchain/Wallet_mock.go Added mock method GetOutputs with full mocking support.
internal/nursery/reverse.go Removed wallet package import; changed checkSwapsWallet to call GetOutputs on generic wallet interface; improved error handling for unsupported method; adjusted control flow for output matching.
internal/onchain/wallet.go Added GetOutputs method to Wallet interface; added Legacy boolean field to WalletCredentials.
internal/onchain/liquid-wallet/wallet_test.go Refactored test setup to use shared backend config function; removed global consolidation threshold; updated wallet creation helpers to accept backend parameter; replaced some test helpers with direct wallet creation and funding calls.
internal/onchain/wallet/wallet_test.go Simplified consolidation wait logic by replacing manual event loop with require.Eventually polling.
internal/rpcserver/serializer.go Added //nolint:staticcheck directives to serializeWalletSubaccount function.
internal/test/test.go Removed liquid wallet test setup functions; renamed fundWallet to exported FundWallet; removed liquid wallet package import.
pkg/boltzrpc/boltzrpc.proto Marked wallet subaccount RPCs, messages, and fields as deprecated.
pkg/boltzrpc/client/client.go Added //nolint:staticcheck directives to deprecated subaccount methods.
.gitignore Added internal/rpcserver/test/liquid-wallet/ directory to .gitignore.
Makefile Added clear-wallet-data target to remove liquid wallet test data; updated start-regtest and restart-regtest targets to depend on it.
cmd/boltzcli/commands.go Added blank line after claimSwaps; added //nolint:staticcheck before printSubaccount function.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Server
    participant DB
    participant BTCBackend
    participant LiquidBackend

    User->>Server: ImportWallet(credentials)
    Server->>DB: Start transaction
    Server->>DB: Decrypt & append credentials
    Server->>Server: loginWallet(credentials)
    alt Currency is BTC
        Server->>BTCBackend: Login(credentials)
    else Currency is Liquid
        Server->>LiquidBackend: Login(credentials)
    end
    Server->>DB: Encrypt all credentials
    Server->>DB: Commit transaction
    Server->>User: Return wallet info
Loading

Possibly related PRs

  • BoltzExchange/boltz-client#451: Introduces the initial implementation of the lwk wallet, which this PR extends by integrating and initializing the Liquid wallet backend.

Suggested reviewers

  • michael1011

Poem

A hop to Liquid, a leap to chain,
The wallets grow, no code in vain.
With BTC and Liquid, side by side,
Credentials safe, transactions glide.
On test and main, the bunnies cheer—
New wallets bloom, the path is clear!
🐰💧🪙


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.

@jackstar12

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 3, 2025

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@jackstar12

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 3, 2025

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@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

🔭 Outside diff range comments (1)
internal/rpcserver/router.go (1)

1396-1433: 🛠️ Refactor suggestion

Consider defensive copying when appending to the credentials slice.

The refactoring to use database transactions is excellent for ensuring atomicity. However, on line 1415, appending to decryptedCredentials modifies the original slice returned by decryptWalletCredentials. If this slice is cached or used elsewhere, it could lead to unexpected behavior.

Consider creating a new slice to avoid modifying the original:

-		decryptedCredentials = append(decryptedCredentials, credentials)
+		allCredentials := make([]*onchain.WalletCredentials, len(decryptedCredentials)+1)
+		copy(allCredentials, decryptedCredentials)
+		allCredentials[len(decryptedCredentials)] = credentials

 		if password != "" {
-			if err := server.encryptWalletCredentials(tx, password, decryptedCredentials); err != nil {
+			if err := server.encryptWalletCredentials(tx, password, allCredentials); err != nil {
 				return fmt.Errorf("could not encrypt credentials: %w", err)
 			}
 		}
🧹 Nitpick comments (2)
internal/onchain/liquid-wallet/wallet.go (1)

64-82: Consider making Regtest Esplora URL configurable

The enhanced Esplora configuration logic with default settings for Regtest is a good improvement. However, the hardcoded http://localhost:3003 URL might be inflexible for different development setups.

Consider making the default Regtest URL configurable through environment variables or configuration:

		case boltz.Regtest:
+			url := os.Getenv("REGTEST_ESPLORA_URL")
+			if url == "" {
+				url = "http://localhost:3003"
+			}
			cfg.Esplora = &EsploraConfig{
-				Url:       "http://localhost:3003",
+				Url:       url,
				Waterfall: false,
			}

The rest of the logic correctly handles client creation and error cases.

internal/rpcserver/router.go (1)

2397-2402: Clean wallet routing implementation.

The loginWallet method provides clean routing between Liquid and Bitcoin wallet implementations. The implementation is simple and focused.

Consider adding error context to help with debugging:

 func (server *routedBoltzServer) loginWallet(credentials *onchain.WalletCredentials) (onchain.Wallet, error) {
 	if credentials.Currency == boltz.CurrencyLiquid {
-		return liquid_wallet.NewWallet(server.liquidBackend, credentials)
+		wallet, err := liquid_wallet.NewWallet(server.liquidBackend, credentials)
+		if err != nil {
+			return nil, fmt.Errorf("failed to create liquid wallet: %w", err)
+		}
+		return wallet, nil
 	}
-	return wallet.Login(credentials)
+	wallet, err := wallet.Login(credentials)
+	if err != nil {
+		return nil, fmt.Errorf("failed to login to wallet: %w", err)
+	}
+	return wallet, nil
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9ede288 and e6c67a3.

📒 Files selected for processing (4)
  • internal/onchain/liquid-wallet/wallet.go (1 hunks)
  • internal/rpcserver/router.go (11 hunks)
  • internal/rpcserver/rpcserver_test.go (1 hunks)
  • internal/rpcserver/server.go (2 hunks)
🧰 Additional context used
🪛 GitHub Actions: CI
internal/rpcserver/rpcserver_test.go

[error] 288-288: TestDirectReverseSwapPayments/Multiple failed: timed out while waiting for swap EA5UqotPduHR to reach state SUCCESSFUL


[error] 1850-1850: TestDirectReverseSwapPayments/Liquid/ZeroConf failed: rpc error: code = Unknown desc = wallet regtest has insufficient balance for sending 50069 sats


[error] 2793-2793: TestChainSwap/BTC/InternalWallets/EnoughBalance failed: rpc error: code = NotFound desc = readonly wallet with id: 2 currency: L-BTC not found


[error] 2793-2793: TestChainSwap/Liquid/InternalWallets/EnoughBalance failed: rpc error: code = NotFound desc = readonly wallet with id: 2 currency: BTC not found


[error] 2971-2971: TestChainSwap/BTC/Refund/Manual/Wallet/Valid failed: Should not be zero, but was 0


[error] 1859-1859: TestDirectReverseSwapPayments/Liquid/Normal failed: timed out while waiting for swap wqSqI2oSbGg5 to reach state PENDING

🔇 Additional comments (11)
internal/rpcserver/server.go (2)

21-21: LGTM: Clean import addition

The import of the liquid_wallet package follows Go conventions and is properly aliased.


194-200:

Details

✅ Verification successful

Verify liquidBackend field declaration in routedBoltzServer struct

The liquid backend initialization logic is correct and follows the same pattern as other backend initializations. However, ensure that the liquidBackend field is declared in the routedBoltzServer struct.


🏁 Script executed:

#!/bin/bash
# Description: Verify that liquidBackend field is declared in routedBoltzServer struct
# Expected: Should find the liquidBackend field declaration

ast-grep --pattern $'type routedBoltzServer struct {
  $$$
  liquidBackend $_
  $$$
}'

Length of output: 1207


liquidBackend field is properly declared

The routedBoltzServer struct in internal/rpcserver/router.go already includes:

• Line 73: liquidBackend *liquid_wallet.BlockchainBackend

No further action required.

internal/onchain/liquid-wallet/wallet.go (1)

53-58: LGTM: Network-specific sync intervals improve development experience

The network-specific sync interval configuration is a good improvement. Using 1 second for Regtest environments will provide faster feedback during development and testing, while maintaining the 30-second default for production networks.

internal/rpcserver/router.go (8)

29-29: LGTM!

The import of the liquid-wallet package with an appropriate alias is clean and follows Go conventions.


73-74: LGTM!

The liquidBackend field is properly typed and logically placed with other service dependencies in the struct.


1531-1539: Verify that Liquid wallets don't support subaccounts.

The code now restricts subaccount creation to BTC wallets only. While the comment indicates this is intentional ("only GDK wallets have subaccounts"), please confirm that:

  1. Liquid wallets indeed don't support subaccounts in the current implementation
  2. This won't break any existing functionality for users who might have expected subaccount support for Liquid wallets

1736-1761: LGTM! Proper multi-currency support.

The changes correctly handle fee estimation for different wallet currencies by:

  • Extracting the currency from the wallet info
  • Using the appropriate currency for fee estimation
  • Selecting the correct dummy address based on the wallet's currency

1826-1829: LGTM!

Using getAnyWallet with AllowReadonly: true is appropriate for wallet removal operations, as both readonly and regular wallets should be removable.


1922-1934: LGTM! Good transaction composition pattern.

The signature change to accept a transaction parameter enables better transaction composition, allowing this method to participate in larger atomic operations. The caller is now responsible for transaction management, which is a cleaner design.


2032-2032: LGTM!

Using the new loginWallet method provides proper routing between Bitcoin and Liquid wallet implementations while maintaining the concurrent login behavior.


2071-2073: LGTM! Proper transaction usage.

Wrapping the credential encryption in a transaction ensures atomicity - if encryption fails for any credential, all changes are rolled back. This prevents partial password updates.

Comment thread internal/rpcserver/rpcserver_test.go
@jackstar12 jackstar12 force-pushed the feat/lwk-server-integration branch 2 times, most recently from 16c3c8f to c10fd68 Compare June 4, 2025 06:50
@jackstar12 jackstar12 force-pushed the feat/lwk-server-integration branch from c10fd68 to fa5d3ea Compare June 24, 2025 10:19
@jackstar12 jackstar12 force-pushed the feat/lwk-server-integration branch from fa5d3ea to c1e12c4 Compare June 24, 2025 10:54
@jackstar12 jackstar12 force-pushed the feat/lwk-server-integration branch from cdd4bdb to 904749c Compare June 24, 2025 18:59
@jackstar12 jackstar12 force-pushed the feat/lwk-server-integration branch from 904749c to ab20430 Compare June 30, 2025 14:10
@jackstar12 jackstar12 marked this pull request as ready for review June 30, 2025 16:20
@jackstar12

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 30, 2025

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@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

🧹 Nitpick comments (2)
internal/rpcserver/rpcserver_test.go (2)

1866-1869: Fix TODO grammar and consider tracking in an issue.

The TODO comment has a grammatical error and should be tracked properly.

-		// TODO: re-enable this once when we have mrh notifications
+		// TODO: re-enable this once we have mrh notifications

Consider creating a GitHub issue to track the re-enabling of these Liquid tests when mrh notifications are implemented.


3159-3195: Well-structured test for legacy wallet functionality.

The test properly verifies the legacy wallet type switching behavior. Good use of type assertions to verify the wallet implementation changes from liquid_wallet.Wallet to wallet.Wallet when the legacy flag is set.

Consider extracting the direct SQL update into a test helper function for better maintainability:

func setWalletLegacyFlag(t *testing.T, db *database.Database, walletId uint64, legacy bool) {
    _, err := db.Exec("UPDATE wallets SET legacy = ? WHERE id = ?", legacy, walletId)
    require.NoError(t, err)
}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e6c67a3 and a122e80.

⛔ Files ignored due to path filters (5)
  • pkg/boltzrpc/autoswaprpc/autoswaprpc.pb.go is excluded by !**/*.pb.go
  • pkg/boltzrpc/autoswaprpc/autoswaprpc_grpc.pb.go is excluded by !**/*.pb.go
  • pkg/boltzrpc/boltzrpc.pb.go is excluded by !**/*.pb.go
  • pkg/boltzrpc/boltzrpc.pb.gw.go is excluded by !**/*.pb.gw.go
  • pkg/boltzrpc/boltzrpc_grpc.pb.go is excluded by !**/*.pb.go
📒 Files selected for processing (23)
  • .gitignore (1 hunks)
  • Makefile (1 hunks)
  • cmd/boltzcli/commands.go (2 hunks)
  • docs/grpc.md (1 hunks)
  • internal/cln/cln.go (1 hunks)
  • internal/database/database.go (1 hunks)
  • internal/database/migration.go (2 hunks)
  • internal/database/wallet.go (1 hunks)
  • internal/lnd/lnd.go (1 hunks)
  • internal/mocks/lightning/LightningNode_mock.go (1 hunks)
  • internal/mocks/onchain/Wallet_mock.go (1 hunks)
  • internal/nursery/reverse.go (1 hunks)
  • internal/onchain/liquid-wallet/wallet.go (5 hunks)
  • internal/onchain/liquid-wallet/wallet_test.go (5 hunks)
  • internal/onchain/wallet.go (2 hunks)
  • internal/onchain/wallet/wallet_test.go (1 hunks)
  • internal/rpcserver/router.go (15 hunks)
  • internal/rpcserver/rpcserver_test.go (5 hunks)
  • internal/rpcserver/serializer.go (1 hunks)
  • internal/rpcserver/server.go (2 hunks)
  • internal/test/test.go (2 hunks)
  • pkg/boltzrpc/boltzrpc.proto (4 hunks)
  • pkg/boltzrpc/client/client.go (1 hunks)
✅ Files skipped from review due to trivial changes (5)
  • .gitignore
  • internal/rpcserver/serializer.go
  • internal/database/database.go
  • docs/grpc.md
  • cmd/boltzcli/commands.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • internal/rpcserver/server.go
  • internal/onchain/liquid-wallet/wallet.go
🧰 Additional context used
🧠 Learnings (5)
pkg/boltzrpc/client/client.go (1)
Learnt from: jackstar12
PR: BoltzExchange/boltz-client#444
File: internal/rpcserver/router.go:2036-2052
Timestamp: 2025-05-26T09:32:25.533Z
Learning: In boltz-client, when handling Boltz backend connectivity during startup, the code intentionally uses different error handling strategies: logger.Fatalf for version incompatibility (fail fast approach) and retry logic for availability issues. Version incompatibility requires immediate human intervention and should not be retried.
internal/nursery/reverse.go (1)
Learnt from: jackstar12
PR: BoltzExchange/boltz-client#444
File: internal/rpcserver/router.go:2036-2052
Timestamp: 2025-05-26T09:32:25.533Z
Learning: In boltz-client, when handling Boltz backend connectivity during startup, the code intentionally uses different error handling strategies: logger.Fatalf for version incompatibility (fail fast approach) and retry logic for availability issues. Version incompatibility requires immediate human intervention and should not be retried.
internal/test/test.go (1)
Learnt from: jackstar12
PR: BoltzExchange/boltz-client#444
File: internal/rpcserver/router.go:2036-2052
Timestamp: 2025-05-26T09:32:25.533Z
Learning: In boltz-client, when handling Boltz backend connectivity during startup, the code intentionally uses different error handling strategies: logger.Fatalf for version incompatibility (fail fast approach) and retry logic for availability issues. Version incompatibility requires immediate human intervention and should not be retried.
internal/rpcserver/router.go (1)
Learnt from: jackstar12
PR: BoltzExchange/boltz-client#444
File: internal/rpcserver/router.go:2036-2052
Timestamp: 2025-05-26T09:32:25.533Z
Learning: In boltz-client, when handling Boltz backend connectivity during startup, the code intentionally uses different error handling strategies: logger.Fatalf for version incompatibility (fail fast approach) and retry logic for availability issues. Version incompatibility requires immediate human intervention and should not be retried.
internal/rpcserver/rpcserver_test.go (1)
Learnt from: jackstar12
PR: BoltzExchange/boltz-client#444
File: internal/rpcserver/router.go:2036-2052
Timestamp: 2025-05-26T09:32:25.533Z
Learning: In boltz-client, when handling Boltz backend connectivity during startup, the code intentionally uses different error handling strategies: logger.Fatalf for version incompatibility (fail fast approach) and retry logic for availability issues. Version incompatibility requires immediate human intervention and should not be retried.
🧬 Code Graph Analysis (8)
pkg/boltzrpc/client/client.go (2)
pkg/boltzrpc/boltzrpc.pb.go (6)
  • Subaccount (5992-6001)
  • Subaccount (6016-6016)
  • Subaccount (6031-6033)
  • SetSubaccountRequest (4618-4626)
  • SetSubaccountRequest (4641-4641)
  • SetSubaccountRequest (4656-4658)
internal/onchain/wallet/wallet.go (1)
  • Subaccount (53-59)
internal/onchain/wallet.go (1)
internal/onchain/onchain.go (1)
  • Output (33-36)
internal/onchain/wallet/wallet_test.go (1)
internal/onchain/wallet/wallet.go (1)
  • MaxInputs (36-36)
internal/lnd/lnd.go (2)
internal/onchain/onchain.go (1)
  • Output (33-36)
internal/lightning/lightning.go (1)
  • ErrUnsupported (28-28)
internal/cln/cln.go (2)
internal/onchain/onchain.go (1)
  • Output (33-36)
internal/lightning/lightning.go (1)
  • ErrUnsupported (28-28)
internal/nursery/reverse.go (4)
internal/lightning/lightning.go (1)
  • ErrUnsupported (28-28)
internal/database/reverse.go (1)
  • ReverseSwap (17-49)
internal/onchain/onchain.go (2)
  • Output (33-36)
  • Id (19-19)
internal/logger/logger.go (1)
  • Errorf (97-99)
internal/mocks/onchain/Wallet_mock.go (1)
internal/onchain/onchain.go (1)
  • Output (33-36)
internal/mocks/lightning/LightningNode_mock.go (2)
internal/onchain/onchain.go (1)
  • Output (33-36)
internal/nursery/swap.go (1)
  • Output (32-39)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: CI (ubuntu-latest, 1.24.x)
🔇 Additional comments (40)
internal/database/wallet.go (1)

59-59: LGTM! Database field scanning correctly updated.

The addition of the Legacy field scanning aligns with the database schema migration and follows the established pattern for parsing wallet fields.

pkg/boltzrpc/client/client.go (1)

118-118: LGTM! Appropriate lint suppressions for deprecated methods.

The //nolint:staticcheck directives correctly suppress static analysis warnings for the deprecated subaccount methods while maintaining backward compatibility.

Also applies to: 123-123

internal/lnd/lnd.go (1)

400-402: LGTM! Proper stub implementation for unsupported functionality.

The GetOutputs method correctly implements the Wallet interface by returning lightning.ErrUnsupported, consistent with other unsupported methods in the LND implementation.

internal/cln/cln.go (2)

354-354: LGTM! Syntax fix resolves missing closing brace.

The addition of the closing brace fixes the SendToAddress method syntax.


356-358: LGTM! Consistent stub implementation for unsupported functionality.

The GetOutputs method properly implements the Wallet interface with lightning.ErrUnsupported, maintaining consistency with the LND implementation and other unsupported methods in CLN.

internal/onchain/wallet.go (2)

57-57: LGTM! Clean interface extension for output retrieval.

The GetOutputs method is a well-designed addition to the Wallet interface, enabling address-specific output retrieval with an appropriate signature that returns []*Output and error.


75-75: LGTM! Legacy field supports wallet migration strategy.

The Legacy boolean field is properly positioned in the WalletCredentials struct and aligns with the database migration strategy for distinguishing legacy wallets during the Liquid wallet integration.

Makefile (2)

76-78: LGTM! Clean test data management.

The new clear-wallet-data target properly removes test data directories for both liquid wallet components, ensuring a clean testing environment.


80-84: LGTM! Automated cleanup integration.

Adding the clear-wallet-data dependency to both regtest targets ensures test data is automatically cleaned before each run, preventing potential test contamination.

internal/test/test.go (2)

64-64: LGTM! Function export for broader usage.

Exporting FundWallet enables its usage in other packages, which aligns with the restructured wallet initialization approach.


132-132: LGTM! Consistent function naming.

Updated call correctly uses the newly exported FundWallet function.

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

279-292: LGTM! Simplified test logic with reliable polling.

The replacement of complex event notification logic with require.Eventually polling is a good improvement. The test now:

  • Polls every 250ms for up to 15 seconds
  • Checks for the expected number of transactions (including consolidation)
  • Validates consolidation transaction properties correctly

This approach is more reliable and easier to understand than the previous event-based waiting.

internal/database/migration.go (3)

24-24: LGTM! Schema version incremented for new migration.

Correctly increments the schema version to support the new legacy wallet column migration.


591-592: LGTM! Proper migration logging.

Consistent with the established pattern of logging migration steps.


598-611: LGTM! Well-structured migration for legacy wallet support.

The migration correctly:

  • Adds the legacy boolean column with appropriate default value (FALSE)
  • Sets existing wallets as legacy (TRUE) to maintain backward compatibility
  • Includes proper error handling for both steps

This supports the new wallet type differentiation in the Liquid wallet integration.

internal/nursery/reverse.go (1)

339-377: LGTM! Excellent abstraction improvement.

The refactoring successfully removes the dependency on the internal wallet package by:

Key improvements:

  • Uses the new generic GetOutputs interface method instead of type assertion
  • Handles ErrUnsupported gracefully by returning (false, nil)
  • Implements sophisticated output-to-swap matching with proper sorting by amount
  • Includes robust error handling for database queries

Logic validation:

  • Correctly sorts both swaps and outputs by amount for optimal matching
  • Handles multiple swaps per address with appropriate output selection
  • Validates existing claim transactions to prevent conflicts
  • Chooses outputs that best match swap amounts while staying within bounds

This abstraction enables the nursery to work generically across different wallet implementations while maintaining all the existing functionality.

pkg/boltzrpc/boltzrpc.proto (4)

108-108: LGTM: Consistent deprecation of subaccount RPC methods.

The deprecation of SetSubaccount and GetSubaccounts RPC methods aligns with the broader changes to restrict subaccount management to BTC wallets only.

Also applies to: 113-113


721-721: LGTM: Subaccount field deprecation in WalletCredentials.

Marking the subaccount field as deprecated is consistent with the overall subaccount deprecation strategy.


746-746: LGTM: Comprehensive deprecation of subaccount message types.

All subaccount-related request and response messages are properly marked as deprecated, ensuring a consistent deprecation strategy.

Also applies to: 753-753, 758-758


899-899: LGTM: Core Subaccount message deprecation.

Deprecating the main Subaccount message completes the systematic phase-out of subaccount functionality.

internal/onchain/liquid-wallet/wallet_test.go (4)

22-28: LGTM: Centralized configuration management.

The defaultConfig() function provides a clean way to centralize test configuration, improving maintainability and consistency across tests.


32-32: LGTM: Improved TestMain initialization.

Using defaultConfig() for backend initialization and adding explicit logger initialization improves test setup consistency.

Also applies to: 36-36


121-132: LGTM: Explicit backend parameter in helper function.

Making the backend parameter explicit in the newWallet helper function improves clarity and allows for test-specific backend configurations.


147-152: LGTM: Test-specific backend configuration.

Creating a custom backend with a specific ConsolidationThreshold for the auto-consolidation test enables deterministic testing behavior.

internal/mocks/onchain/Wallet_mock.go (1)

204-264: LGTM: Proper mock implementation for new GetOutputs method.

The auto-generated mock for GetOutputs(address string) ([]*onchain.Output, error) follows the standard testify mock patterns and provides complete testing support for the new wallet interface method.

internal/mocks/lightning/LightningNode_mock.go (1)

446-506: LGTM: Consistent GetOutputs mock implementation.

The auto-generated mock for GetOutputs(address string) ([]*onchain.Output, error) on the LightningNode interface matches the wallet implementation and follows proper testify mock conventions.

internal/rpcserver/rpcserver_test.go (3)

20-21: LGTM! Import statements properly organized.

The new imports for Liquid wallet support are correctly added and follow the project's import organization pattern.


1161-1186: Much improved wallet funding implementation!

The refactored fundedWallet function addresses the critical issues from previous reviews:

  • ✅ Uses require.Eventually with a 10-second timeout instead of an infinite loop
  • ✅ Proper error handling without failing the test inside the polling logic
  • ✅ Sends multiple transactions before mining to ensure deterministic funding

This implementation is much more robust and test-friendly.


1847-1857: Good improvement to test reliability with polling logic.

The change from immediate checks to require.Eventually with block mining makes the test more robust by accounting for asynchronous transaction processing. The 15-second timeout with 3-second intervals provides a good balance between test speed and reliability.

internal/rpcserver/router.go (11)

29-29: LGTM: Import added for Liquid wallet support

The import follows Go naming conventions and aligns with the PR objective of integrating Liquid wallet functionality.


72-72: LGTM: Server struct extended for Liquid backend

The liquidBackend field addition is consistent with the server architecture pattern and enables Liquid wallet functionality as mentioned in the AI summary.


1394-1431: Excellent refactoring: Wallet import now runs in database transaction

The wallet import process has been properly refactored to ensure transactional consistency. The implementation correctly:

  • Validates credentials before database operations
  • Uses RunTx to wrap all database operations in a transaction
  • Handles wallet login and onchain addition within the transaction scope
  • Provides proper error handling with rollback on failure

This addresses potential data consistency issues that could occur if the process failed partway through.


1533-1542: LGTM: Subaccount creation restricted to BTC wallets

The logic correctly restricts subaccount creation to BTC wallets only, which aligns with the comment "only GDK wallets have subaccounts" and the overall deprecation of subaccount features for other currencies.


1739-1739: Good change: Broadened wallet access for fee estimation and removal

Changing from getOwnWallet to getAnyWallet allows more flexible wallet access patterns:

  • Line 1739: Enables fee estimation for any wallet type (not just owned/modifiable wallets)
  • Line 1829: Allows removal of any wallet type (including read-only wallets)

This is consistent with the functionality these operations require.

Also applies to: 1829-1829


1744-1752: LGTM: Improved fee estimation logic

The refactoring correctly:

  • Extracts currency from the wallet info rather than hardcoding
  • Uses the wallet's currency for fee estimation and dummy address lookup
  • Maintains the same logic flow while being more generic

This supports multi-currency wallet operations introduced with Liquid support.


1925-1937: LGTM: Password encryption refactored for transaction support

The encryptWalletCredentials function now properly accepts a transaction parameter, enabling it to be used within database transactions. The implementation correctly:

  • Uses the passed transaction for database operations
  • Maintains the same encryption logic
  • Provides proper error handling

This supports the transactional wallet import process.


2056-2058: LGTM: Password change operation now transactional

The password change operation is properly wrapped in a database transaction using RunTx, ensuring atomicity when updating multiple wallet credentials. This is consistent with the transactional approach used elsewhere in the codebase.


2017-2017: LGTM: Using unified loginWallet method

The call to server.loginWallet(creds) uses the new unified method that handles both Liquid and Bitcoin wallets based on the credential type. This maintains consistency with the wallet login logic used elsewhere.


2382-2387: Excellent implementation: Unified wallet login method

The new loginWallet method provides clean abstraction for wallet creation:

  • Correctly routes Liquid wallets (non-legacy) to the Liquid wallet implementation
  • Falls back to the standard Bitcoin wallet implementation for legacy wallets
  • Maintains type safety and clear separation of concerns

This is a well-designed solution for supporting multiple wallet backends while maintaining backward compatibility.


1462-1487: Deprecation of subaccount RPCs confirmed
Both SetSubaccount and GetSubaccounts (and their request/response messages, plus the Subaccount type) are marked option deprecated = true in pkg/boltzrpc/boltzrpc.proto. The //nolint:staticcheck in internal/rpcserver/router.go is therefore appropriate.

Key locations:

  • pkg/boltzrpc/boltzrpc.proto:
    • rpc SetSubaccount (SetSubaccountRequest) returns (Subaccount) { option deprecated = true; }
    • rpc GetSubaccounts (GetSubaccountsRequest) returns (GetSubaccountsResponse) { option deprecated = true; }
    • message SetSubaccountRequest { option deprecated = true; … }
    • message GetSubaccountsRequest { option deprecated = true; … }
    • message GetSubaccountsResponse { option deprecated = true; … }
    • message Subaccount { option deprecated = true; … }

No further changes required.

Comment thread internal/rpcserver/router.go

@michael1011 michael1011 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Waterfall working nicely?

Comment thread cmd/boltzcli/commands.go
Comment thread pkg/boltzrpc/boltzrpc.proto
Comment thread pkg/boltzrpc/client/client.go
@jackstar12 jackstar12 force-pushed the feat/lwk-server-integration branch from 04cade3 to c4e6fc4 Compare July 1, 2025 13:58
Comment thread cmd/boltzcli/commands.go
if !wallet.Readonly {
return wallet, selectSubaccount(ctx, wallet.Id)
}
fmt.Printf("Wallet Balance: %s\n", utils.Satoshis(wallet.Balance.Total))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why?

@jackstar12 jackstar12 Jul 2, 2025

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

In the GDK model, we had to choose a subaccount after importing to actually discover all accounts and see the balance.

We dont do that in LWK anymore. We import, in case of a mnemonic it derives the default descriptor (wpkh) and syncs to that - done.

The LWK implementation now allows populating both mnemonic and descriptor to allow cases where the default descriptor isn't the one the user wants. That option still has to be built into the CLI

@michael1011 michael1011 Jul 9, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I mean why print the balance on import

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

If the wallet has an existing balance I can see that directly here too

Comment thread internal/onchain/wallet.go
Comment thread internal/rpcserver/router.go
Comment thread internal/onchain/liquid-wallet/wallet.go
Comment thread internal/onchain/liquid-wallet/wallet.go
Comment thread internal/onchain/liquid-wallet/wallet.go
Comment thread internal/onchain/liquid-wallet/wallet.go
@jackstar12 jackstar12 force-pushed the feat/lwk-server-integration branch from 831d105 to 15627fa Compare July 4, 2025 12:51
Comment thread internal/rpcserver/router.go Outdated
if err != nil {
return nil, err
}
runtime.GC()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why run garbage collection manually?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Debugging leftovers

jackstar12 and others added 2 commits July 10, 2025 12:13
* feat: implement `transaction.direct` status update

* refactor: dont set mrh for external claim addresses

this simplifies the handling of direct payments and gets rid of the
problem where we cant verify the value of liquid transactions made to
these transactions

* fix: flaky gdk bump test
debugging leftover
@jackstar12 jackstar12 force-pushed the feat/lwk-server-integration branch from 424cc08 to ba3eb9b Compare July 10, 2025 10:15
@jackstar12 jackstar12 merged commit 4852f12 into feat/lwk Jul 10, 2025
@jackstar12 jackstar12 deleted the feat/lwk-server-integration branch July 10, 2025 10:15
@kilrau kilrau mentioned this pull request Jul 10, 2025
@jackstar12 jackstar12 mentioned this pull request Jul 11, 2025
@coderabbitai coderabbitai Bot mentioned this pull request Oct 1, 2025
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