mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-02-23 22:46:40 +01:00
sqldb: set settled_at and settle_index on invocie insertion is set
Previously we intentially did not set settled_at and settle_index when inserting a new invoice as those fields are set when we settle an invoice through the usual invoice update. As migration requires that we set these nullable fields, we can safely add them.
This commit is contained in:
parent
115f96c29a
commit
3820497d7f
3 changed files with 66 additions and 0 deletions
|
@ -533,6 +533,61 @@ func (q *Queries) InsertInvoiceHTLCCustomRecord(ctx context.Context, arg InsertI
|
|||
return err
|
||||
}
|
||||
|
||||
const insertMigratedInvoice = `-- name: InsertMigratedInvoice :one
|
||||
INSERT INTO invoices (
|
||||
hash, preimage, settle_index, settled_at, memo, amount_msat, cltv_delta,
|
||||
expiry, payment_addr, payment_request, payment_request_hash, state,
|
||||
amount_paid_msat, is_amp, is_hodl, is_keysend, created_at
|
||||
) VALUES (
|
||||
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17
|
||||
) RETURNING id
|
||||
`
|
||||
|
||||
type InsertMigratedInvoiceParams struct {
|
||||
Hash []byte
|
||||
Preimage []byte
|
||||
SettleIndex sql.NullInt64
|
||||
SettledAt sql.NullTime
|
||||
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) InsertMigratedInvoice(ctx context.Context, arg InsertMigratedInvoiceParams) (int64, error) {
|
||||
row := q.db.QueryRowContext(ctx, insertMigratedInvoice,
|
||||
arg.Hash,
|
||||
arg.Preimage,
|
||||
arg.SettleIndex,
|
||||
arg.SettledAt,
|
||||
arg.Memo,
|
||||
arg.AmountMsat,
|
||||
arg.CltvDelta,
|
||||
arg.Expiry,
|
||||
arg.PaymentAddr,
|
||||
arg.PaymentRequest,
|
||||
arg.PaymentRequestHash,
|
||||
arg.State,
|
||||
arg.AmountPaidMsat,
|
||||
arg.IsAmp,
|
||||
arg.IsHodl,
|
||||
arg.IsKeysend,
|
||||
arg.CreatedAt,
|
||||
)
|
||||
var id int64
|
||||
err := row.Scan(&id)
|
||||
return id, err
|
||||
}
|
||||
|
||||
const nextInvoiceSettleIndex = `-- name: NextInvoiceSettleIndex :one
|
||||
UPDATE invoice_sequences SET current_value = current_value + 1
|
||||
WHERE name = 'settle_index'
|
||||
|
|
|
@ -34,6 +34,7 @@ type Querier interface {
|
|||
InsertInvoiceFeature(ctx context.Context, arg InsertInvoiceFeatureParams) error
|
||||
InsertInvoiceHTLC(ctx context.Context, arg InsertInvoiceHTLCParams) (int64, error)
|
||||
InsertInvoiceHTLCCustomRecord(ctx context.Context, arg InsertInvoiceHTLCCustomRecordParams) error
|
||||
InsertMigratedInvoice(ctx context.Context, arg InsertMigratedInvoiceParams) (int64, error)
|
||||
NextInvoiceSettleIndex(ctx context.Context) (int64, error)
|
||||
OnAMPSubInvoiceCanceled(ctx context.Context, arg OnAMPSubInvoiceCanceledParams) error
|
||||
OnAMPSubInvoiceCreated(ctx context.Context, arg OnAMPSubInvoiceCreatedParams) error
|
||||
|
|
|
@ -7,6 +7,16 @@ INSERT INTO invoices (
|
|||
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15
|
||||
) RETURNING id;
|
||||
|
||||
-- name: InsertMigratedInvoice :one
|
||||
INSERT INTO invoices (
|
||||
hash, preimage, settle_index, settled_at, memo, amount_msat, cltv_delta,
|
||||
expiry, payment_addr, payment_request, payment_request_hash, state,
|
||||
amount_paid_msat, is_amp, is_hodl, is_keysend, created_at
|
||||
) VALUES (
|
||||
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17
|
||||
) RETURNING id;
|
||||
|
||||
|
||||
-- name: InsertInvoiceFeature :exec
|
||||
INSERT INTO invoice_features (
|
||||
invoice_id, feature
|
||||
|
|
Loading…
Add table
Reference in a new issue