-
-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LUD-18 Service Support #518
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
a41bd51
first pass of LUD-18 support
SatsAllDay ff89900
Various LUD-18 updates
SatsAllDay 9dc9ff8
Various LUD18 updates
SatsAllDay 2fbb93b
Show lud18 data in invoice notification
SatsAllDay 1382332
PayerData component for easier display of info in invoice, notificati…
SatsAllDay 10e4f59
`payerData` -> `invoicePayerData` in fact schema
SatsAllDay a2c3b62
Merge prisma migrations
SatsAllDay 6fe9a93
lint fixes
SatsAllDay 0b7f711
worker job to clear out unused lnurlp requests after 30 minutes
SatsAllDay 1a64d84
More linting
SatsAllDay f1838de
Move migration to older
SatsAllDay 1ad0505
Merge branch 'master' into lud-18
huumn a614ced
Merge branch 'master' into lud-18
huumn 3e0f031
WIP review
huumn e80cadd
Merge branch 'master' into lud-18
huumn df9173c
enhance lud-18
huumn 533850f
refine notification ui
huumn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
export default function PayerData ({ data, className, header = false }) { | ||
const supportedPayerData = ['name', 'pubkey', 'email', 'identifier'] | ||
|
||
if (!data) { | ||
return null | ||
} | ||
return ( | ||
<div className={className}> | ||
{header && <small className='fw-bold'>sender information:</small>} | ||
{Object.entries(data) | ||
// Don't display unsupported keys | ||
.filter(([key]) => supportedPayerData.includes(key)) | ||
.map(([key, value]) => { | ||
return <div key={key}><small>{value} ({key})</small></div> | ||
})} | ||
</div> | ||
) | ||
} |
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 |
---|---|---|
|
@@ -100,6 +100,7 @@ export const NOTIFICATIONS = gql` | |
id | ||
nostr | ||
comment | ||
lud18Data | ||
} | ||
} | ||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,10 @@ const corsHeaders = [ | |
value: 'GET, HEAD, OPTIONS' | ||
} | ||
] | ||
const noCacheHeader = { | ||
key: 'Cache-Control', | ||
value: 'no-cache, max-age=0, must-revalidate' | ||
} | ||
|
||
let commitHash | ||
if (isProd) { | ||
|
@@ -62,17 +66,15 @@ module.exports = withPlausibleProxy()({ | |
{ | ||
source: '/.well-known/:slug*', | ||
headers: [ | ||
...corsHeaders | ||
...corsHeaders, | ||
noCacheHeader | ||
] | ||
}, | ||
// never cache service worker | ||
// https://stackoverflow.com/questions/38843970/service-worker-javascript-update-frequency-every-24-hours/38854905#38854905 | ||
{ | ||
source: '/sw.js', | ||
headers: [{ | ||
key: 'Cache-Control', | ||
value: 'no-cache' | ||
}] | ||
headers: [noCacheHeader] | ||
}, | ||
{ | ||
source: '/api/lnauth', | ||
|
@@ -83,7 +85,8 @@ module.exports = withPlausibleProxy()({ | |
{ | ||
source: '/api/lnurlp/:slug*', | ||
headers: [ | ||
...corsHeaders | ||
...corsHeaders, | ||
noCacheHeader | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above |
||
] | ||
}, | ||
{ | ||
|
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
49 changes: 49 additions & 0 deletions
49
prisma/migrations/20230927235726_lud18_lnurlp_requests/migration.sql
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,49 @@ | ||
-- AlterTable | ||
ALTER TABLE "Invoice" ADD COLUMN "lud18Data" JSONB; | ||
|
||
-- Add lud18 data parameter to invoice creation | ||
CREATE OR REPLACE FUNCTION create_invoice(hash TEXT, bolt11 TEXT, expires_at timestamp(3) without time zone, | ||
msats_req BIGINT, user_id INTEGER, idesc TEXT, comment TEXT, lud18_data JSONB, inv_limit INTEGER, balance_limit_msats BIGINT) | ||
RETURNS "Invoice" | ||
LANGUAGE plpgsql | ||
AS $$ | ||
DECLARE | ||
invoice "Invoice"; | ||
inv_limit_reached BOOLEAN; | ||
balance_limit_reached BOOLEAN; | ||
inv_pending_msats BIGINT; | ||
BEGIN | ||
PERFORM ASSERT_SERIALIZED(); | ||
|
||
-- prevent too many pending invoices | ||
SELECT inv_limit > 0 AND count(*) >= inv_limit, sum("msatsRequested") INTO inv_limit_reached, inv_pending_msats | ||
FROM "Invoice" | ||
WHERE "userId" = user_id AND "expiresAt" > now_utc() AND "confirmedAt" IS NULL AND cancelled = false; | ||
|
||
IF inv_limit_reached THEN | ||
RAISE EXCEPTION 'SN_INV_PENDING_LIMIT'; | ||
END IF; | ||
|
||
-- prevent pending invoices + msats from exceeding the limit | ||
SELECT balance_limit_msats > 0 AND inv_pending_msats+msats_req+msats > balance_limit_msats INTO balance_limit_reached | ||
FROM users | ||
WHERE id = user_id; | ||
|
||
IF balance_limit_reached THEN | ||
RAISE EXCEPTION 'SN_INV_EXCEED_BALANCE'; | ||
END IF; | ||
|
||
-- we good, proceed frens | ||
INSERT INTO "Invoice" (hash, bolt11, "expiresAt", "msatsRequested", "userId", created_at, updated_at, "desc", comment, "lud18Data") | ||
VALUES (hash, bolt11, expires_at, msats_req, user_id, now_utc(), now_utc(), idesc, comment, lud18_data) RETURNING * INTO invoice; | ||
|
||
INSERT INTO pgboss.job (name, data, retrylimit, retrybackoff, startafter) | ||
VALUES ('checkInvoice', jsonb_build_object('hash', hash), 21, true, now() + interval '10 seconds'); | ||
|
||
RETURN invoice; | ||
END; | ||
$$; | ||
|
||
-- make sure old function is gone | ||
DROP FUNCTION IF EXISTS create_invoice(hash TEXT, bolt11 TEXT, expires_at timestamp(3) without time zone, | ||
msats_req BIGINT, user_id INTEGER, idesc TEXT, comment TEXT, inv_limit INTEGER, balance_limit_msats BIGINT); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I set no caching here since we include a
k1
in the response payload that's unique for each request.