Skip to content

feat: implement transaction.direct status update#497

Merged
jackstar12 merged 3 commits into
feat/lwk-server-integrationfrom
feat/direct-tx-lwk
Jul 10, 2025
Merged

feat: implement transaction.direct status update#497
jackstar12 merged 3 commits into
feat/lwk-server-integrationfrom
feat/direct-tx-lwk

Conversation

@jackstar12

@jackstar12 jackstar12 commented Jul 6, 2025

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • New Features

    • Added support for handling direct transactions in reverse swaps, including selection of suitable outputs and special handling for Liquid currency.
    • Introduced the ability to derive blinding keys for Liquid wallet addresses.
    • Implemented a new method to query reverse swaps by claim address.
  • Bug Fixes

    • Prevented creation of multiple pending reverse swaps with the same claim address.
  • Refactor

    • Separated fee estimation logic from amount checking for improved modularity.
    • Simplified and improved the logic for processing and checking reverse swaps.
  • Tests

    • Added tests for direct output selection and updated tests to verify prevention of duplicate claim addresses in reverse swaps.
    • Re-enabled and updated Liquid-related test cases.

@coderabbitai

coderabbitai Bot commented Jul 6, 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

This update introduces new methods for reverse swap management, including querying by claim address and selecting direct outputs. It refactors fee estimation and amount checking logic for better modularity, enhances direct reverse swap payment handling, and adds related tests. Duplicate claim address prevention is enforced during reverse swap creation.

Changes

File(s) Change Summary
internal/database/reverse.go Added QueryReverseSwapByClaimAddress method to query pending reverse swaps by claim address.
internal/nursery/nursery.go Refactored fee estimation into GetFeeEstimations; updated CheckAmounts to use this new method.
internal/nursery/nursery_test.go Added TestChooseDirectOutput to test output selection logic for reverse swaps.
internal/nursery/reverse.go Added/updated methods for direct output selection and direct payment handling; refactored swap wallet checks.
internal/onchain/liquid-wallet/wallet.go Added descriptor field and DeriveBlindingKey method to Wallet.
internal/rpcserver/router.go Added check to prevent duplicate claim addresses for pending reverse swaps.
internal/rpcserver/rpcserver_test.go Updated tests to check for duplicate claim address errors and re-enabled Liquid test cases.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant RPCServer
    participant Database

    Client->>RPCServer: createReverseSwap(claimAddress)
    RPCServer->>Database: Query all pending reverse swaps
    Database-->>RPCServer: List of pending swaps
    RPCServer->>RPCServer: Check for duplicate claimAddress
    alt Duplicate found
        RPCServer-->>Client: Error (AlreadyExists)
    else No duplicate
        RPCServer->>Database: Create new reverse swap
        Database-->>RPCServer: Confirmation
        RPCServer-->>Client: Success
    end
Loading
sequenceDiagram
    participant Nursery
    participant Onchain
    participant Database

    Nursery->>Onchain: GetFeeEstimations()
    Onchain-->>Nursery: FeeEstimations
    Nursery->>Database: Fetch ReverseSwaps
    loop For each swap
        Nursery->>Onchain: Get outputs for swap
        Nursery->>Nursery: chooseDirectOutput(swap, fees, outputs)
        Nursery->>Nursery: handleReverseSwapDirectPayments(swap, outputs)
        Nursery->>Database: Update swap status/claim tx
    end
Loading

Possibly related PRs

Suggested reviewers

  • michael1011

Poem

