send payment when order invoice is received

This commit is contained in:
Daniel Lugo 2020-01-13 21:28:50 -04:00
parent 88abc9a2a9
commit 0734cb6cb9

View file

@ -2,6 +2,9 @@
* @format
*/
const uuidv1 = require('uuid/v1')
const LightningServices = require('../../../utils/lightningServices')
const ErrorCode = require('./errorCode')
const Getters = require('./getters')
const Key = require('./key')
@ -908,15 +911,28 @@ const sendPayment = async (to, amount, memo, gun, user, SEA) => {
})
])
if (Math.random() > 0.5) {
return Promise.resolve()
}
const decInvoice = await SEA.decrypt(invoice, ourSecret)
return Promise.reject(
new Error('Lightning could not find a route to pay invoice: ' + decInvoice)
const {
services: { lightning }
} = LightningServices
await new Promise((rej, resolve) => {
lightning.sendPaymentSync(
{
payment_request: decInvoice
},
(/** @type {any} */ err, /** @type {any} */ res) => {
if (err) {
console.log(err)
rej(err)
} else {
console.log(res)
resolve()
}
}
)
})
}
/**