mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-13 12:33:03 +02:00
staticaddr: ignoreUnknown flag for DepositsForOutpoints
This commit is contained in:
parent
7c41ec579a
commit
55081cd8fe
6 changed files with 32 additions and 8 deletions
|
|
@ -1629,7 +1629,10 @@ func (s *swapClientServer) ListUnspentDeposits(ctx context.Context,
|
|||
}
|
||||
|
||||
// Check the spent status of the deposits by looking at their states.
|
||||
deposits, err := s.depositManager.DepositsForOutpoints(ctx, outpoints)
|
||||
ignoreUnknownOutpoints := false
|
||||
deposits, err := s.depositManager.DepositsForOutpoints(
|
||||
ctx, outpoints, ignoreUnknownOutpoints,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package deposit
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sort"
|
||||
"sync"
|
||||
|
|
@ -566,7 +567,7 @@ func (m *Manager) toActiveDeposits(outpoints *[]wire.OutPoint) ([]*FSM,
|
|||
// DepositsForOutpoints returns all deposits that are behind the given
|
||||
// outpoints.
|
||||
func (m *Manager) DepositsForOutpoints(ctx context.Context,
|
||||
outpoints []string) ([]*Deposit, error) {
|
||||
outpoints []string, ignoreUnknown bool) ([]*Deposit, error) {
|
||||
|
||||
// Check for duplicates.
|
||||
existingOutpoints := make(map[string]struct{}, len(outpoints))
|
||||
|
|
@ -587,6 +588,9 @@ func (m *Manager) DepositsForOutpoints(ctx context.Context,
|
|||
|
||||
deposit, err := m.cfg.Store.DepositForOutpoint(ctx, op.String())
|
||||
if err != nil {
|
||||
if ignoreUnknown && errors.Is(err, ErrDepositNotFound) {
|
||||
continue
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,10 +5,12 @@ import (
|
|||
"context"
|
||||
"database/sql"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
|
||||
"github.com/btcsuite/btcd/btcutil"
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/lightninglabs/loop/fsm"
|
||||
"github.com/lightninglabs/loop/loopdb"
|
||||
"github.com/lightninglabs/loop/loopdb/sqlc"
|
||||
|
|
@ -16,6 +18,12 @@ import (
|
|||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrDepositNotFound is returned when a deposit is not found in the
|
||||
// database.
|
||||
ErrDepositNotFound = errors.New("deposit not found")
|
||||
)
|
||||
|
||||
// SqlStore is the backing store for static address deposits.
|
||||
type SqlStore struct {
|
||||
baseDB *loopdb.BaseDB
|
||||
|
|
@ -168,6 +176,12 @@ func (s *SqlStore) DepositForOutpoint(ctx context.Context,
|
|||
}
|
||||
row, err := q.DepositForOutpoint(ctx, params)
|
||||
if err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) ||
|
||||
errors.Is(err, pgx.ErrNoRows) {
|
||||
|
||||
return ErrDepositNotFound
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -50,9 +50,10 @@ type DepositManager interface {
|
|||
event fsm.EventType, expectedFinalState fsm.StateType) error
|
||||
|
||||
// DepositsForOutpoints returns all deposits that behind the given
|
||||
// outpoints.
|
||||
DepositsForOutpoints(ctx context.Context, outpoints []string) (
|
||||
[]*deposit.Deposit, error)
|
||||
// outpoints. If ignoreUnknown is false, the function returns an error
|
||||
// if any of the outpoints is not known, no error otherwise.
|
||||
DepositsForOutpoints(ctx context.Context, outpoints []string,
|
||||
ignoreUnknown bool) ([]*deposit.Deposit, error)
|
||||
|
||||
// GetActiveDepositsInState returns all active deposits in the given
|
||||
// state.
|
||||
|
|
|
|||
|
|
@ -289,8 +289,9 @@ func (m *Manager) handleLoopInSweepReq(ctx context.Context,
|
|||
return err
|
||||
}
|
||||
|
||||
ignoreUnknownOutpoints := false
|
||||
deposits, err := m.cfg.DepositManager.DepositsForOutpoints(
|
||||
ctx, loopIn.DepositOutpoints,
|
||||
ctx, loopIn.DepositOutpoints, ignoreUnknownOutpoints,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -458,8 +459,9 @@ func (m *Manager) checkChange(ctx context.Context,
|
|||
prevOuts[i] = in.PreviousOutPoint.String()
|
||||
}
|
||||
|
||||
ignoreUnknownOutpoints := true
|
||||
deposits, err := m.cfg.DepositManager.DepositsForOutpoints(
|
||||
ctx, prevOuts,
|
||||
ctx, prevOuts, ignoreUnknownOutpoints,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
|||
|
|
@ -163,7 +163,7 @@ func (m *mockDepositManager) TransitionDeposits(_ context.Context,
|
|||
}
|
||||
|
||||
func (m *mockDepositManager) DepositsForOutpoints(_ context.Context,
|
||||
outpoints []string) ([]*deposit.Deposit, error) {
|
||||
outpoints []string, ignoreUnknown bool) ([]*deposit.Deposit, error) {
|
||||
|
||||
res := make([]*deposit.Deposit, 0, len(outpoints))
|
||||
for _, op := range outpoints {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue