ADD: post to GroundControl notification about invoice paid

This commit is contained in:
Overtorment
2020-07-11 14:42:09 +01:00
parent 9533e43d19
commit 69ce4d032a
3 changed files with 145 additions and 3 deletions

View File

@@ -1,4 +1,5 @@
import { User, Lock, Paym } from '../class/';
import Frisbee from 'frisbee';
const config = require('../config');
let express = require('express');
let router = express.Router();
@@ -46,13 +47,49 @@ lightning.getInfo({}, function(err, info) {
}
});
redis.info(function(err, info) {
redis.info(function (err, info) {
if (err || !info) {
console.error('redis failure');
process.exit(5);
}
});
let subscribeInvoicesCall = lightning.subscribeInvoices({});
subscribeInvoicesCall.on('data', async function (response) {
if (response.state === 'SETTLED') {
const LightningInvoiceSettledNotification = {
memo: response.memo,
preimage: response.r_preimage.toString('hex'),
hash: response.r_hash.toString('hex'),
amt_paid_sat: response.amt_paid_sat,
};
console.log('payment', LightningInvoiceSettledNotification.hash, 'was paid, posting to GroundControl...');
const baseURI = process.env.GROUNDCONTROL;
if (!baseURI) return;
const _api = new Frisbee({ baseURI: baseURI });
const apiResponse = await _api.post(
'/lightningInvoiceGotSettled',
Object.assign(
{},
{
headers: {
'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/json',
},
body: LightningInvoiceSettledNotification,
},
),
);
console.log('GroundControl:', apiResponse.originalResponse.status);
}
});
subscribeInvoicesCall.on('status', function (status) {
// The current status of the stream.
});
subscribeInvoicesCall.on('end', function () {
// The server has closed the stream.
});
// ######################## ROUTES ########################
const rateLimit = require('express-rate-limit');