Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down
1 change: 1 addition & 0 deletions api/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/screens/wallet/swap/SwapOutStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { Button } from "src/components/ui/button";
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from "src/components/ui/card";
Expand Down Expand Up @@ -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" ? (
Expand Down
1 change: 1 addition & 0 deletions frontend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ export type BaseSwap = {
paymentHash: string;
invoice: string;
autoSwap: boolean;
usedXpub: boolean;
boltzPubkey: string;
createdAt: string;
updatedAt: string;
Expand Down
12 changes: 5 additions & 7 deletions swaps/swaps_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}()
Expand Down Expand Up @@ -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)
}
}()
Expand All @@ -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)
Expand Down Expand Up @@ -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)
}
}()
Expand Down Expand Up @@ -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)
}
}()
Expand Down