fix: auto swap to xpub (#1662)

This commit is contained in:
Roland 2025-08-29 16:47:31 +07:00 committed by GitHub
parent 7ad3a9e5c2
commit 7a38f051c5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 20 additions and 7 deletions

View file

@ -185,6 +185,12 @@ Make sure to update your RPC password below, and change your work directory each
And then run the frontend with: `VITE_API_URL="http://localhost:8082" yarn dev:http`
To test auto-swaps to xpub you can use sparrow wallet in regtest:
/opt/sparrow/bin/Sparrow -n regtest
Sparrow needs to be connected to regtest boltz setup Bitcoin Core RPC (127.0.0.1:18443 with user:password as `__cookie__:cookiepassword`) with an imported mnemonic and copied the tpub from the settings page
### Migrating the database (Sqlite <-> Postgres)
Migration of the database is currently experimental. Please make a backup before continuing.

View file

@ -748,6 +748,7 @@ func toApiSwap(swap *swaps.Swap) *Swap {
BoltzPubkey: swap.BoltzPubkey,
CreatedAt: swap.CreatedAt.Format(time.RFC3339),
UpdatedAt: swap.UpdatedAt.Format(time.RFC3339),
UsedXpub: swap.UsedXpub,
}
}

View file

@ -205,6 +205,7 @@ type Swap struct {
BoltzPubkey string `json:"boltzPubkey"`
CreatedAt string `json:"createdAt"`
UpdatedAt string `json:"updatedAt"`
UsedXpub bool `json:"usedXpub"`
}
type StartRequest struct {

View file

@ -14,6 +14,7 @@ import { Button } from "src/components/ui/button";
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from "src/components/ui/card";
@ -54,6 +55,11 @@ export default function SwapOutStatus() {
{swapStatus === "PENDING" && <Loading className="w-4 h-4 mr-2" />}
{statusText[swapStatus]}
</CardTitle>
{swap.autoSwap && (
<CardDescription className="flex justify-center">
Auto swap{swap.usedXpub && <> to xpub</>}
</CardDescription>
)}
</CardHeader>
<CardContent className="flex flex-col items-center gap-4">
{swapStatus === "SUCCESS" ? (

View file

@ -218,6 +218,7 @@ export type BaseSwap = {
paymentHash: string;
invoice: string;
autoSwap: boolean;
usedXpub: boolean;
boltzPubkey: string;
createdAt: string;
updatedAt: string;

View file

@ -229,7 +229,7 @@ func (svc *swapsService) EnableAutoSwapOut() error {
"amount": amount,
"destination": actualDestination,
}).Info("Initiating swap")
_, err = svc.SwapOut(amount, swapDestination, false, true, usedXpubDerivation)
_, err = svc.SwapOut(amount, actualDestination, false, true, usedXpubDerivation)
if err != nil {
logger.Logger.WithError(err).Error("Failed to initiate swap")
continue
@ -309,6 +309,7 @@ func (svc *swapsService) SwapOut(amount uint64, destination string, useExactRece
defer func() {
if err != nil && dbSwap.ID != 0 {
logger.Logger.WithError(err).Error("Marking swap state as failed")
svc.markSwapState(&dbSwap, constants.SWAP_STATE_FAILED)
}
}()
@ -444,6 +445,7 @@ func (svc *swapsService) SwapIn(amount uint64, autoSwap bool) (*SwapResponse, er
defer func() {
if err != nil && dbSwap.ID != 0 {
logger.Logger.WithError(err).Error("Marking swap state as failed")
svc.markSwapState(&dbSwap, constants.SWAP_STATE_FAILED)
}
}()
@ -454,12 +456,6 @@ func (svc *swapsService) SwapIn(amount uint64, autoSwap bool) (*SwapResponse, er
return err
}
defer func() {
if err != nil {
svc.markSwapState(&dbSwap, constants.SWAP_STATE_FAILED)
}
}()
ourKeys, err = svc.keys.GetSwapKey(dbSwap.ID)
if err != nil {
return fmt.Errorf("error generating swap child private key: %w", err)
@ -853,6 +849,7 @@ func (svc *swapsService) startSwapInListener(swap *db.Swap) {
svc.swapListenersLock.Unlock()
svc.boltzWs.Unsubscribe(swap.SwapId)
if err != nil {
logger.Logger.WithError(err).Error("Marking swap state as failed")
svc.markSwapState(swap, constants.SWAP_STATE_FAILED)
}
}()
@ -1020,6 +1017,7 @@ func (svc *swapsService) startSwapOutListener(swap *db.Swap) {
svc.swapListenersLock.Unlock()
svc.boltzWs.Unsubscribe(swap.SwapId)
if err != nil {
logger.Logger.WithError(err).Error("Marking swap state as failed")
svc.markSwapState(swap, constants.SWAP_STATE_FAILED)
}
}()