paymentsdb: add query to only fetch resolution type for HTLCs
This commit is contained in:
4 files changed
+45
No files matched your search
@@ -49,6 +49,7 @@ type SQLQueries interface {
|
||||
CountPayments(ctx context.Context) (int64, error)
|
||||
|
||||
FetchHtlcAttemptsForPayments(ctx context.Context, paymentIDs []int64) ([]sqlc.FetchHtlcAttemptsForPaymentsRow, error)
|
||||
FetchHtlcAttemptResolutionsForPayment(ctx context.Context, paymentID int64) ([]sql.NullInt32, error)
|
||||
FetchAllInflightAttempts(ctx context.Context) ([]sqlc.PaymentHtlcAttempt, error)
|
||||
FetchHopsForAttempts(ctx context.Context, htlcAttemptIndices []int64) ([]sqlc.FetchHopsForAttemptsRow, error)
|
||||
|
||||
|
||||
@@ -242,6 +242,39 @@ func (q *Queries) FetchHopsForAttempts(ctx context.Context, htlcAttemptIndices [
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const fetchHtlcAttemptResolutionsForPayment = `-- name: FetchHtlcAttemptResolutionsForPayment :many
|
||||
SELECT
|
||||
hr.resolution_type
|
||||
FROM payment_htlc_attempts ha
|
||||
LEFT JOIN payment_htlc_attempt_resolutions hr ON hr.attempt_index = ha.attempt_index
|
||||
WHERE ha.payment_id = $1
|
||||
ORDER BY ha.attempt_time ASC
|
||||
`
|
||||
|
||||
// Lightweight query to fetch only HTLC resolution status.
|
||||
func (q *Queries) FetchHtlcAttemptResolutionsForPayment(ctx context.Context, paymentID int64) ([]sql.NullInt32, error) {
|
||||
rows, err := q.db.QueryContext(ctx, fetchHtlcAttemptResolutionsForPayment, paymentID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []sql.NullInt32
|
||||
for rows.Next() {
|
||||
var resolution_type sql.NullInt32
|
||||
if err := rows.Scan(&resolution_type); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, resolution_type)
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const fetchHtlcAttemptsForPayments = `-- name: FetchHtlcAttemptsForPayments :many
|
||||
SELECT
|
||||
ha.id,
|
||||
|
||||
@@ -38,6 +38,8 @@ type Querier interface {
|
||||
FetchAllInflightAttempts(ctx context.Context) ([]PaymentHtlcAttempt, error)
|
||||
FetchHopLevelCustomRecords(ctx context.Context, hopIds []int64) ([]PaymentHopCustomRecord, error)
|
||||
FetchHopsForAttempts(ctx context.Context, htlcAttemptIndices []int64) ([]FetchHopsForAttemptsRow, error)
|
||||
// Lightweight query to fetch only HTLC resolution status.
|
||||
FetchHtlcAttemptResolutionsForPayment(ctx context.Context, paymentID int64) ([]sql.NullInt32, error)
|
||||
FetchHtlcAttemptsForPayments(ctx context.Context, paymentIds []int64) ([]FetchHtlcAttemptsForPaymentsRow, error)
|
||||
FetchPayment(ctx context.Context, paymentIdentifier []byte) (FetchPaymentRow, error)
|
||||
FetchPaymentLevelFirstHopCustomRecords(ctx context.Context, paymentIds []int64) ([]PaymentFirstHopCustomRecord, error)
|
||||
|
||||
@@ -75,6 +75,15 @@ LEFT JOIN payment_htlc_attempt_resolutions hr ON hr.attempt_index = ha.attempt_i
|
||||
WHERE ha.payment_id IN (sqlc.slice('payment_ids')/*SLICE:payment_ids*/)
|
||||
ORDER BY ha.payment_id ASC, ha.attempt_time ASC;
|
||||
|
||||
-- name: FetchHtlcAttemptResolutionsForPayment :many
|
||||
-- Lightweight query to fetch only HTLC resolution status.
|
||||
SELECT
|
||||
hr.resolution_type
|
||||
FROM payment_htlc_attempts ha
|
||||
LEFT JOIN payment_htlc_attempt_resolutions hr ON hr.attempt_index = ha.attempt_index
|
||||
WHERE ha.payment_id = $1
|
||||
ORDER BY ha.attempt_time ASC;
|
||||
|
||||
-- name: FetchAllInflightAttempts :many
|
||||
-- Fetch all inflight attempts across all payments
|
||||
SELECT
|
||||
|
||||
Reference in new issue
Block a user