Skip to content

Commit

Permalink
New checkinvoice super admin command
Browse files Browse the repository at this point in the history
* Update lightning library
  • Loading branch information
grunch committed Jul 13, 2023
1 parent de2caab commit 8ea4af8
Show file tree
Hide file tree
Showing 15 changed files with 846 additions and 261 deletions.
8 changes: 6 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ const { delay } = require('./util');

(async () => {
process.on('unhandledRejection', e => {
logger.error(`Unhandled Rejection: ${e.message}`);
if (e) {
logger.error(`Unhandled Rejection: ${e}`);
}
});

process.on('uncaughtException', e => {
logger.error(`Uncaught Exception: ${e.message}`);
if (e) {
logger.error(`Uncaught Exception: ${e}`);
}
});

const mongoose = mongoConnect();
Expand Down
19 changes: 19 additions & 0 deletions bot/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,24 @@ const checkOrderMessage = async (ctx, order, buyer, seller) => {
}
};

const checkInvoiceMessage = async (ctx, isConfirmed, isCanceled, isHeld) => {
try {
if (isConfirmed) {
return await ctx.reply(ctx.i18n.t('invoice_settled'));
}
if (isCanceled) {
return await ctx.reply(ctx.i18n.t('invoice_cancelled'));
}
if (isHeld) {
return await ctx.reply(ctx.i18n.t('invoice_held'));
}

return await ctx.reply(ctx.i18n.t('invoice_no_info'));
} catch (error) {
logger.error(error);
}
};

const mustBeValidCurrency = async ctx => {
try {
await ctx.reply(ctx.i18n.t('must_be_valid_currency'));
Expand Down Expand Up @@ -1661,4 +1679,5 @@ module.exports = {
mustBeANumber,
showConfirmationButtons,
counterPartyCancelOrderMessage,
checkInvoiceMessage,
};
24 changes: 24 additions & 0 deletions bot/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const {
payToBuyer,
isPendingPayment,
subscribeInvoice,
getInvoice,
} = require('../ln');
const {
validateUser,
Expand Down Expand Up @@ -426,6 +427,29 @@ const initialize = (botToken, options) => {
}
});

bot.command('checkinvoice', superAdminMiddleware, async ctx => {
try {
const [orderId] = await validateParams(ctx, 2, '\\<_order id_\\>');
if (!orderId) return;
if (!(await validateObjectId(ctx, orderId))) return;
const order = await Order.findOne({ _id: orderId });

if (!order) return;
if (!order.hash) return;

const invoice = await getInvoice({ hash: order.hash });

await messages.checkInvoiceMessage(
ctx,
invoice.is_confirmed,
invoice.is_canceled,
invoice.is_held
);
} catch (error) {
logger.error(error);
}
});

bot.command('resubscribe', superAdminMiddleware, async ctx => {
try {
const [hash] = await validateParams(ctx, 2, '\\<_hash_\\>');
Expand Down
15 changes: 14 additions & 1 deletion ln/hold_invoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,17 @@ const cancelHoldInvoice = async ({ hash }) => {
}
};

module.exports = { createHoldInvoice, settleHoldInvoice, cancelHoldInvoice };
const getInvoice = async ({ hash }) => {
try {
return await lightning.getInvoice({ lnd, id: hash });
} catch (error) {
logger.error(error);
}
};

module.exports = {
createHoldInvoice,
settleHoldInvoice,
cancelHoldInvoice,
getInvoice,
};
2 changes: 2 additions & 0 deletions ln/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const {
createHoldInvoice,
settleHoldInvoice,
cancelHoldInvoice,
getInvoice,
} = require('./hold_invoice');
const subscribeInvoice = require('./subscribe_invoice');
const subscribeProbe = require('./subscribe_probe');
Expand All @@ -20,4 +21,5 @@ module.exports = {
getInfo,
isPendingPayment,
subscribeProbe,
getInvoice,
};
7 changes: 6 additions & 1 deletion locales/de.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -549,4 +549,9 @@ user_settings: |
<strong># HELP</strong>
/setnpub &lt;npub&gt; - Configure user public key. Nostr events will be tagged with this public key.
/exit - to exit the wizard.
# END modules/user
# END modules/user
# check hold invoice
invoice_settled: Rechnung wurde bereits niedergelassen
invoice_cancelled: Rechnung storniert
invoice_held: Rechnung festgehalten
invoice_no_info: Ich habe keine Informationen für diese Rechnung
7 changes: 6 additions & 1 deletion locales/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -551,4 +551,9 @@ user_settings: |
<strong># HELP</strong>
/setnpub &lt;npub&gt; - Configure user public key. Nostr events will be tagged with this public key.
/exit - to exit the wizard.
# END modules/user
# END modules/user
# check hold invoice
invoice_settled: Invoice already settled
invoice_cancelled: Invoice cancelled
invoice_held: Invoice held
invoice_no_info: I don't have information for that invoice
7 changes: 6 additions & 1 deletion locales/es.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -551,4 +551,9 @@ user_settings: |
<strong># AYUDA</strong>
/setnpub &lt;npub&gt; - Setea la llave pública. Los eventos Nostr serán taggeados con esta misma.
/exit - para salir del asistente.
# END modules/user
# END modules/user
# check hold invoice
invoice_settled: Factura ya cobrada
invoice_cancelled: Factura cancelada
invoice_held: Factura retenida
invoice_no_info: No tengo información para esa factura
5 changes: 5 additions & 0 deletions locales/fr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -552,3 +552,8 @@ user_settings: |
/setnpub &lt;npub&gt; - Configurer la clé publique de l'utilisateur. Les événements Nostr seront marqués avec cette clé publique.
/exit - pour quitter l'assistant.
# END modules/user
# check hold invoice
invoice_settled: Facture déjà installée
invoice_cancelled: Facture annulée
invoice_held: Facture tenue
invoice_no_info: Je n'ai pas d'informations pour cette facture
7 changes: 6 additions & 1 deletion locales/it.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -546,4 +546,9 @@ user_settings: |
<strong># HELP</strong>
/setnpub &lt;npub&gt; - Configure user public key. Nostr events will be tagged with this public key.
/exit - to exit the wizard.
# END modules/user
# END modules/user
# check hold invoice
invoice_settled: Fattura già risolta
invoice_cancelled: Fattura annullata
invoice_held: Fattura detenuta
invoice_no_info: Non ho informazioni per quella fattura
7 changes: 6 additions & 1 deletion locales/pt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -547,4 +547,9 @@ user_settings: |
<strong># HELP</strong>
/setnpub &lt;npub&gt; - Configure user public key. Nostr events will be tagged with this public key.
/exit - to exit the wizard.
# END modules/user
# END modules/user
# check hold invoice
invoice_settled: Fatura já liquidada
invoice_cancelled: Fatura cancelada
invoice_held: Fatura mantida
invoice_no_info: Não tenho informações para essa fatura
7 changes: 6 additions & 1 deletion locales/ru.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -549,4 +549,9 @@ user_settings: |
<strong># HELP</strong>
/setnpub &lt;npub&gt; - Configure user public key. Nostr events will be tagged with this public key.
/exit - to exit the wizard.
# END modules/user
# END modules/user
# check hold invoice
invoice_settled: Invoice already settled
invoice_cancelled: Invoice cancelled
invoice_held: Invoice held
invoice_no_info: I don't have information for that invoice
7 changes: 6 additions & 1 deletion locales/uk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -546,4 +546,9 @@ user_settings: |
<strong># HELP</strong>
/setnpub &lt;npub&gt; - Configure user public key. Nostr events will be tagged with this public key.
/exit - to exit the wizard.
# END modules/user
# END modules/user
# check hold invoice
invoice_settled: Invoice already settled
invoice_cancelled: Invoice cancelled
invoice_held: Invoice held
invoice_no_info: I don't have information for that invoice
Loading

0 comments on commit 8ea4af8

Please sign in to comment.