2023-05-30 07:37:48 -07:00
|
|
|
// Code generated by sqlc. DO NOT EDIT.
|
|
|
|
// versions:
|
2023-09-22 12:30:15 -07:00
|
|
|
// sqlc v1.25.0
|
2023-05-30 07:37:48 -07:00
|
|
|
// source: invoices.sql
|
|
|
|
|
|
|
|
package sqlc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"database/sql"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2023-11-22 17:23:23 +01:00
|
|
|
const deleteCanceledInvoices = `-- name: DeleteCanceledInvoices :execresult
|
|
|
|
DELETE
|
|
|
|
FROM invoices
|
|
|
|
WHERE state = 2
|
|
|
|
`
|
|
|
|
|
|
|
|
func (q *Queries) DeleteCanceledInvoices(ctx context.Context) (sql.Result, error) {
|
|
|
|
return q.db.ExecContext(ctx, deleteCanceledInvoices)
|
|
|
|
}
|
|
|
|
|
|
|
|
const deleteInvoice = `-- name: DeleteInvoice :execresult
|
2023-05-30 07:37:48 -07:00
|
|
|
DELETE
|
|
|
|
FROM invoices
|
|
|
|
WHERE (
|
|
|
|
id = $1 OR
|
|
|
|
$1 IS NULL
|
|
|
|
) AND (
|
|
|
|
hash = $2 OR
|
|
|
|
$2 IS NULL
|
|
|
|
) AND (
|
2023-11-22 17:23:23 +01:00
|
|
|
settle_index = $3 OR
|
2023-05-30 07:37:48 -07:00
|
|
|
$3 IS NULL
|
|
|
|
) AND (
|
|
|
|
payment_addr = $4 OR
|
|
|
|
$4 IS NULL
|
|
|
|
)
|
|
|
|
`
|
|
|
|
|
|
|
|
type DeleteInvoiceParams struct {
|
2023-11-22 17:23:23 +01:00
|
|
|
AddIndex sql.NullInt64
|
2023-05-30 07:37:48 -07:00
|
|
|
Hash []byte
|
2023-11-22 17:23:23 +01:00
|
|
|
SettleIndex sql.NullInt64
|
2023-05-30 07:37:48 -07:00
|
|
|
PaymentAddr []byte
|
|
|
|
}
|
|
|
|
|
2023-11-22 17:23:23 +01:00
|
|
|
func (q *Queries) DeleteInvoice(ctx context.Context, arg DeleteInvoiceParams) (sql.Result, error) {
|
|
|
|
return q.db.ExecContext(ctx, deleteInvoice,
|
2023-05-30 07:37:48 -07:00
|
|
|
arg.AddIndex,
|
|
|
|
arg.Hash,
|
2023-11-22 17:23:23 +01:00
|
|
|
arg.SettleIndex,
|
2023-05-30 07:37:48 -07:00
|
|
|
arg.PaymentAddr,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
const filterInvoices = `-- name: FilterInvoices :many
|
2023-11-22 17:23:23 +01:00
|
|
|
SELECT
|
|
|
|
invoices.id, invoices.hash, invoices.preimage, invoices.settle_index, invoices.settled_at, invoices.memo, invoices.amount_msat, invoices.cltv_delta, invoices.expiry, invoices.payment_addr, invoices.payment_request, invoices.payment_request_hash, invoices.state, invoices.amount_paid_msat, invoices.is_amp, invoices.is_hodl, invoices.is_keysend, invoices.created_at
|
2023-05-30 07:37:48 -07:00
|
|
|
FROM invoices
|
|
|
|
WHERE (
|
|
|
|
id >= $1 OR
|
|
|
|
$1 IS NULL
|
|
|
|
) AND (
|
|
|
|
id <= $2 OR
|
|
|
|
$2 IS NULL
|
|
|
|
) AND (
|
2023-11-22 17:23:23 +01:00
|
|
|
settle_index >= $3 OR
|
2023-05-30 07:37:48 -07:00
|
|
|
$3 IS NULL
|
|
|
|
) AND (
|
2023-11-22 17:23:23 +01:00
|
|
|
settle_index <= $4 OR
|
2023-05-30 07:37:48 -07:00
|
|
|
$4 IS NULL
|
|
|
|
) AND (
|
2023-11-22 17:23:23 +01:00
|
|
|
state = $5 OR
|
2023-05-30 07:37:48 -07:00
|
|
|
$5 IS NULL
|
2023-11-22 17:23:23 +01:00
|
|
|
) AND (
|
|
|
|
created_at >= $6 OR
|
|
|
|
$6 IS NULL
|
|
|
|
) AND (
|
|
|
|
created_at <= $7 OR
|
|
|
|
$7 IS NULL
|
2023-05-30 07:37:48 -07:00
|
|
|
) AND (
|
|
|
|
CASE
|
2024-04-03 16:21:12 +02:00
|
|
|
WHEN $8 = TRUE THEN (state = 0 OR state = 3)
|
2023-05-30 07:37:48 -07:00
|
|
|
ELSE TRUE
|
|
|
|
END
|
|
|
|
)
|
|
|
|
ORDER BY
|
2024-04-03 16:21:12 +02:00
|
|
|
CASE
|
|
|
|
WHEN $9 = FALSE OR $9 IS NULL THEN id
|
|
|
|
ELSE NULL
|
2023-05-30 07:37:48 -07:00
|
|
|
END ASC,
|
2024-04-03 16:21:12 +02:00
|
|
|
CASE
|
|
|
|
WHEN $9 = TRUE THEN id
|
|
|
|
ELSE NULL
|
|
|
|
END DESC
|
2023-11-22 17:23:23 +01:00
|
|
|
LIMIT $11 OFFSET $10
|
2023-05-30 07:37:48 -07:00
|
|
|
`
|
|
|
|
|
|
|
|
type FilterInvoicesParams struct {
|
2023-11-22 17:23:23 +01:00
|
|
|
AddIndexGet sql.NullInt64
|
|
|
|
AddIndexLet sql.NullInt64
|
|
|
|
SettleIndexGet sql.NullInt64
|
|
|
|
SettleIndexLet sql.NullInt64
|
|
|
|
State sql.NullInt16
|
|
|
|
CreatedAfter sql.NullTime
|
|
|
|
CreatedBefore sql.NullTime
|
|
|
|
PendingOnly interface{}
|
|
|
|
Reverse interface{}
|
|
|
|
NumOffset int32
|
|
|
|
NumLimit int32
|
2023-05-30 07:37:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) FilterInvoices(ctx context.Context, arg FilterInvoicesParams) ([]Invoice, error) {
|
|
|
|
rows, err := q.db.QueryContext(ctx, filterInvoices,
|
|
|
|
arg.AddIndexGet,
|
|
|
|
arg.AddIndexLet,
|
2023-11-22 17:23:23 +01:00
|
|
|
arg.SettleIndexGet,
|
|
|
|
arg.SettleIndexLet,
|
2023-05-30 07:37:48 -07:00
|
|
|
arg.State,
|
|
|
|
arg.CreatedAfter,
|
|
|
|
arg.CreatedBefore,
|
|
|
|
arg.PendingOnly,
|
|
|
|
arg.Reverse,
|
|
|
|
arg.NumOffset,
|
|
|
|
arg.NumLimit,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
var items []Invoice
|
|
|
|
for rows.Next() {
|
|
|
|
var i Invoice
|
|
|
|
if err := rows.Scan(
|
|
|
|
&i.ID,
|
|
|
|
&i.Hash,
|
|
|
|
&i.Preimage,
|
2023-11-22 17:23:23 +01:00
|
|
|
&i.SettleIndex,
|
|
|
|
&i.SettledAt,
|
2023-05-30 07:37:48 -07:00
|
|
|
&i.Memo,
|
|
|
|
&i.AmountMsat,
|
|
|
|
&i.CltvDelta,
|
|
|
|
&i.Expiry,
|
|
|
|
&i.PaymentAddr,
|
|
|
|
&i.PaymentRequest,
|
2023-11-22 17:23:23 +01:00
|
|
|
&i.PaymentRequestHash,
|
2023-05-30 07:37:48 -07:00
|
|
|
&i.State,
|
|
|
|
&i.AmountPaidMsat,
|
|
|
|
&i.IsAmp,
|
|
|
|
&i.IsHodl,
|
|
|
|
&i.IsKeysend,
|
|
|
|
&i.CreatedAt,
|
|
|
|
); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
items = append(items, i)
|
|
|
|
}
|
|
|
|
if err := rows.Close(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if err := rows.Err(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return items, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
const getInvoice = `-- name: GetInvoice :many
|
|
|
|
|
2023-11-22 17:23:23 +01:00
|
|
|
SELECT i.id, i.hash, i.preimage, i.settle_index, i.settled_at, i.memo, i.amount_msat, i.cltv_delta, i.expiry, i.payment_addr, i.payment_request, i.payment_request_hash, i.state, i.amount_paid_msat, i.is_amp, i.is_hodl, i.is_keysend, i.created_at
|
|
|
|
FROM invoices i
|
|
|
|
LEFT JOIN amp_sub_invoices a on i.id = a.invoice_id
|
2023-05-30 07:37:48 -07:00
|
|
|
WHERE (
|
2023-11-22 17:23:23 +01:00
|
|
|
i.id = $1 OR
|
2023-05-30 07:37:48 -07:00
|
|
|
$1 IS NULL
|
|
|
|
) AND (
|
2023-11-22 17:23:23 +01:00
|
|
|
i.hash = $2 OR
|
2023-05-30 07:37:48 -07:00
|
|
|
$2 IS NULL
|
|
|
|
) AND (
|
2023-11-22 17:23:23 +01:00
|
|
|
i.preimage = $3 OR
|
2023-05-30 07:37:48 -07:00
|
|
|
$3 IS NULL
|
|
|
|
) AND (
|
2023-11-22 17:23:23 +01:00
|
|
|
i.payment_addr = $4 OR
|
2023-05-30 07:37:48 -07:00
|
|
|
$4 IS NULL
|
2023-11-22 17:23:23 +01:00
|
|
|
) AND (
|
|
|
|
a.set_id = $5 OR
|
|
|
|
$5 IS NULL
|
2023-05-30 07:37:48 -07:00
|
|
|
)
|
2023-11-22 17:23:23 +01:00
|
|
|
GROUP BY i.id
|
2023-05-30 07:37:48 -07:00
|
|
|
LIMIT 2
|
|
|
|
`
|
|
|
|
|
|
|
|
type GetInvoiceParams struct {
|
2023-11-22 17:23:23 +01:00
|
|
|
AddIndex sql.NullInt64
|
2023-05-30 07:37:48 -07:00
|
|
|
Hash []byte
|
|
|
|
Preimage []byte
|
|
|
|
PaymentAddr []byte
|
2023-11-22 17:23:23 +01:00
|
|
|
SetID []byte
|
2023-05-30 07:37:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// This method may return more than one invoice if filter using multiple fields
|
|
|
|
// from different invoices. It is the caller's responsibility to ensure that
|
|
|
|
// we bubble up an error in those cases.
|
|
|
|
func (q *Queries) GetInvoice(ctx context.Context, arg GetInvoiceParams) ([]Invoice, error) {
|
|
|
|
rows, err := q.db.QueryContext(ctx, getInvoice,
|
|
|
|
arg.AddIndex,
|
|
|
|
arg.Hash,
|
|
|
|
arg.Preimage,
|
|
|
|
arg.PaymentAddr,
|
2023-11-22 17:23:23 +01:00
|
|
|
arg.SetID,
|
2023-05-30 07:37:48 -07:00
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
var items []Invoice
|
|
|
|
for rows.Next() {
|
|
|
|
var i Invoice
|
|
|
|
if err := rows.Scan(
|
|
|
|
&i.ID,
|
|
|
|
&i.Hash,
|
|
|
|
&i.Preimage,
|
2023-11-22 17:23:23 +01:00
|
|
|
&i.SettleIndex,
|
|
|
|
&i.SettledAt,
|
2023-05-30 07:37:48 -07:00
|
|
|
&i.Memo,
|
|
|
|
&i.AmountMsat,
|
|
|
|
&i.CltvDelta,
|
|
|
|
&i.Expiry,
|
|
|
|
&i.PaymentAddr,
|
|
|
|
&i.PaymentRequest,
|
2023-11-22 17:23:23 +01:00
|
|
|
&i.PaymentRequestHash,
|
2023-05-30 07:37:48 -07:00
|
|
|
&i.State,
|
|
|
|
&i.AmountPaidMsat,
|
|
|
|
&i.IsAmp,
|
|
|
|
&i.IsHodl,
|
|
|
|
&i.IsKeysend,
|
|
|
|
&i.CreatedAt,
|
|
|
|
); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
items = append(items, i)
|
|
|
|
}
|
|
|
|
if err := rows.Close(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if err := rows.Err(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return items, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
const getInvoiceFeatures = `-- name: GetInvoiceFeatures :many
|
|
|
|
SELECT feature, invoice_id
|
|
|
|
FROM invoice_features
|
|
|
|
WHERE invoice_id = $1
|
|
|
|
`
|
|
|
|
|
2023-11-22 17:23:23 +01:00
|
|
|
func (q *Queries) GetInvoiceFeatures(ctx context.Context, invoiceID int64) ([]InvoiceFeature, error) {
|
2023-05-30 07:37:48 -07:00
|
|
|
rows, err := q.db.QueryContext(ctx, getInvoiceFeatures, invoiceID)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
var items []InvoiceFeature
|
|
|
|
for rows.Next() {
|
|
|
|
var i InvoiceFeature
|
|
|
|
if err := rows.Scan(&i.Feature, &i.InvoiceID); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
items = append(items, i)
|
|
|
|
}
|
|
|
|
if err := rows.Close(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if err := rows.Err(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return items, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
const getInvoiceHTLCCustomRecords = `-- name: GetInvoiceHTLCCustomRecords :many
|
|
|
|
SELECT ihcr.htlc_id, key, value
|
|
|
|
FROM invoice_htlcs ih JOIN invoice_htlc_custom_records ihcr ON ih.id=ihcr.htlc_id
|
|
|
|
WHERE ih.invoice_id = $1
|
|
|
|
`
|
|
|
|
|
|
|
|
type GetInvoiceHTLCCustomRecordsRow struct {
|
|
|
|
HtlcID int64
|
|
|
|
Key int64
|
|
|
|
Value []byte
|
|
|
|
}
|
|
|
|
|
2023-11-22 17:23:23 +01:00
|
|
|
func (q *Queries) GetInvoiceHTLCCustomRecords(ctx context.Context, invoiceID int64) ([]GetInvoiceHTLCCustomRecordsRow, error) {
|
2023-05-30 07:37:48 -07:00
|
|
|
rows, err := q.db.QueryContext(ctx, getInvoiceHTLCCustomRecords, invoiceID)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
var items []GetInvoiceHTLCCustomRecordsRow
|
|
|
|
for rows.Next() {
|
|
|
|
var i GetInvoiceHTLCCustomRecordsRow
|
|
|
|
if err := rows.Scan(&i.HtlcID, &i.Key, &i.Value); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
items = append(items, i)
|
|
|
|
}
|
|
|
|
if err := rows.Close(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if err := rows.Err(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return items, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
const getInvoiceHTLCs = `-- name: GetInvoiceHTLCs :many
|
2023-11-22 17:23:23 +01:00
|
|
|
SELECT id, chan_id, htlc_id, amount_msat, total_mpp_msat, accept_height, accept_time, expiry_height, state, resolve_time, invoice_id
|
2023-05-30 07:37:48 -07:00
|
|
|
FROM invoice_htlcs
|
|
|
|
WHERE invoice_id = $1
|
|
|
|
`
|
|
|
|
|
2023-11-22 17:23:23 +01:00
|
|
|
func (q *Queries) GetInvoiceHTLCs(ctx context.Context, invoiceID int64) ([]InvoiceHtlc, error) {
|
2023-05-30 07:37:48 -07:00
|
|
|
rows, err := q.db.QueryContext(ctx, getInvoiceHTLCs, invoiceID)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
var items []InvoiceHtlc
|
|
|
|
for rows.Next() {
|
|
|
|
var i InvoiceHtlc
|
|
|
|
if err := rows.Scan(
|
|
|
|
&i.ID,
|
|
|
|
&i.ChanID,
|
2023-11-22 17:23:23 +01:00
|
|
|
&i.HtlcID,
|
2023-05-30 07:37:48 -07:00
|
|
|
&i.AmountMsat,
|
|
|
|
&i.TotalMppMsat,
|
|
|
|
&i.AcceptHeight,
|
|
|
|
&i.AcceptTime,
|
|
|
|
&i.ExpiryHeight,
|
|
|
|
&i.State,
|
|
|
|
&i.ResolveTime,
|
|
|
|
&i.InvoiceID,
|
|
|
|
); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
items = append(items, i)
|
|
|
|
}
|
|
|
|
if err := rows.Close(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if err := rows.Err(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return items, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
const insertInvoice = `-- name: InsertInvoice :one
|
|
|
|
INSERT INTO invoices (
|
|
|
|
hash, preimage, memo, amount_msat, cltv_delta, expiry, payment_addr,
|
2023-11-22 17:23:23 +01:00
|
|
|
payment_request, payment_request_hash, state, amount_paid_msat, is_amp,
|
|
|
|
is_hodl, is_keysend, created_at
|
2023-05-30 07:37:48 -07:00
|
|
|
) VALUES (
|
2023-11-22 17:23:23 +01:00
|
|
|
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15
|
2023-05-30 07:37:48 -07:00
|
|
|
) RETURNING id
|
|
|
|
`
|
|
|
|
|
|
|
|
type InsertInvoiceParams struct {
|
2023-11-22 17:23:23 +01:00
|
|
|
Hash []byte
|
|
|
|
Preimage []byte
|
|
|
|
Memo sql.NullString
|
|
|
|
AmountMsat int64
|
|
|
|
CltvDelta sql.NullInt32
|
|
|
|
Expiry int32
|
|
|
|
PaymentAddr []byte
|
|
|
|
PaymentRequest sql.NullString
|
|
|
|
PaymentRequestHash []byte
|
|
|
|
State int16
|
|
|
|
AmountPaidMsat int64
|
|
|
|
IsAmp bool
|
|
|
|
IsHodl bool
|
|
|
|
IsKeysend bool
|
|
|
|
CreatedAt time.Time
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) InsertInvoice(ctx context.Context, arg InsertInvoiceParams) (int64, error) {
|
2023-05-30 07:37:48 -07:00
|
|
|
row := q.db.QueryRowContext(ctx, insertInvoice,
|
|
|
|
arg.Hash,
|
|
|
|
arg.Preimage,
|
|
|
|
arg.Memo,
|
|
|
|
arg.AmountMsat,
|
|
|
|
arg.CltvDelta,
|
|
|
|
arg.Expiry,
|
|
|
|
arg.PaymentAddr,
|
|
|
|
arg.PaymentRequest,
|
2023-11-22 17:23:23 +01:00
|
|
|
arg.PaymentRequestHash,
|
2023-05-30 07:37:48 -07:00
|
|
|
arg.State,
|
|
|
|
arg.AmountPaidMsat,
|
|
|
|
arg.IsAmp,
|
|
|
|
arg.IsHodl,
|
|
|
|
arg.IsKeysend,
|
|
|
|
arg.CreatedAt,
|
|
|
|
)
|
2023-11-22 17:23:23 +01:00
|
|
|
var id int64
|
2023-05-30 07:37:48 -07:00
|
|
|
err := row.Scan(&id)
|
|
|
|
return id, err
|
|
|
|
}
|
|
|
|
|
|
|
|
const insertInvoiceFeature = `-- name: InsertInvoiceFeature :exec
|
|
|
|
INSERT INTO invoice_features (
|
|
|
|
invoice_id, feature
|
|
|
|
) VALUES (
|
|
|
|
$1, $2
|
|
|
|
)
|
|
|
|
`
|
|
|
|
|
|
|
|
type InsertInvoiceFeatureParams struct {
|
2023-11-22 17:23:23 +01:00
|
|
|
InvoiceID int64
|
2023-05-30 07:37:48 -07:00
|
|
|
Feature int32
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) InsertInvoiceFeature(ctx context.Context, arg InsertInvoiceFeatureParams) error {
|
|
|
|
_, err := q.db.ExecContext(ctx, insertInvoiceFeature, arg.InvoiceID, arg.Feature)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-11-22 17:23:23 +01:00
|
|
|
const insertInvoiceHTLC = `-- name: InsertInvoiceHTLC :one
|
2023-05-30 07:37:48 -07:00
|
|
|
INSERT INTO invoice_htlcs (
|
|
|
|
htlc_id, chan_id, amount_msat, total_mpp_msat, accept_height, accept_time,
|
|
|
|
expiry_height, state, resolve_time, invoice_id
|
|
|
|
) VALUES (
|
|
|
|
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10
|
2023-11-22 17:23:23 +01:00
|
|
|
) RETURNING id
|
2023-05-30 07:37:48 -07:00
|
|
|
`
|
|
|
|
|
|
|
|
type InsertInvoiceHTLCParams struct {
|
|
|
|
HtlcID int64
|
|
|
|
ChanID string
|
|
|
|
AmountMsat int64
|
|
|
|
TotalMppMsat sql.NullInt64
|
|
|
|
AcceptHeight int32
|
|
|
|
AcceptTime time.Time
|
|
|
|
ExpiryHeight int32
|
|
|
|
State int16
|
|
|
|
ResolveTime sql.NullTime
|
2023-11-22 17:23:23 +01:00
|
|
|
InvoiceID int64
|
2023-05-30 07:37:48 -07:00
|
|
|
}
|
|
|
|
|
2023-11-22 17:23:23 +01:00
|
|
|
func (q *Queries) InsertInvoiceHTLC(ctx context.Context, arg InsertInvoiceHTLCParams) (int64, error) {
|
|
|
|
row := q.db.QueryRowContext(ctx, insertInvoiceHTLC,
|
2023-05-30 07:37:48 -07:00
|
|
|
arg.HtlcID,
|
|
|
|
arg.ChanID,
|
|
|
|
arg.AmountMsat,
|
|
|
|
arg.TotalMppMsat,
|
|
|
|
arg.AcceptHeight,
|
|
|
|
arg.AcceptTime,
|
|
|
|
arg.ExpiryHeight,
|
|
|
|
arg.State,
|
|
|
|
arg.ResolveTime,
|
|
|
|
arg.InvoiceID,
|
|
|
|
)
|
2023-11-22 17:23:23 +01:00
|
|
|
var id int64
|
|
|
|
err := row.Scan(&id)
|
|
|
|
return id, err
|
2023-05-30 07:37:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
const insertInvoiceHTLCCustomRecord = `-- name: InsertInvoiceHTLCCustomRecord :exec
|
|
|
|
INSERT INTO invoice_htlc_custom_records (
|
|
|
|
key, value, htlc_id
|
|
|
|
) VALUES (
|
|
|
|
$1, $2, $3
|
|
|
|
)
|
|
|
|
`
|
|
|
|
|
|
|
|
type InsertInvoiceHTLCCustomRecordParams struct {
|
|
|
|
Key int64
|
|
|
|
Value []byte
|
|
|
|
HtlcID int64
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) InsertInvoiceHTLCCustomRecord(ctx context.Context, arg InsertInvoiceHTLCCustomRecordParams) error {
|
|
|
|
_, err := q.db.ExecContext(ctx, insertInvoiceHTLCCustomRecord, arg.Key, arg.Value, arg.HtlcID)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-11-22 17:23:23 +01:00
|
|
|
const nextInvoiceSettleIndex = `-- name: NextInvoiceSettleIndex :one
|
|
|
|
UPDATE invoice_sequences SET current_value = current_value + 1
|
|
|
|
WHERE name = 'settle_index'
|
|
|
|
RETURNING current_value
|
2023-05-30 07:37:48 -07:00
|
|
|
`
|
|
|
|
|
2023-11-22 17:23:23 +01:00
|
|
|
func (q *Queries) NextInvoiceSettleIndex(ctx context.Context) (int64, error) {
|
|
|
|
row := q.db.QueryRowContext(ctx, nextInvoiceSettleIndex)
|
|
|
|
var current_value int64
|
|
|
|
err := row.Scan(¤t_value)
|
|
|
|
return current_value, err
|
2023-05-30 07:37:48 -07:00
|
|
|
}
|
|
|
|
|
2023-11-22 17:23:23 +01:00
|
|
|
const updateInvoiceAmountPaid = `-- name: UpdateInvoiceAmountPaid :execresult
|
|
|
|
UPDATE invoices
|
|
|
|
SET amount_paid_msat = $2
|
|
|
|
WHERE id = $1
|
2023-05-30 07:37:48 -07:00
|
|
|
`
|
|
|
|
|
2023-11-22 17:23:23 +01:00
|
|
|
type UpdateInvoiceAmountPaidParams struct {
|
|
|
|
ID int64
|
2023-05-30 07:37:48 -07:00
|
|
|
AmountPaidMsat int64
|
|
|
|
}
|
|
|
|
|
2023-11-22 17:23:23 +01:00
|
|
|
func (q *Queries) UpdateInvoiceAmountPaid(ctx context.Context, arg UpdateInvoiceAmountPaidParams) (sql.Result, error) {
|
|
|
|
return q.db.ExecContext(ctx, updateInvoiceAmountPaid, arg.ID, arg.AmountPaidMsat)
|
2023-05-30 07:37:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
const updateInvoiceHTLC = `-- name: UpdateInvoiceHTLC :exec
|
|
|
|
UPDATE invoice_htlcs
|
2023-11-22 17:23:23 +01:00
|
|
|
SET state=$4, resolve_time=$5
|
|
|
|
WHERE htlc_id = $1 AND chan_id = $2 AND invoice_id = $3
|
2023-05-30 07:37:48 -07:00
|
|
|
`
|
|
|
|
|
|
|
|
type UpdateInvoiceHTLCParams struct {
|
2023-11-22 17:23:23 +01:00
|
|
|
HtlcID int64
|
|
|
|
ChanID string
|
|
|
|
InvoiceID int64
|
2023-05-30 07:37:48 -07:00
|
|
|
State int16
|
|
|
|
ResolveTime sql.NullTime
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) UpdateInvoiceHTLC(ctx context.Context, arg UpdateInvoiceHTLCParams) error {
|
2023-11-22 17:23:23 +01:00
|
|
|
_, err := q.db.ExecContext(ctx, updateInvoiceHTLC,
|
|
|
|
arg.HtlcID,
|
|
|
|
arg.ChanID,
|
|
|
|
arg.InvoiceID,
|
|
|
|
arg.State,
|
|
|
|
arg.ResolveTime,
|
|
|
|
)
|
2023-05-30 07:37:48 -07:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
const updateInvoiceHTLCs = `-- name: UpdateInvoiceHTLCs :exec
|
|
|
|
UPDATE invoice_htlcs
|
|
|
|
SET state=$2, resolve_time=$3
|
|
|
|
WHERE invoice_id = $1 AND resolve_time IS NULL
|
|
|
|
`
|
|
|
|
|
|
|
|
type UpdateInvoiceHTLCsParams struct {
|
2023-11-22 17:23:23 +01:00
|
|
|
InvoiceID int64
|
2023-05-30 07:37:48 -07:00
|
|
|
State int16
|
|
|
|
ResolveTime sql.NullTime
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) UpdateInvoiceHTLCs(ctx context.Context, arg UpdateInvoiceHTLCsParams) error {
|
|
|
|
_, err := q.db.ExecContext(ctx, updateInvoiceHTLCs, arg.InvoiceID, arg.State, arg.ResolveTime)
|
|
|
|
return err
|
|
|
|
}
|
2023-11-22 17:23:23 +01:00
|
|
|
|
|
|
|
const updateInvoiceState = `-- name: UpdateInvoiceState :execresult
|
|
|
|
UPDATE invoices
|
|
|
|
SET state = $2,
|
|
|
|
preimage = COALESCE(preimage, $3),
|
|
|
|
settle_index = COALESCE(settle_index, $4),
|
|
|
|
settled_at = COALESCE(settled_at, $5)
|
|
|
|
WHERE id = $1
|
|
|
|
`
|
|
|
|
|
|
|
|
type UpdateInvoiceStateParams struct {
|
|
|
|
ID int64
|
|
|
|
State int16
|
|
|
|
Preimage []byte
|
|
|
|
SettleIndex sql.NullInt64
|
|
|
|
SettledAt sql.NullTime
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) UpdateInvoiceState(ctx context.Context, arg UpdateInvoiceStateParams) (sql.Result, error) {
|
|
|
|
return q.db.ExecContext(ctx, updateInvoiceState,
|
|
|
|
arg.ID,
|
|
|
|
arg.State,
|
|
|
|
arg.Preimage,
|
|
|
|
arg.SettleIndex,
|
|
|
|
arg.SettledAt,
|
|
|
|
)
|
|
|
|
}
|