-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathissuerServer.js
48 lines (36 loc) · 1.41 KB
/
issuerServer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
var express = require("express");
var bodyParser = require("body-parser");
// var routes = require("./routes/routes.js");
var app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
// routes(app);
//define util function.
const util = require('util');
const exec = util.promisify(require('child_process').exec);
var server = app.listen(3001, function () {
console.log("app running on port.", server.address().port);
});
// app.get("/getCredential", function (req, res) {
// res.status(200).send("success");
// });
async function isChannelActive(channelId) {
const { stdout, stderr } = await exec('lightning-cli listchannels ' + channelId);
console.log('stdout:', stdout);
console.log('stderr:', stderr);
return stdout.length > 0;
}
app.post('/getCredential', async function(request, response){
let unverifiedChannelId = request.body.channelId;
console.log(request.body);
//TODO: test this
let isChannelVerified = await isChannelActive(unverifiedChannelId);
let signedCredential = request.body;
if (isChannelVerified) {
response.send(signedCredential);
} else {
response.status(500).send('Channel not found');
}
response.send(channelList); // echo the result back but signed
});
//curl -vX POST localhost:3001/getCredential -d @tempExampleTemplate.json --header "Content-Type: application/json"