multi: add call to directly insert an AMP sub-invoice

This commit is contained in:
Andras Banki-Horvath 2024-06-11 22:38:38 +02:00
parent 91c3e1496f
commit 115f96c29a
No known key found for this signature in database
GPG Key ID: 80E5375C094198D8
4 changed files with 42 additions and 0 deletions

View File

@ -79,6 +79,10 @@ type SQLInvoiceQueries interface { //nolint:interfacebloat
UpsertAMPSubInvoice(ctx context.Context, UpsertAMPSubInvoice(ctx context.Context,
arg sqlc.UpsertAMPSubInvoiceParams) (sql.Result, error) arg sqlc.UpsertAMPSubInvoiceParams) (sql.Result, error)
// TODO(bhandras): remove this once migrations have been separated out.
InsertAMPSubInvoice(ctx context.Context,
arg sqlc.InsertAMPSubInvoiceParams) error
UpdateAMPSubInvoiceState(ctx context.Context, UpdateAMPSubInvoiceState(ctx context.Context,
arg sqlc.UpdateAMPSubInvoiceStateParams) error arg sqlc.UpdateAMPSubInvoiceStateParams) error

View File

@ -235,6 +235,35 @@ func (q *Queries) GetAMPInvoiceID(ctx context.Context, setID []byte) (int64, err
return invoice_id, err return invoice_id, err
} }
const insertAMPSubInvoice = `-- name: InsertAMPSubInvoice :exec
INSERT INTO amp_sub_invoices (
set_id, state, created_at, settled_at, settle_index, invoice_id
) VALUES (
$1, $2, $3, $4, $5, $6
)
`
type InsertAMPSubInvoiceParams struct {
SetID []byte
State int16
CreatedAt time.Time
SettledAt sql.NullTime
SettleIndex sql.NullInt64
InvoiceID int64
}
func (q *Queries) InsertAMPSubInvoice(ctx context.Context, arg InsertAMPSubInvoiceParams) error {
_, err := q.db.ExecContext(ctx, insertAMPSubInvoice,
arg.SetID,
arg.State,
arg.CreatedAt,
arg.SettledAt,
arg.SettleIndex,
arg.InvoiceID,
)
return err
}
const insertAMPSubInvoiceHTLC = `-- name: InsertAMPSubInvoiceHTLC :exec const insertAMPSubInvoiceHTLC = `-- name: InsertAMPSubInvoiceHTLC :exec
INSERT INTO amp_sub_invoice_htlcs ( INSERT INTO amp_sub_invoice_htlcs (
invoice_id, set_id, htlc_id, root_share, child_index, hash, preimage invoice_id, set_id, htlc_id, root_share, child_index, hash, preimage

View File

@ -28,6 +28,7 @@ type Querier interface {
GetInvoiceHTLCCustomRecords(ctx context.Context, invoiceID int64) ([]GetInvoiceHTLCCustomRecordsRow, error) GetInvoiceHTLCCustomRecords(ctx context.Context, invoiceID int64) ([]GetInvoiceHTLCCustomRecordsRow, error)
GetInvoiceHTLCs(ctx context.Context, invoiceID int64) ([]InvoiceHtlc, error) GetInvoiceHTLCs(ctx context.Context, invoiceID int64) ([]InvoiceHtlc, error)
GetMigration(ctx context.Context, version int32) (time.Time, error) GetMigration(ctx context.Context, version int32) (time.Time, error)
InsertAMPSubInvoice(ctx context.Context, arg InsertAMPSubInvoiceParams) error
InsertAMPSubInvoiceHTLC(ctx context.Context, arg InsertAMPSubInvoiceHTLCParams) error InsertAMPSubInvoiceHTLC(ctx context.Context, arg InsertAMPSubInvoiceHTLCParams) error
InsertInvoice(ctx context.Context, arg InsertInvoiceParams) (int64, error) InsertInvoice(ctx context.Context, arg InsertInvoiceParams) (int64, error)
InsertInvoiceFeature(ctx context.Context, arg InsertInvoiceFeatureParams) error InsertInvoiceFeature(ctx context.Context, arg InsertInvoiceFeatureParams) error

View File

@ -65,3 +65,11 @@ SET preimage = $5
WHERE a.invoice_id = $1 AND a.set_id = $2 AND a.htlc_id = ( WHERE a.invoice_id = $1 AND a.set_id = $2 AND a.htlc_id = (
SELECT id FROM invoice_htlcs AS i WHERE i.chan_id = $3 AND i.htlc_id = $4 SELECT id FROM invoice_htlcs AS i WHERE i.chan_id = $3 AND i.htlc_id = $4
); );
-- name: InsertAMPSubInvoice :exec
INSERT INTO amp_sub_invoices (
set_id, state, created_at, settled_at, settle_index, invoice_id
) VALUES (
$1, $2, $3, $4, $5, $6
);