Payments Incomplete

Payments Incomplete
pull/47/head
ShahanaFarooqui 6 years ago
parent a7188bed37
commit ffac7fabed

@ -9,4 +9,4 @@
<body>
<rtl-root></rtl-root>
<script type="text/javascript" src="runtime.6afe30102d8fe7337431.js"></script><script type="text/javascript" src="polyfills.c7939909ac1e754960ad.js"></script><script type="text/javascript" src="main.d9733a5555e43c712336.js"></script></body></html>
<script type="text/javascript" src="runtime.6afe30102d8fe7337431.js"></script><script type="text/javascript" src="polyfills.c7939909ac1e754960ad.js"></script><script type="text/javascript" src="main.6e78687f0195665aa682.js"></script></body></html>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -13,6 +13,8 @@ const walletRoutes = require("./routes/wallet");
const graphInfoRoutes = require("./routes/graphInfo");
const newAddressRoutes = require("./routes/newAddress");
const transactionsRoutes = require("./routes/transactions");
const payReqRoutes = require("./routes/payReq");
const paymentsRoutes = require("./routes/payments");
const UISettingsRoutes = require("./routes/UISettings");
const LNDSettingsRoutes = require("./routes/lndConfSettings");
@ -45,6 +47,8 @@ app.use("/api/wallet", walletRoutes);
app.use("/api/network", graphInfoRoutes);
app.use("/api/newaddress", newAddressRoutes);
app.use("/api/transactions", transactionsRoutes);
app.use("/api/payreq", payReqRoutes);
app.use("/api/payments", paymentsRoutes);
app.use("/api/uisettings", UISettingsRoutes);
app.use("/api/lndconf", LNDSettingsRoutes);

@ -0,0 +1,18 @@
var common = {};
common.lnd_server_url = 'https://localhost:8080/v1';
common.lnd_dir = '';
common.twoDecimalRound = (num) => {
return num.toFixed(2);
};
common.convertToBTC = (num) => {
return (num / 100000000).toFixed(6);
};
common.convertTimestampToDate = (num) => {
return new Date(+num*1000).toLocaleString();
};
module.exports = common;

@ -1,16 +1,16 @@
var fs = require('fs');
var config = require('./config');
var common = require('./common');
var clArgs = require('optimist').argv;
if(undefined !== clArgs.lndir) {
config.lnd_dir = clArgs.lndir;
common.lnd_dir = clArgs.lndir;
} else {
if(config.lnd_dir === '') {
config.lnd_dir = __dirname;
if(common.lnd_dir === '') {
common.lnd_dir = __dirname;
}
}
var macaroon = fs.readFileSync(config.lnd_dir + '/admin.macaroon').toString('hex');
var macaroon = fs.readFileSync(common.lnd_dir + '/admin.macaroon').toString('hex');
var options = {
url: '',
rejectUnauthorized: false,

@ -1,11 +1,11 @@
var request = require('request');
var options = require("../connect");
var config = require('../config');
var common = require('../common');
exports.getBalance = (req, res, next) => {
// setTimeout(()=>{res.status(201).json({"balance":{"total_balance":"15305209","confirmed_balance":"15305209"}});}, 5000);
// setTimeout(()=>{res.status(201).json({"balance":{"balance":"5983797"}});}, 5000);
options.url = config.lnd_server_url + '/balance/' + req.params.source;
options.url = common.lnd_server_url + '/balance/' + req.params.source;
options.qs = req.query;
request.get(options, (error, response, body) => {
console.log('Request params: ' + JSON.stringify(req.params) + '\nRequest Query: ' + JSON.stringify(req.query) + ' \nBalance Received: ' + JSON.stringify(body));
@ -18,16 +18,11 @@ exports.getBalance = (req, res, next) => {
error: (undefined === body || search_idx > -1) ? 'ERROR From Server!' : body.error
});
} else {
body.btc_balance = (undefined === body.balance) ? 0 : convertToBTC(body.balance);
body.btc_total_balance = (undefined === body.total_balance) ? 0 : convertToBTC(body.total_balance);
body.btc_confirmed_balance = (undefined === body.confirmed_balance) ? 0 : convertToBTC(body.confirmed_balance);
body.btc_unconfirmed_balance = (undefined === body.unconfirmed_balance) ? 0 : convertToBTC(body.unconfirmed_balance);
body.btc_balance = (undefined === body.balance) ? 0 : common.convertToBTC(body.balance);
body.btc_total_balance = (undefined === body.total_balance) ? 0 : common.convertToBTC(body.total_balance);
body.btc_confirmed_balance = (undefined === body.confirmed_balance) ? 0 : common.convertToBTC(body.confirmed_balance);
body.btc_unconfirmed_balance = (undefined === body.unconfirmed_balance) ? 0 : common.convertToBTC(body.unconfirmed_balance);
res.status(200).json(body);
}
});
convertToBTC = (num) => {
return (num / 100000000).toFixed(6);
};
};

