Skip to content
Open
Changes from 1 commit
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
39 changes: 39 additions & 0 deletions payments/db/sql_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package paymentsdb

import (
"context"
"database/sql"
"errors"
"fmt"
"math"
"time"

"github.com/lightningnetwork/lnd/lntypes"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/sqldb"
"github.com/lightningnetwork/lnd/sqldb/sqlc"
Expand Down Expand Up @@ -474,3 +476,40 @@ func (s *SQLStore) QueryPayments(ctx context.Context,
TotalCount: uint64(totalCount),
}, nil
}

// FetchPayment fetches the payment corresponding to the given payment
// hash.
//
// This is part of the DB interface.
func (s *SQLStore) FetchPayment(paymentHash lntypes.Hash) (*MPPayment, error) {
ctx := context.TODO()

var mpPayment *MPPayment

err := s.db.ExecTx(ctx, sqldb.ReadTxOpt(), func(db SQLQueries) error {
dbPayment, err := db.FetchPayment(ctx, paymentHash[:])
if err != nil && !errors.Is(err, sql.ErrNoRows) {
return fmt.Errorf("failed to fetch payment: %w", err)
}

if errors.Is(err, sql.ErrNoRows) {
return ErrPaymentNotInitiated
}

mpPayment, err = s.fetchPaymentWithCompleteData(
ctx, db, dbPayment,
)
if err != nil {
return fmt.Errorf("failed to fetch payment with "+
"complete data: %w", err)
}

return nil
}, func() {
})
Comment on lines +508 to +509
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sqldb.NoOpReset

if err != nil {
return nil, fmt.Errorf("failed to fetch payment: %w", err)
}

return mpPayment, nil
}