@@ -2,11 +2,13 @@ package paymentsdb
22
33import (
44 "context"
5+ "database/sql"
56 "errors"
67 "fmt"
78 "math"
89 "time"
910
11+ "github.com/lightningnetwork/lnd/lntypes"
1012 "github.com/lightningnetwork/lnd/lnwire"
1113 "github.com/lightningnetwork/lnd/sqldb"
1214 "github.com/lightningnetwork/lnd/sqldb/sqlc"
@@ -652,3 +654,39 @@ func (s *SQLStore) QueryPayments(ctx context.Context, query Query) (Response,
652654 TotalCount : uint64 (totalCount ),
653655 }, nil
654656}
657+
658+ // FetchPayment fetches the payment corresponding to the given payment
659+ // hash.
660+ //
661+ // This is part of the DB interface.
662+ func (s * SQLStore ) FetchPayment (paymentHash lntypes.Hash ) (* MPPayment , error ) {
663+ ctx := context .TODO ()
664+
665+ var mpPayment * MPPayment
666+
667+ err := s .db .ExecTx (ctx , sqldb .ReadTxOpt (), func (db SQLQueries ) error {
668+ dbPayment , err := db .FetchPayment (ctx , paymentHash [:])
669+ if err != nil && ! errors .Is (err , sql .ErrNoRows ) {
670+ return fmt .Errorf ("failed to fetch payment: %w" , err )
671+ }
672+
673+ if errors .Is (err , sql .ErrNoRows ) {
674+ return ErrPaymentNotInitiated
675+ }
676+
677+ mpPayment , err = s .fetchPaymentWithCompleteData (
678+ ctx , db , dbPayment ,
679+ )
680+ if err != nil {
681+ return fmt .Errorf ("failed to fetch payment with " +
682+ "complete data: %w" , err )
683+ }
684+
685+ return nil
686+ }, sqldb .NoOpReset )
687+ if err != nil {
688+ return nil , err
689+ }
690+
691+ return mpPayment , nil
692+ }
0 commit comments