check for invoice amt mismatch

This commit is contained in:
Daniel Lugo 2020-11-03 13:55:43 -04:00
parent 7fbd1c8b7f
commit 7b84f250c1

View file

@ -9,7 +9,10 @@ const Gun = require('gun')
const { ErrorCode } = Constants const { ErrorCode } = Constants
const { sendPaymentV2Invoice } = require('../../../utils/lightningServices/v2') const {
sendPaymentV2Invoice,
decodePayReq
} = require('../../../utils/lightningServices/v2')
/** /**
* @typedef {import('../../../utils/lightningServices/types').PaymentV2} PaymentV2 * @typedef {import('../../../utils/lightningServices/types').PaymentV2} PaymentV2
@ -1040,6 +1043,21 @@ const sendSpontaneousPayment = async (
throw new Error(orderResponse.response) 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') logger.info('Will now send payment through lightning')
const payment = await sendPaymentV2Invoice({ const payment = await sendPaymentV2Invoice({