@ -1,12 +1,12 @@
var request = require('request');
var options = require("../connect");
var config = require('../config');
var common = require('../common');
exports.getChannels = (req, res, next) => {
if (undefined === req.params.channelType || req.params.channelType === 'all') {
options.url = config.lnd_server_url + '/channels';
options.url = common.lnd_server_url + '/channels';
} else {
options.url = config.lnd_server_url + '/channels/' + req.params.channelType;
options.url = common.lnd_server_url + '/channels/' + req.params.channelType;
}
options.qs = req.query;
request.get(options, (error, response, body) => {
@ -24,7 +24,7 @@ exports.getChannels = (req, res, next) => {
exports.postChannel = (req, res, next) => {
// setTimeout(()=>{res.status(201).json({message: 'Channel Open!'});}, 5000);
options.url = config.lnd_server_url + '/channels';
options.url = common.lnd_server_url + '/channels';
options.form = JSON.stringify({
node_pubkey_string: req.body.node_pubkey,
local_funding_amount: req.body.local_funding_amount

@ -1,10 +1,10 @@
var request = require('request');
var options = require("../connect");
var config = require('../config');
var common = require('../common');
exports.getFees = (req, res, next) => {
// setTimeout(()=>{res.status(201).json({"fees":{"channel_fees":[{"chan_point":"a75eabb7386e977210a9796032f5bc3c793b474630ca373669f3c09d0fa095a5:0","base_fee_msat":"1000","fee_per_mil":"1","fee_rate":0.000001},{"chan_point":"acda63cdb77c5feffa41342e376968865bc1578f9e13a04d6b5d02af60f21425:0","base_fee_msat":"1000","fee_per_mil":"1","fee_rate":0.000001},{"chan_point":"3d387f17ee1937faf93b9355d9b351dd9227a424b3c3f0ae4120b275957fef1c:0","base_fee_msat":"1000","fee_per_mil":"1","fee_rate":0.000001},{"chan_point":"d437c5c67aabcb9e8ca36ffd3458068edb20bd15bba7cae60a99cdfa5ac71d3c:0","base_fee_msat":"1000","fee_per_mil":"1","fee_rate":0.000001},{"chan_point":"e799a7e18f99398c9849391947bbbce46b14b651181dac57bfcbb7705796ce52:0","base_fee_msat":"1000","fee_per_mil":"1","fee_rate":0.000001},{"chan_point":"aefc7a8269998ad5617a2e4fb5fa40c7f6716ca5e09b065f50b80473624a0b8b:0","base_fee_msat":"1000","fee_per_mil":"1","fee_rate":0.000001}],"day_fee_sum":0,"week_fee_sum":0,"month_fee_sum":0}});}, 5000);
options.url = config.lnd_server_url + '/fees';
options.url = common.lnd_server_url + '/fees';
request.get(options, (error, response, body) => {
console.log("Fee Received: " + JSON.stringify(body));
if(undefined === body || body.error) {

@ -1,9 +1,9 @@
var request = require('request');
var options = require("../connect");
var config = require('../config');
var common = require('../common');
exports.getInfo = (req, res, next) => {
options.url = config.lnd_server_url + '/getinfo';
options.url = common.lnd_server_url + '/getinfo';
request.get(options, (error, response, body) => {
const body_str = (undefined === body) ? '' : JSON.stringify(body);
const search_idx = (undefined === body) ? -1 : body_str.search('Not Found');

@ -1,9 +1,9 @@
var request = require('request');
var options = require("../connect");
var config = require('../config');
var common = require('../common');
exports.getGraphInfo = (req, res, next) => {
options.url = config.lnd_server_url + '/graph/info';
options.url = common.lnd_server_url + '/graph/info';
request.get(options, (error, response, body) => {
const body_str = (undefined === body) ? '' : JSON.stringify(body);
const search_idx = (undefined === body) ? -1 : body_str.search('Not Found');
@ -14,23 +14,14 @@ exports.getGraphInfo = (req, res, next) => {
error: (undefined === body || search_idx > -1) ? 'ERROR From Server!' : body.error
});
} else {
body.avg_out_degree = (undefined === body.avg_out_degree) ? 0 : twoDecimalRound(body.avg_out_degree);
body.avg_channel_size = (undefined === body.avg_channel_size) ? 0 : twoDecimalRound(body.avg_channel_size);
body.btc_total_network_capacity = (undefined === body.total_network_capacity) ? 0 : convertToBTC(body.total_network_capacity);
body.btc_avg_channel_size = (undefined === body.avg_channel_size) ? 0 : convertToBTC(body.avg_channel_size);
body.btc_min_channel_size = (undefined === body.min_channel_size) ? 0 : convertToBTC(body.min_channel_size);
body.btc_max_channel_size = (undefined === body.max_channel_size) ? 0 : convertToBTC(body.max_channel_size);
body.avg_out_degree = (undefined === body.avg_out_degree) ? 0 : common.twoDecimalRound(body.avg_out_degree);
body.avg_channel_size = (undefined === body.avg_channel_size) ? 0 : common.twoDecimalRound(body.avg_channel_size);
body.btc_total_network_capacity = (undefined === body.total_network_capacity) ? 0 : common.convertToBTC(body.total_network_capacity);
body.btc_avg_channel_size = (undefined === body.avg_channel_size) ? 0 : common.convertToBTC(body.avg_channel_size);
body.btc_min_channel_size = (undefined === body.min_channel_size) ? 0 : common.convertToBTC(body.min_channel_size);
body.btc_max_channel_size = (undefined === body.max_channel_size) ? 0 : common.convertToBTC(body.max_channel_size);
console.log('Network Information After Rounding and Conversion: ' + body_str);
res.status(200).json(body);
}
});
twoDecimalRound = (num) => {
return num.toFixed(2);
};
convertToBTC = (num) => {
return (num / 100000000).toFixed(6);
};
};

@ -1,9 +1,9 @@
var request = require('request');
var options = require("../connect");
var config = require('../config');
var common = require('../common');
exports.getNewAddress = (req, res, next) => {
options.url = config.lnd_server_url + '/newaddress?type=' + req.query.type;
options.url = common.lnd_server_url + '/newaddress?type=' + req.query.type;
console.log('\n-------------------------------------------------');
console.log('Get New Address');
console.log('-------------------------------------------------');

@ -0,0 +1,23 @@
var request = require('request');
var options = require("../connect");
var common = require('../common');
exports.decodePayment = (req, res, next) => {
options.url = common.lnd_server_url + '/payreq/' + req.params.payRequest;
console.log('Options URL: ' + JSON.stringify(options.url));
request.get(options, (error, response, body) => {
const body_str = (undefined === body) ? '' : JSON.stringify(body);
const search_idx = (undefined === body) ? -1 : body_str.search('Not Found');
console.log("Payment Request Decoded Received: " + body_str);
if(undefined === body || search_idx > -1 || body.error) {
res.status(500).json({
message: "Payment Request Decode Failed!",
error: (undefined === body || search_idx > -1) ? 'ERROR From Server!' : body.error
});
} else {
body.btc_num_satoshis = (undefined === body.num_satoshis) ? 0 : common.convertToBTC(body.num_satoshis);
body.timestamp_str = (undefined === body.timestamp) ? '' : common.convertTimestampToDate(body.timestamp);
res.status(200).json(body);
}
});
};

@ -0,0 +1,24 @@
var request = require('request');
var options = require("../connect");
var common = require('../common');
exports.getPayments = (req, res, next) => {
options.url = common.lnd_server_url + '/payments';
console.log('Options URL: ' + JSON.stringify(options.url));
request.get(options, (error, response, body) => {
const body_str = (undefined === body) ? '' : JSON.stringify(body);
const search_idx = (undefined === body) ? -1 : body_str.search('Not Found');
console.log("Payment Request Decoded Received: " + body_str);
if(undefined === body || search_idx > -1 || body.error) {
res.status(500).json({
message: "Payments List Failed!",
error: (undefined === body || search_idx > -1) ? 'ERROR From Server!' : body.error
});
} else {
body.payments.forEach(payment => {
payment.creation_date_str = (undefined === payment.creation_date) ? '' : common.convertTimestampToDate(payment.creation_date);
});
res.status(200).json(body.payments);
}
});
};

@ -1,10 +1,10 @@
var fs = require('fs');
var request = require('request');
var options = require("../connect");
var config = require('../config');
var common = require('../common');
exports.getPeers = (req, res, next) => {
options.url = config.lnd_server_url + '/peers';
options.url = common.lnd_server_url + '/peers';
request.get(options, (error, response, body) => {
console.log('Peers Received: ' + JSON.stringify(body));
if(error) {
@ -20,7 +20,7 @@ exports.getPeers = (req, res, next) => {
exports.postPeer = (req, res, next) => {
// setTimeout(()=>{res.status(201).json({message: 'Peer Added!'});}, 5000);
options.url = config.lnd_server_url + '/peers';
options.url = common.lnd_server_url + '/peers';
options.form = JSON.stringify({
addr: { host: req.body.host, pubkey: req.body.pubkey },
perm: req.body.perm

@ -1,9 +1,9 @@
var request = require('request');
var options = require("../connect");
var config = require('../config');
var common = require('../common');
exports.postTransactions = (req, res, next) => {
options.url = config.lnd_server_url + '/transactions';
options.url = common.lnd_server_url + '/transactions';
options.form = JSON.stringify({
amount: req.body.amount,
addr: req.body.address,

@ -1,6 +1,6 @@
var request = require('request');
var options = require("../connect");
var config = require('../config');
var common = require('../common');
exports.operateWallet = (req, res, next) => {
var requestBody = {
@ -9,11 +9,11 @@ exports.operateWallet = (req, res, next) => {
console.log('\nRequest Body after conversion into Uint8Array: ');
console.log(requestBody);
if (undefined === req.params.operation || req.params.operation === 'unlock') {
options.url = config.lnd_server_url + '/unlockwallet';
options.url = common.lnd_server_url + '/unlockwallet';
options.form = JSON.stringify(requestBody);
err_message = 'Unlocking wallet failed! Verify that lnd is running!';
} else {
options.url = config.lnd_server_url + '/initwallet';
options.url = common.lnd_server_url + '/initwallet';
options.form = JSON.stringify(requestBody);
err_message = 'Initializing wallet failed!';
}

@ -0,0 +1,7 @@
const PayRequestController = require("../controllers/payReq");
const express = require("express");
const router = express.Router();
router.get("/:payRequest", PayRequestController.decodePayment);
module.exports = router;

@ -0,0 +1,7 @@
const PaymentsController = require("../controllers/payments");
const express = require("express");
const router = express.Router();
router.get("/", PaymentsController.getPayments);
module.exports = router;

@ -1 +1 @@
{"name":"RTL","loadingSpinner":false,"fixedHeader":false,"sidenavIsOpened":true,"sidenavIsPinned":true,"sidenavUserBlock":true,"menu":"vertical","menuType":"default","theme":"dark-blue","rtl":false,"lndConfigPath":"","satsToBTC":false}
{"name":"RTL","loadingSpinner":false,"fixedHeader":false,"sidenavIsOpened":true,"sidenavIsPinned":true,"sidenavUserBlock":true,"menu":"vertical","menuType":"default","theme":"dark-blue","rtl":false,"lndConfigPath":"","satsToBTC":true}
Loading…
Cancel
Save