diff --git a/services/gunDB/contact-api/actions.js b/services/gunDB/contact-api/actions.js index c067b4d3..77d72556 100644 --- a/services/gunDB/contact-api/actions.js +++ b/services/gunDB/contact-api/actions.js @@ -9,7 +9,10 @@ const Gun = require('gun') const { ErrorCode } = Constants -const { sendPaymentV2Invoice } = require('../../../utils/lightningServices/v2') +const { + sendPaymentV2Invoice, + decodePayReq +} = require('../../../utils/lightningServices/v2') /** * @typedef {import('../../../utils/lightningServices/types').PaymentV2} PaymentV2 @@ -1040,6 +1043,21 @@ const sendSpontaneousPayment = async ( throw new Error(orderResponse.response) } + logger.info('Will now check for invoice amount mismatch') + + const encodedInvoice = orderResponse.response + + const { num_satoshis: decodedAmt } = await decodePayReq(encodedInvoice) + + if (decodedAmt !== amount.toString()) { + throw new Error('Invoice amount mismatch') + } + + // double check + if (Number(decodedAmt) !== amount) { + throw new Error('Invoice amount mismatch') + } + logger.info('Will now send payment through lightning') const payment = await sendPaymentV2Invoice({