Skip to content
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

Remove the lightning prefix from the lnInvoice #572

Merged
merged 6 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions bot/bot_utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const removeLightningPrefix = function (invoice) {
const prefix = 'lightning:';

// Check if the invoice starts with the prefix
if (invoice.startsWith(prefix)) {
return invoice.substring(prefix.length);
}

// Return the invoice as is if no prefix is found
return invoice;
};

module.exports = {
removeLightningPrefix
};
4 changes: 3 additions & 1 deletion bot/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const OrderEvents = require('./modules/events/orders');

const { resolvLightningAddress } = require('../lnurl/lnurl-pay');
const { logger } = require('../logger');
const { removeLightningPrefix } = require('./bot_utils');

const waitPayment = async (ctx, bot, buyer, seller, order, buyerInvoice) => {
try {
Expand All @@ -32,7 +33,8 @@ const waitPayment = async (ctx, bot, buyer, seller, order, buyerInvoice) => {
return;
}

order.buyer_invoice = buyerInvoice;
// ISSUE: 542
order.buyer_invoice = removeLightningPrefix(buyerInvoice);
// We need the i18n context to send the message with the correct language
const i18nCtx = await getUserI18nContext(seller);
// If the buyer is the creator, at this moment the seller already paid the hold invoice
Expand Down
13 changes: 11 additions & 2 deletions bot/validations.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const { Order, User, Community } = require('../models');
const { isIso4217, isDisputeSolver } = require('../util');
const { existLightningAddress } = require('../lnurl/lnurl-pay');
const { logger } = require('../logger');
const { removeLightningPrefix } = require('./bot_utils');

// We look in database if the telegram user exists,
// if not, it creates a new user
Expand Down Expand Up @@ -305,7 +306,11 @@ const validateLightningAddress = async lightningAddress => {

const validateInvoice = async (ctx, lnInvoice) => {
try {
const invoice = parsePaymentRequest({ request: lnInvoice });
// ISSUE: 542

const checkedPrefixlnInvoice = removeLightningPrefix(lnInvoice);
const invoice = parsePaymentRequest({ request: checkedPrefixlnInvoice });

const latestDate = new Date(
Date.now() + parseInt(process.env.INVOICE_EXPIRATION_WINDOW)
).toISOString();
Expand Down Expand Up @@ -344,7 +349,11 @@ const validateInvoice = async (ctx, lnInvoice) => {

const isValidInvoice = async (ctx, lnInvoice) => {
try {
const invoice = parsePaymentRequest({ request: lnInvoice });
// ISSUE: 542

const checkedPrefixlnInvoice = removeLightningPrefix(lnInvoice);
const invoice = parsePaymentRequest({ request: checkedPrefixlnInvoice });

const latestDate = new Date(
Date.now() + parseInt(process.env.INVOICE_EXPIRATION_WINDOW)
).toISOString();
Expand Down