In the warren, swaps abound,
Claim addresses checked, errors found.
Outputs chosen with careful eyes,
Fees estimated, no surprise.
Liquid keys now blind with glee,
All these changes, code runs free!
🐰✨


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 jackstar12 force-pushed the feat/direct-tx-lwk branch from c924032 to 20e87e2 Compare July 6, 2025 19:37
Comment thread internal/rpcserver/rpcserver_test.go Outdated
Comment thread internal/nursery/reverse.go Outdated
Comment thread internal/nursery/reverse.go
Comment thread internal/nursery/reverse.go Outdated
Comment thread internal/nursery/reverse.go Outdated
@jackstar12 jackstar12 force-pushed the feat/direct-tx-lwk branch from ead465d to e2c6d65 Compare July 8, 2025 12:07
@jackstar12

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 8, 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 (1)

1910-1910: Consider using event-based waiting instead of sleep.

While the 1-second sleep works, it could make tests slower and potentially flaky. Consider waiting for a specific event or condition instead.

internal/nursery/reverse.go (1)

155-199: Consider improving the wallet type handling clarity.

The current implementation correctly handles Liquid wallets but silently breaks for non-Liquid wallets (e.g., GDK). While the comment explains this, consider making the intent more explicit.

Consider adding a log message or more explicit handling:

 } else {
-    // gdk handles direct transactions via its own transaction notifier
+    // gdk handles direct transactions via its own transaction notifier
+    logger.Debugf("Skipping direct transaction handling for non-LWK wallet type")
     break
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 15627fa and e2c6d65.

📒 Files selected for processing (7)
  • internal/database/reverse.go (1 hunks)
  • internal/nursery/nursery.go (1 hunks)
  • internal/nursery/nursery_test.go (2 hunks)
  • internal/nursery/reverse.go (5 hunks)
  • internal/onchain/liquid-wallet/wallet.go (5 hunks)
  • internal/rpcserver/router.go (1 hunks)
  • internal/rpcserver/rpcserver_test.go (6 hunks)
🧰 Additional context used
🧠 Learnings (3)
internal/nursery/nursery_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/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.
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.
🧬 Code Graph Analysis (4)
internal/nursery/nursery.go (3)
pkg/boltz/fees.go (2)
  • FeeEstimations (31-31)
  • CheckAmounts (63-72)
pkg/boltz/currency.go (2)
  • CurrencyLiquid (12-12)
  • CurrencyBtc (11-11)
pkg/boltz/api.go (1)
  • Percentage (79-79)
internal/onchain/liquid-wallet/wallet.go (1)
internal/onchain/liquid-wallet/lwk/lwk.go (3)
  • WolletDescriptor (7173-7175)
  • NewWolletDescriptor (7177-7187)
  • NewAddress (2356-2366)
internal/rpcserver/router.go (2)
internal/database/database.go (2)
  • SwapQuery (332-341)
  • Id (330-330)
pkg/boltzrpc/boltzrpc.pb.go (5)
  • SwapState (70-70)
  • SwapState (115-117)
  • SwapState (119-121)
  • SwapState (128-130)
  • SwapState_PENDING (73-73)
internal/rpcserver/rpcserver_test.go (2)
internal/test/test.go (2)
  • GetNewAddress (188-190)
  • LiquidCli (160-162)
pkg/boltzrpc/boltzrpc.pb.go (1)
  • Currency_LBTC (136-136)
🔇 Additional comments (15)
internal/database/reverse.go (1)

269-278: LGTM! Well-implemented database query method.

The new QueryReverseSwapByClaimAddress method correctly follows the existing patterns in the codebase and properly filters by both claim address and PENDING state to prevent duplicate claim addresses.

internal/nursery/nursery_test.go (1)

111-218: Excellent test coverage for the new functionality.

The TestChooseDirectOutput test is well-implemented with comprehensive coverage of different scenarios including matching outputs, no matches, and the special case of zero-value outputs for Liquid transactions. The table-driven test structure makes it easy to understand and maintain.

internal/nursery/nursery.go (1)

368-388: Good refactoring that improves modularity.

The extraction of fee estimation logic into a separate GetFeeEstimations method improves code organization and reusability. The method properly handles errors for both currency fee estimations and maintains the existing behavior of CheckAmounts.

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

30-30: LGTM!

The descriptor field is properly added to store the wallet descriptor for deriving blinding keys.


191-207: LGTM!

The descriptor initialization and usage in the constructor is implemented correctly with proper error handling.


395-406: LGTM!

The DeriveBlindingKey method correctly implements blinding key derivation for Liquid addresses with appropriate error handling.

internal/rpcserver/rpcserver_test.go (4)

34-34: LGTM!

The serializers import is correctly added and used for currency parsing in the test.


1830-1846: LGTM!

The test correctly validates that duplicate claim addresses are prevented for pending reverse swaps, which aligns with the new validation logic.


1854-1856: LGTM!

Re-enabling the Liquid test cases is appropriate now that the Liquid blinding key derivation is implemented.


1867-1867: LGTM!

The mock expectation for BroadcastTransaction is correctly added to support the transaction broadcasting in the test flow.

internal/nursery/reverse.go (5)

9-14: LGTM!

The added imports are necessary for string manipulation and Liquid wallet operations.


285-323: LGTM! The output selection logic is well-implemented.

The method correctly handles multiple outputs, prevents double-claiming, and has appropriate special handling for unblindable Liquid outputs.


325-377: Excellent implementation of direct payment handling!

The method properly handles direct payments with atomic database updates, appropriate confirmation checks, and comprehensive error handling.


388-402: LGTM!

The simplified individual swap processing is cleaner and aligns well with the duplicate claim address prevention strategy.


407-424: LGTM!

The method signature change to handle a single swap is consistent with the new processing model and simplifies the logic.

Comment thread internal/rpcserver/router.go Outdated
Comment thread internal/rpcserver/router.go Outdated
Comment thread internal/nursery/reverse.go Outdated
Comment thread internal/nursery/reverse.go Outdated
@jackstar12 jackstar12 force-pushed the feat/direct-tx-lwk branch 2 times, most recently from 05f3273 to d9b9d61 Compare July 8, 2025 20:18
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
@jackstar12 jackstar12 force-pushed the feat/direct-tx-lwk branch from d9b9d61 to 03c34e6 Compare July 8, 2025 20:20
@jackstar12 jackstar12 requested a review from michael1011 July 8, 2025 20:31
@jackstar12 jackstar12 force-pushed the feat/direct-tx-lwk branch from c76b957 to 13ef84e Compare July 8, 2025 21:02
@jackstar12 jackstar12 merged commit 166fa66 into feat/lwk-server-integration Jul 10, 2025
2 of 4 checks passed
@jackstar12 jackstar12 deleted the feat/direct-tx-lwk branch July 10, 2025 10:14
jackstar12 added a commit that referenced this pull request Jul 10, 2025
* feat: lwk server integration

* feat: lwk `GetOutputs` implementation for MRHs

* refactor: improve wallet tests

* chore: .gitignore

* chore: deprecate subaccount apis

* feat: electrum backend

* refactor: `getOwnWallet` -> `getGdkWallet`

* fix: dont select subaccounts in cli wallet import

not needed anymore

* feat: `TxProvider` in wallet backend

important to not broadcast via boltz

* feat: lwk index persister

* refactor: move full scan of wallets into seperate `Sync` function

this way, we can create the wallet inside of a transaction with the
other db operations and have the heavier sync not block the db

* feat: transactions pagination

* docs: clarify persister comments

* fix: correct insufficient funds error

want to be consistent with gdk

* fix: encrypt wallets after logging in

* feat: derive default descriptor before creating wallet in db

users will see descriptor in credentials of hot wallets this way

* fix: use `GetSendFee` from wallet interface in `checkBalance`

* feat: implement `transaction.direct` status update (#497)

* 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

* fix: remove manual GC run

debugging leftover
@coderabbitai coderabbitai Bot mentioned this pull request Jul 11, 2025
@coderabbitai coderabbitai Bot mentioned this pull request Oct 9, 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