Optimized initialization and optional params on send fund

pull/86/head
ShahanaFarooqui 5 years ago
parent f8a7177cda
commit cc3bfb804d

@ -488,12 +488,12 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
@angular/material/expansion
@angular/material/tree
@angular/material/radio
@angular/material/sidenav
@angular/material/tree
@angular/material/toolbar
@angular/material/menu

@ -8,5 +8,5 @@
<link rel="stylesheet" href="styles.b70b44fe050fa03ed5cb.css"></head>
<body>
<rtl-app></rtl-app>
<script type="text/javascript" src="runtime.ec2944dd8b20ec099bf3.js"></script><script type="text/javascript" src="polyfills.418928a701f2040ada02.js"></script><script type="text/javascript" src="main.3b5d3f9de1836f3580e9.js"></script></body>
<script type="text/javascript" src="runtime.ec2944dd8b20ec099bf3.js"></script><script type="text/javascript" src="polyfills.418928a701f2040ada02.js"></script><script type="text/javascript" src="main.995d04f1bd4fb9645a05.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

@ -21,8 +21,8 @@ const paymentsRoutes = require("./routes/payments");
const RTLConfRoutes = require("./routes/RTLConf");
const invoiceRoutes = require("./routes/invoices");
const switchRoutes = require("./routes/switch");
const baseHref = '/rtl/';
const apiRoot = baseHref + 'api/';
const baseHref = "/rtl/";
const apiRoot = baseHref + "api/";
app.use(cookieParser(common.secret_key));
app.use(bodyParser.json());

@ -1,5 +1,5 @@
var fs = require('fs');
var crypto = require('crypto');
var common = {};
common.port = 3000;
@ -17,36 +17,52 @@ common.rtl_cookie_path = '';
common.logout_redirect_link = '/login';
common.cookie = '';
common.secret_key = crypto.randomBytes(64).toString('hex');
common.options = {};
common.setOptions = () => {
var macaroon = fs.readFileSync(common.macaroon_path + '/admin.macaroon').toString('hex');
common.options = {
url: '',
rejectUnauthorized: false,
json: true,
headers: {
'Grpc-Metadata-macaroon': macaroon,
},
form: ''
};
return common.options;
}
common.convertToBTC = (num) => {
return (num / 100000000).toFixed(6);
};
common.convertTimestampToDate = (num) => {
return new Date(+num*1000).toUTCString();
return new Date(+num * 1000).toUTCString();
};
common.sortAscByKey = (array, key) => {
return array.sort(function(a, b) {
var x = a[key]; var y = b[key];
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
});
return array.sort(function (a, b) {
var x = a[key]; var y = b[key];
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
});
}
common.sortDescByKey = (array, key) => {
return array.sort(function(a, b) {
var x = a[key]; var y = b[key];
return ((x > y) ? -1 : ((x < y) ? 1 : 0));
});
return array.sort(function (a, b) {
var x = a[key]; var y = b[key];
return ((x > y) ? -1 : ((x < y) ? 1 : 0));
});
}
common.newestOnTop = (array, key, value) => {
var index = array.findIndex(function(item){
return item[key] === value
});
var newlyAddedRecord = array.splice(index, 1);
array.unshift(newlyAddedRecord[0]);
return array;
var index = array.findIndex(function (item) {
return item[key] === value
});
var newlyAddedRecord = array.splice(index, 1);
array.unshift(newlyAddedRecord[0]);
return array;
}
module.exports = common;

@ -6,7 +6,7 @@ var common = require('./common');
var path = require('path');
var upperCase = require('upper-case');
var logger = require('./controllers/logger');
var options = {};
var connect = {};
var defaultConfig = {
Authentication: {
@ -225,19 +225,6 @@ String.random = function (length) {
}, '').substring(-length);
}
const setOptions = () => {
var macaroon = fs.readFileSync(common.macaroon_path + '/admin.macaroon').toString('hex');
options = {
url: '',
rejectUnauthorized: false,
json: true,
headers: {
'Grpc-Metadata-macaroon': macaroon,
},
form: ''
};
}
const logEnvVariables = () => {
if (!common.enable_logging) {
return;
@ -255,7 +242,7 @@ const logEnvVariables = () => {
}
var errMsg = '';
const configFileExists = () => {
connect.configFileExists = () => {
common.rtl_conf_file_path = (undefined !== process.env.RTL_CONFIG_PATH) ? process.env.RTL_CONFIG_PATH.substring(0, process.env.RTL_CONFIG_PATH.length - 9) : path.normalize(__dirname);
RTLConfFile = common.rtl_conf_file_path + '/RTL.conf';
let exists = fs.existsSync(RTLConfFile);
@ -263,7 +250,6 @@ const configFileExists = () => {
var config = ini.parse(fs.readFileSync(RTLConfFile, 'utf-8'));
setMacaroonPath(clArgs, config)
validateConfigFile(config);
setOptions();
logEnvVariables();
} else {
try {
@ -271,7 +257,6 @@ const configFileExists = () => {
var config = ini.parse(fs.readFileSync(RTLConfFile, 'utf-8'));
setMacaroonPath(clArgs, config)
validateConfigFile(config);
setOptions();
logEnvVariables();
}
catch(err) {
@ -280,5 +265,5 @@ const configFileExists = () => {
}
}
}
configFileExists();
module.exports = options;
module.exports = connect.configFileExists();

@ -1,9 +1,10 @@
var request = require('request-promise');
var options = require("../connect");
var common = require('../common');
var logger = require('./logger');
var options = {};
exports.getBalance = (req, res, next) => {
options = common.options;
options.url = common.lnd_server_url + '/balance/' + req.params.source;
options.qs = req.query;
request(options).then((body) => {

@ -1,7 +1,7 @@
var request = require('request-promise');
var options = require('../connect');
var common = require('../common');
var logger = require('./logger');
var options = {};
getAliasForChannel = (channel, channelType) => {
return new Promise(function(resolve, reject) {
@ -25,6 +25,7 @@ getAliasForChannel = (channel, channelType) => {
}
exports.getChannels = (req, res, next) => {
options = common.options;
if (undefined === req.params.channelType || req.params.channelType === 'all') {
options.url = common.lnd_server_url + '/channels';
} else {
@ -73,6 +74,7 @@ exports.getChannels = (req, res, next) => {
};
exports.postChannel = (req, res, next) => {
options = common.options;
options.url = common.lnd_server_url + '/channels';
options.form = JSON.stringify({
node_pubkey_string: req.body.node_pubkey,
@ -99,6 +101,7 @@ exports.postChannel = (req, res, next) => {
};
exports.postTransactions = (req, res, next) => {
options = common.options;
options.url = common.lnd_server_url + '/channels/transactions';
if(req.body.paymentReq) {
options.form = JSON.stringify({
@ -139,6 +142,7 @@ exports.postTransactions = (req, res, next) => {
exports.closeChannel = (req, res, next) => {
req.setTimeout(60000 * 10); // timeout 10 mins
options = common.options;
let channelpoint = req.params.channelPoint.replace(':', '/');
options.url = common.lnd_server_url + '/channels/' + channelpoint + '?force=' + req.query.force;
logger.info('\r\nChannels: 144: ' + JSON.stringify(Date.now()) + ': INFO: Closing Channel: ' + options.url);
@ -163,6 +167,7 @@ exports.closeChannel = (req, res, next) => {
}
exports.postChanPolicy = (req, res, next) => {
options = common.options;
options.url = common.lnd_server_url + '/chanpolicy';
if(req.body.chanPoint === 'all') {
options.form = JSON.stringify({

@ -1,9 +1,10 @@
var request = require('request-promise');
var options = require("../connect");
var common = require('../common');
var logger = require('./logger');
var options = {};
exports.getFees = (req, res, next) => {
options = common.options;
options.url = common.lnd_server_url + '/fees';
request(options).then((body) => {
logger.info('\r\nFees: 8: ' + JSON.stringify(Date.now()) + ': INFO: Fee Received: ' + JSON.stringify(body));

@ -1,9 +1,10 @@
var request = require('request-promise');
var options = require("../connect");
var common = require('../common');
var logger = require('./logger');
var options = {};
exports.getInfo = (req, res, next) => {
options = common.setOptions();
options.url = common.lnd_server_url + '/getinfo';
logger.info('\r\nCalling getinfo from lnd server url: INFO: ' + options.url);
request(options).then((body) => {

@ -1,9 +1,10 @@
var request = require("request-promise");
var options = require("../connect");
var common = require('../common');
var logger = require('./logger');
var options = {};
exports.getDescribeGraph = (req, res, next) => {
options = common.options;
options.url = common.lnd_server_url + '/graph';
request.get(options).then((body) => {
const body_str = (undefined === body) ? '' : JSON.stringify(body);
@ -27,6 +28,7 @@ exports.getDescribeGraph = (req, res, next) => {
};
exports.getGraphInfo = (req, res, next) => {
options = common.options;
options.url = common.lnd_server_url + '/graph/info';
request.get(options).then((body) => {
const body_str = (undefined === body) ? '' : JSON.stringify(body);
@ -55,6 +57,7 @@ exports.getGraphInfo = (req, res, next) => {
};
exports.getGraphNode = (req, res, next) => {
options = common.options;
options.url = common.lnd_server_url + '/graph/node/' + req.params.pubKey;
request(options).then((body) => {
logger.info('\r\nGraph: 59: ' + JSON.stringify(Date.now()) + ': INFO: Node Info Received: ' + JSON.stringify(body));
@ -64,6 +67,9 @@ exports.getGraphNode = (req, res, next) => {
error: (undefined === body) ? 'Error From Server!' : body.error
});
}
if (undefined !== body) {
body.node.last_update_str = (undefined === body.node.last_update) ? '' : common.convertTimestampToDate(body.node.last_update);
}
res.status(200).json(body);
})
.catch((err) => {
@ -75,6 +81,7 @@ exports.getGraphNode = (req, res, next) => {
};
exports.getGraphEdge = (req, res, next) => {
options = common.options;
options.url = common.lnd_server_url + '/graph/edge/' + req.params.chanid;
request(options).then((body) => {
logger.info('\r\nGraph: 79: ' + JSON.stringify(Date.now()) + ': INFO: Edge Info Received: ' + JSON.stringify(body));
@ -84,6 +91,9 @@ exports.getGraphEdge = (req, res, next) => {
error: (undefined === body) ? 'Error From Server!' : body.error
});
}
if (undefined !== body) {
body.last_update_str = (undefined === body.last_update) ? '' : common.convertTimestampToDate(body.last_update);
}
res.status(200).json(body);
})
.catch((err) => {

@ -1,9 +1,10 @@
var request = require('request-promise');
var options = require("../connect");
var common = require('../common');
var logger = require('./logger');
var options = {};
exports.getInvoice = (req, res, next) => {
options = common.options;
options.url = common.lnd_server_url + '/invoice/' + req.params.rHashStr;
request(options).then((body) => {
logger.info('\r\nInvoice: 8: ' + JSON.stringify(Date.now()) + ': INFO: Invoice Info Received: ' + JSON.stringify(body));
@ -24,6 +25,7 @@ exports.getInvoice = (req, res, next) => {
};
exports.listInvoices = (req, res, next) => {
options = common.options;
options.url = common.lnd_server_url + '/invoices';
request(options).then((body) => {
const body_str = (undefined === body) ? '' : JSON.stringify(body);
@ -57,6 +59,7 @@ exports.listInvoices = (req, res, next) => {
};
exports.addInvoice = (req, res, next) => {
options = common.options;
options.url = common.lnd_server_url + '/invoices';
options.form = JSON.stringify({
memo: req.body.memo,

@ -1,9 +1,10 @@
var request = require('request-promise');
var options = require("../connect");
var common = require('../common');
var logger = require('./logger');
var options = {};
exports.getNewAddress = (req, res, next) => {
options = common.options;
options.url = common.lnd_server_url + '/newaddress?type=' + req.query.type;
request(options).then((body) => {
const body_str = (undefined === body) ? '' : JSON.stringify(body);

@ -1,9 +1,10 @@
var request = require('request-promise');
var options = require("../connect");
var common = require('../common');
var logger = require('./logger');
var options = {};
exports.decodePayment = (req, res, next) => {
options = common.options;
options.url = common.lnd_server_url + '/payreq/' + req.params.payRequest;
request(options).then((body) => {
const body_str = (undefined === body) ? '' : JSON.stringify(body);

@ -1,9 +1,10 @@
var request = require('request-promise');
var options = require("../connect");
var common = require('../common');
var logger = require('./logger');
var options = {};
exports.getPayments = (req, res, next) => {
options = common.options;
options.url = common.lnd_server_url + '/payments';
request(options).then((body) => {
const body_str = (undefined === body) ? '' : JSON.stringify(body);

@ -1,8 +1,7 @@
var fs = require('fs');
var request = require('request-promise');
var options = require("../connect");
var common = require('../common');
var logger = require('./logger');
var options = {};
getAliasForPeers = (peer) => {
return new Promise(function(resolve, reject) {
@ -19,6 +18,7 @@ getAliasForPeers = (peer) => {
exports.getPeers = (req, res, next) =>
{
options = common.options;
options.url = common.lnd_server_url + '/peers';
request(options).then(function (body) {
let peers = (undefined === body.peers) ? [] : body.peers;
@ -43,6 +43,7 @@ exports.getPeers = (req, res, next) =>
};
exports.postPeer = (req, res, next) => {
options = common.options;
options.url = common.lnd_server_url + '/peers';
options.form = JSON.stringify({
addr: { host: req.body.host, pubkey: req.body.pubkey },
@ -85,6 +86,7 @@ exports.postPeer = (req, res, next) => {
};
exports.deletePeer = (req, res, next) => {
options = common.options;
options.url = common.lnd_server_url + '/peers/' + req.params.peerPubKey;
request.delete(options).then((body) => {
logger.info('\r\nPeers: 81: ' + JSON.stringify(Date.now()) + ': INFO: Detach Peer Response: ' + JSON.stringify(body));

@ -1,9 +1,10 @@
var request = require('request-promise');
var options = require("../connect");
var common = require('../common');
var logger = require('./logger');
var options = {};
exports.forwardingHistory = (req, res, next) => {
options = common.options;
options.url = common.lnd_server_url + '/switch';
options.form = {};
if (undefined !== req.body.num_max_events) {

@ -1,9 +1,10 @@
var request = require('request-promise');
var options = require("../connect");
var common = require('../common');
var logger = require('./logger');
var options = {};
exports.getTransactions = (req, res, next) => {
options = common.options;
options.url = common.lnd_server_url + '/transactions';
request(options).then((body) => {
const body_str = (undefined === body) ? '' : JSON.stringify(body);
@ -33,6 +34,7 @@ exports.getTransactions = (req, res, next) => {
};
exports.postTransactions = (req, res, next) => {
options = common.options;
options.url = common.lnd_server_url + '/transactions';
options.form = JSON.stringify({
amount: req.body.amount,

@ -1,9 +1,10 @@
var request = require('request');
var options = require("../connect");
var common = require('../common');
var logger = require('./logger');
var options = {};
exports.operateWallet = (req, res, next) => {
options = common.options;
var requestBody = {
wallet_password: Buffer.from(req.body.wallet_password).toString('base64')
};

2
package-lock.json generated

@ -1,6 +1,6 @@
{
"name": "rtl",
"version": "0.2.13-beta",
"version": "0.2.14-beta",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

@ -1,10 +1,10 @@
{
"name": "rtl",
"version": "0.2.13-beta",
"version": "0.2.14-beta",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "ng build --prod && ng serve",
"start": "ng serve",
"serve": "ng serve",
"prebuild": "node ./prebuild",
"build": "ng build --prod --base-href /rtl/",

@ -2,6 +2,7 @@ const app = require("./app");
const common = require("./common");
const debug = require("debug")("node-angular");
const http = require("http");
var connect = require('./connect'); //Do NOT Remove
const onError = error => {
if (error.syscall !== "listen") {

Loading…
Cancel
Save