use new wrapper
This commit is contained in:
parent
7543a7eca9
commit
a72dd72280
1 changed files with 26 additions and 68 deletions
|
|
@ -29,6 +29,10 @@ const {
|
||||||
const GunActions = require('../services/gunDB/contact-api/actions')
|
const GunActions = require('../services/gunDB/contact-api/actions')
|
||||||
const GunGetters = require('../services/gunDB/contact-api/getters')
|
const GunGetters = require('../services/gunDB/contact-api/getters')
|
||||||
const GunKey = require('../services/gunDB/contact-api/key')
|
const GunKey = require('../services/gunDB/contact-api/key')
|
||||||
|
const {
|
||||||
|
sendPaymentV2Keysend,
|
||||||
|
sendPaymentV2Invoice
|
||||||
|
} = require('../utils/lightningServices/v2')
|
||||||
|
|
||||||
const DEFAULT_MAX_NUM_ROUTES_TO_QUERY = 10
|
const DEFAULT_MAX_NUM_ROUTES_TO_QUERY = 10
|
||||||
const SESSION_ID = uuid()
|
const SESSION_ID = uuid()
|
||||||
|
|
@ -1442,92 +1446,46 @@ module.exports = async (
|
||||||
})
|
})
|
||||||
|
|
||||||
// sendpayment
|
// sendpayment
|
||||||
app.post('/api/lnd/sendpayment', (req, res) => {
|
app.post('/api/lnd/sendpayment', async (req, res) => {
|
||||||
const { router } = LightningServices.services
|
|
||||||
// this is the recommended value from lightning labs
|
// this is the recommended value from lightning labs
|
||||||
let paymentRequest = {}
|
|
||||||
const { keysend, maxParts = 3, timeoutSeconds = 5, feeLimit } = req.body
|
const { keysend, maxParts = 3, timeoutSeconds = 5, feeLimit } = req.body
|
||||||
|
|
||||||
if (!feeLimit) {
|
if (!feeLimit) {
|
||||||
return res.status(500).json({
|
return res.status(400).json({
|
||||||
errorMessage: 'please provide a "feeLimit" to the send payment request'
|
errorMessage: 'please provide a "feeLimit" to the send payment request'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if (keysend) {
|
if (keysend) {
|
||||||
const { dest, amt, finalCltvDelta = 40 } = req.body
|
const { dest, amt, finalCltvDelta = 40 } = req.body
|
||||||
if (!dest || !amt) {
|
if (!dest || !amt) {
|
||||||
return res.status(500).json({
|
return res.status(400).json({
|
||||||
errorMessage: 'please provide "dest" and "amt" for keysend payments'
|
errorMessage: 'please provide "dest" and "amt" for keysend payments'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
const preimage = Crypto.randomBytes(32)
|
|
||||||
const r_hash = Crypto.createHash('sha256')
|
const payment = await sendPaymentV2Keysend({
|
||||||
.update(preimage)
|
|
||||||
.digest()
|
|
||||||
//https://github.com/lightningnetwork/lnd/blob/master/record/experimental.go#L5:2
|
|
||||||
//might break in future updates
|
|
||||||
const KeySendType = 5482373484
|
|
||||||
//https://api.lightning.community/#featurebit
|
|
||||||
const TLV_ONION_REQ = 8
|
|
||||||
paymentRequest = {
|
|
||||||
dest: Buffer.from(dest, 'hex'),
|
|
||||||
amt,
|
amt,
|
||||||
final_cltv_delta: finalCltvDelta,
|
dest,
|
||||||
dest_features: [TLV_ONION_REQ],
|
feeLimit,
|
||||||
dest_custom_records: {
|
finalCltvDelta,
|
||||||
[KeySendType]: preimage
|
maxParts,
|
||||||
},
|
timeoutSeconds
|
||||||
payment_hash: r_hash,
|
})
|
||||||
max_parts: maxParts,
|
|
||||||
timeout_seconds: timeoutSeconds,
|
return res.status(200).json(payment)
|
||||||
no_inflight_updates: true,
|
|
||||||
fee_limit_sat: feeLimit
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
const { payreq } = req.body
|
const { payreq } = req.body
|
||||||
|
|
||||||
paymentRequest = {
|
const payment = await sendPaymentV2Invoice({
|
||||||
|
feeLimit,
|
||||||
payment_request: payreq,
|
payment_request: payreq,
|
||||||
|
amt: req.body.amt,
|
||||||
max_parts: maxParts,
|
max_parts: maxParts,
|
||||||
timeout_seconds: timeoutSeconds,
|
timeoutSeconds
|
||||||
no_inflight_updates: true,
|
|
||||||
fee_limit_sat: feeLimit
|
|
||||||
}
|
|
||||||
|
|
||||||
if (req.body.amt) {
|
|
||||||
paymentRequest.amt = req.body.amt
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.info('Sending payment', paymentRequest)
|
|
||||||
const sentPayment = router.sendPaymentV2(paymentRequest)
|
|
||||||
sentPayment.on('data', response => {
|
|
||||||
logger.info('SendPayment Data:', response)
|
|
||||||
if (response.failure_reason !== 'FAILURE_REASON_NONE') {
|
|
||||||
res.status(500).json({
|
|
||||||
errorMessage: response.failure_reason
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
res.json(response)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
sentPayment.on('status', status => {
|
return res.status(200).json(payment)
|
||||||
logger.info('SendPayment Status:', status)
|
|
||||||
})
|
|
||||||
|
|
||||||
sentPayment.on('error', async err => {
|
|
||||||
logger.error('SendPayment Error:', err)
|
|
||||||
const health = await checkHealth()
|
|
||||||
if (health.LNDStatus.success) {
|
|
||||||
res.status(500).json({
|
|
||||||
errorMessage: sanitizeLNDError(err.details)
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
res.status(500)
|
|
||||||
res.json({ errorMessage: 'LND is down' })
|
|
||||||
}
|
|
||||||
})
|
|
||||||
//sentPayment.on('end', () => {})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
app.post('/api/lnd/trackpayment', (req, res) => {
|
app.post('/api/lnd/trackpayment', (req, res) => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue