mirror of
https://github.com/Cameri/nostream.git
synced 2025-03-17 13:21:45 +01:00
* fix: dont crash when SECRET is not set * docs: add semisol to contributors * docs: improve readme * docs: add payment info to readme * docs: add zebedee_api_key to configuration.md * fix: confirm_invoice unit var * chore: remove unused code * chore: improve error logging for payments * chore: use instead of changeme * chore: fix typo * chore: improve get invoice status ctrl * fix: csp bug * chore: remove rate limits * chore: improve invoice page logging * chore: prevent root with start_local * chore: revert to redis 4.5.1
63 lines
2.2 KiB
JavaScript
63 lines
2.2 KiB
JavaScript
exports.up = function (knex) {
|
|
return knex.schema
|
|
.raw('DROP FUNCTION confirm_invoice(invoice_id UUID, amount_received BIGINT, confirmation_date TIMESTAMP WITHOUT TIME ZONE)')
|
|
.raw('DROP FUNCTION confirm_invoice(invoice_id TEXT, amount_received BIGINT, confirmation_date TIMESTAMP WITHOUT TIME ZONE)')
|
|
.raw(`CREATE OR REPLACE FUNCTION confirm_invoice(invoice_id TEXT, amount_received BIGINT, confirmation_date TIMESTAMP WITHOUT TIME ZONE)
|
|
RETURNS INTEGER
|
|
LANGUAGE plpgsql
|
|
AS $$
|
|
DECLARE
|
|
payee BYTEA;
|
|
confirmed_date TIMESTAMP WITHOUT TIME ZONE;
|
|
invoice_unit TEXT;
|
|
BEGIN
|
|
PERFORM ASSERT_SERIALIZED();
|
|
|
|
SELECT "pubkey", "confirmed_at", "unit" INTO payee, confirmed_date, invoice_unit FROM "invoices" WHERE id = invoice_id;
|
|
IF confirmed_date IS NULL THEN
|
|
UPDATE invoices
|
|
SET
|
|
"confirmed_at" = confirmation_date,
|
|
"amount_paid" = amount_received,
|
|
"updated_at" = now_utc()
|
|
WHERE id = invoice_id;
|
|
IF invoice_unit = 'sats' THEN
|
|
UPDATE users SET balance = balance + amount_received * 1000 WHERE "pubkey" = payee;
|
|
ELSIF invoice_unit = 'msats' THEN
|
|
UPDATE users SET balance = balance + amount_received WHERE "pubkey" = payee;
|
|
ELSIF invoice_unit = 'btc' THEN
|
|
UPDATE users SET balance = balance + amount_received * 100000000 * 1000 WHERE "pubkey" = payee;
|
|
END IF;
|
|
END IF;
|
|
RETURN 0;
|
|
END;
|
|
$$;`)
|
|
}
|
|
|
|
exports.down = function (knex) {
|
|
return knex.schema
|
|
.raw(`CREATE OR REPLACE FUNCTION confirm_invoice(invoice_id TEXT, amount_received BIGINT, confirmation_date TIMESTAMP WITHOUT TIME ZONE)
|
|
RETURNS INTEGER
|
|
LANGUAGE plpgsql
|
|
AS $$
|
|
DECLARE
|
|
payee BYTEA;
|
|
confirmed_date TIMESTAMP WITHOUT TIME ZONE;
|
|
BEGIN
|
|
PERFORM ASSERT_SERIALIZED();
|
|
|
|
SELECT "pubkey", "confirmed_at" INTO payee, confirmed_date FROM "invoices" WHERE id = invoice_id;
|
|
IF confirmed_date IS NULL THEN
|
|
UPDATE invoices
|
|
SET
|
|
"confirmed_at" = confirmation_date,
|
|
"amount_paid" = amount_received,
|
|
"updated_at" = now_utc()
|
|
WHERE id = invoice_id;
|
|
UPDATE users SET balance = balance + amount_received WHERE "pubkey" = payee;
|
|
END IF;
|
|
RETURN 0;
|
|
END;
|
|
$$;`)
|
|
}
|