-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: confirm invoice function ambiguous unit variable (#221)
* 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
- Loading branch information
Showing
16 changed files
with
225 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
migrations/20230220_002700_fix_unit_confirm_invoice_func.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
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; | ||
$$;`) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.