check for invoice amt mismatch
This commit is contained in:
parent
7fbd1c8b7f
commit
7b84f250c1
1 changed files with 19 additions and 1 deletions
|
|
@ -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({
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue