daemon

package
v0.0.0-...-0895702 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 6, 2026 License: AGPL-3.0 Imports: 22 Imported by: 0

Documentation

Overview

40swap daemon to the lightning node

Index

Constants

View Source
const MONITORING_INTERVAL_SECONDS = 10

Variables

This section is empty.

Functions

func ErrInvalidConfig

func ErrInvalidConfig(message string) error

ErrInvalidConfig is returned when the auto swap configuration is invalid

func Start

func Start(ctx context.Context, server *rpc.Server, db Repository, swaps swaps.ClientInterface, lightning lightning.Client, bitcoin bitcoin.Client, network lightning.Network, autoSwapService *AutoSwapService) error

func StartAutoSwapLoop

func StartAutoSwapLoop(ctx context.Context, autoSwapService *AutoSwapService)

StartAutoSwapLoop runs the auto swap check every config.GetCheckInterval()

Types

type AutoSwapConfig

type AutoSwapConfig struct {
	Enabled              bool
	CheckIntervalMinutes int
	TargetBalanceBTC     float64
	BackoffFactor        float64
	MaxAttempts          int
	RoutingFeeLimitPPM   int
	MinSwapSizeBTC       float64
	MaxSwapSizeBTC       float64
}

AutoSwapConfig holds the configuration for auto swap functionality

func NewAutoSwapConfigFromFlags

func NewAutoSwapConfigFromFlags(
	enabled bool,
	interval int,
	targetBalance float64,
	backoffFactor float64,
	maxAttempts int,
	routingFeeLimitPPM int,
	minSwapSize float64,
	maxSwapSize float64,
) *AutoSwapConfig

NewAutoSwapConfigFromFlags creates a new AutoSwapConfig from CLI flags

func (*AutoSwapConfig) GetCheckInterval

func (c *AutoSwapConfig) GetCheckInterval() time.Duration

GetCheckInterval returns the check interval as a time.Duration

func (*AutoSwapConfig) IsEnabled

func (c *AutoSwapConfig) IsEnabled() bool

IsEnabled returns whether auto swap is enabled

func (*AutoSwapConfig) Validate

func (c *AutoSwapConfig) Validate() error

Validate checks if the configuration is valid

type AutoSwapService

type AutoSwapService struct {
	// contains filtered or unexported fields
}

AutoSwapService handles the auto swap functionality

func NewAutoSwapService

func NewAutoSwapService(
	client swaps.ClientInterface,
	rpcClient rpc.SwapServiceClient,
	lightningClient lightning.Client,
	repository Repository,
	config *AutoSwapConfig,
) *AutoSwapService

NewAutoSwapService creates a new AutoSwapService with dependencies for reusing existing logic

func (*AutoSwapService) GetCheckInterval

func (s *AutoSwapService) GetCheckInterval() time.Duration

GetCheckInterval returns the auto swap check interval

func (*AutoSwapService) RecoverPendingAutoSwaps

func (s *AutoSwapService) RecoverPendingAutoSwaps(ctx context.Context) error

RecoverPendingAutoSwaps recovers auto swaps that were running before daemon restart

func (*AutoSwapService) RunAutoSwapCheck

func (s *AutoSwapService) RunAutoSwapCheck(ctx context.Context) error

RunAutoSwapCheck performs the auto swap check logic using existing components

type PSBTBuilder

type PSBTBuilder struct {
	// contains filtered or unexported fields
}

PSBTBuilder contains methods for building PSBTs locally for both refund and claim transactions

func NewPSBTBuilder

func NewPSBTBuilder(bitcoinClient bitcoin.Client, network lightning.Network) *PSBTBuilder

NewPSBTBuilder creates a new PSBT builder instance

func (*PSBTBuilder) BuildClaimPSBT

func (p *PSBTBuilder) BuildClaimPSBT(ctx context.Context, swap *models.SwapOut, swapInfo *swaps.SwapOutResponse, feeRate int64, logger *log.Entry) (*psbt.Packet, error)

BuildClaimPSBT builds a claim PSBT locally for swap out transactions

func (*PSBTBuilder) BuildRefundPSBT

func (p *PSBTBuilder) BuildRefundPSBT(ctx context.Context, swap *models.SwapIn, feeRate int64, logger *log.Entry) (*psbt.Packet, error)

BuildRefundPSBT builds a refund PSBT locally for swap in transactions

func (*PSBTBuilder) SignAndBroadcastPSBT

func (p *PSBTBuilder) SignAndBroadcastPSBT(ctx context.Context, pkt *psbt.Packet, privateKey string, preimage *lntypes.Preimage, logger *log.Entry) (string, error)

SignAndBroadcastPSBT signs a PSBT and broadcasts it to the Bitcoin network

type Repository

type Repository interface {
	database.SwapInRepository
	database.SwapOutRepository
}

type SwapMonitor

type SwapMonitor struct {
	// contains filtered or unexported fields
}

func (*SwapMonitor) ClaimSwapOut

func (m *SwapMonitor) ClaimSwapOut(ctx context.Context, swap *models.SwapOut) (string, error)

func (*SwapMonitor) GetFeesSwapOut

func (m *SwapMonitor) GetFeesSwapOut(ctx context.Context, swap *models.SwapOut) (int64, int64, error)

func (*SwapMonitor) InitiateRefund

func (m *SwapMonitor) InitiateRefund(ctx context.Context, swap *models.SwapIn) (string, error)

func (*SwapMonitor) MonitorSwapIn

func (m *SwapMonitor) MonitorSwapIn(ctx context.Context, currentSwap *models.SwapIn) error

func (*SwapMonitor) MonitorSwapOut

func (m *SwapMonitor) MonitorSwapOut(ctx context.Context, currentSwap *models.SwapOut) error

func (*SwapMonitor) MonitorSwaps

func (m *SwapMonitor) MonitorSwaps(ctx context.Context)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL