Changing env-var to arguments
- Changes console.log and console.debug to relevant types - PASSWORD and I environment variables are now passed as arguments to npm commands - Added optional argument `--debug`. when passed, console.debug is also logged, else console.debug are turned off
This commit is contained in:
parent
4b26ad60bd
commit
48609bd1b7
2
.gitignore
vendored
2
.gitignore
vendored
@ -3,5 +3,7 @@
|
||||
/args/config*.json
|
||||
/args/param.json
|
||||
/args/keys*.json
|
||||
/log.txt
|
||||
/bash_start*
|
||||
*test*
|
||||
*.tmp*
|
||||
|
||||
21
README.md
21
README.md
@ -15,24 +15,17 @@ npm run create-schema - Create schema in MySQL database.
|
||||
npm start - Start the application (main).
|
||||
```
|
||||
**NOTE:**
|
||||
env variable `PASSWORD` required for `npm start`.
|
||||
|
||||
Windows:
|
||||
Argument `PASSWORD` required for `npm start`.
|
||||
```
|
||||
$env:PASSWORD="<password>"; npm start
|
||||
```
|
||||
Linux:
|
||||
```
|
||||
PASSWORD="<password"> npm start
|
||||
npm start -- -PASSWORD=<password>
|
||||
```
|
||||
*(Optional)*
|
||||
Multiple instance can be run/setup on the same dir with different config files by using env variable 'I'.
|
||||
|
||||
Windows:
|
||||
Multiple instance can be run/setup on the same dir with different config files by using argument 'I'.
|
||||
```
|
||||
$env:I="<instance_ID>"; <command>
|
||||
<command> -- -I=<instance_ID>
|
||||
```
|
||||
Linux:
|
||||
*(Optional)*
|
||||
`console.debug` is now turned off by default. pass argument `--debug` to turn it on
|
||||
```
|
||||
I="<instance_ID>" <command>
|
||||
npm start -- -PASSWORD=<password> --debug
|
||||
```
|
||||
@ -1,10 +1,8 @@
|
||||
const floGlobals = {
|
||||
|
||||
//Required for all
|
||||
blockchain: "FLO",
|
||||
application: "exchange",
|
||||
adminID: "FMxYC7gYZhouzqtHZukGnPiQ8nvG4CMzXM",
|
||||
currency: "rupee"
|
||||
};
|
||||
|
||||
('object' === typeof module) ? module.exports = floGlobals: null;
|
||||
('object' === typeof module) ? module.exports = floGlobals : null;
|
||||
@ -1,4 +1,4 @@
|
||||
(function(EXPORTS) { //floTokenAPI v1.0.3b
|
||||
(function(EXPORTS) { //floTokenAPI v1.0.3c
|
||||
/* Token Operator to send/receive tokens via blockchain using API calls*/
|
||||
'use strict';
|
||||
const tokenAPI = EXPORTS;
|
||||
@ -29,7 +29,7 @@
|
||||
|
||||
const fetch_api = tokenAPI.fetch = function(apicall) {
|
||||
return new Promise((resolve, reject) => {
|
||||
console.log(DEFAULT.apiURL + apicall);
|
||||
console.debug(DEFAULT.apiURL + apicall);
|
||||
fetch(DEFAULT.apiURL + apicall).then(response => {
|
||||
if (response.ok)
|
||||
response.json().then(data => resolve(data));
|
||||
|
||||
@ -1,9 +1,16 @@
|
||||
const fs = require('fs');
|
||||
const getInput = require('./getInput');
|
||||
|
||||
let _I = "";
|
||||
for (let arg of process.argv)
|
||||
if (/^-I=/.test(arg)) {
|
||||
_I = arg.split(/=(.*)/s)[1];
|
||||
break;
|
||||
}
|
||||
|
||||
var config, flag_new;
|
||||
try {
|
||||
config = require(`../args/config${process.env.I || ""}.json`);
|
||||
config = require(`../args/config${_I}.json`);
|
||||
flag_new = false;
|
||||
} catch (error) {
|
||||
config = {
|
||||
@ -84,7 +91,7 @@ function configure() {
|
||||
configurePort().then(port_result => {
|
||||
randomizeSessionSecret().then(secret_result => {
|
||||
configureSQL().then(sql_result => {
|
||||
fs.writeFile(__dirname + `/../args/config${process.env.I || ""}.json`, JSON.stringify(config), 'utf8', (err) => {
|
||||
fs.writeFile(__dirname + `/../args/config${_I}.json`, JSON.stringify(config), 'utf8', (err) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
return reject(false);
|
||||
|
||||
@ -1,8 +1,15 @@
|
||||
const fs = require('fs');
|
||||
let Database = require('../src/database');
|
||||
|
||||
let _I = "";
|
||||
for (let arg of process.argv)
|
||||
if (/^-I=/.test(arg)) {
|
||||
_I = arg.split(/=(.*)/s)[1];
|
||||
break;
|
||||
}
|
||||
|
||||
function createSchema() {
|
||||
const config = require(`../args/config${process.env.I || ""}.json`);
|
||||
const config = require(`../args/config${_I}.json`);
|
||||
return new Promise((resolve, reject) => {
|
||||
fs.readFile(__dirname + '/../args/schema.sql', 'utf8', (err, data) => {
|
||||
if (err) {
|
||||
|
||||
@ -14,13 +14,9 @@ npm run backup - Run the backup-node.
|
||||
|
||||
npm start - Start the application (main).
|
||||
|
||||
NOTE: env variable 'PASSWORD' required for 'npm start'.
|
||||
NOTE: argument 'PASSWORD' required for 'npm start'
|
||||
npm start -- -PASSWORD=<password>
|
||||
|
||||
WINDOWS:
|
||||
$env:PASSWORD="<password>"; npm start
|
||||
|
||||
LINUX:
|
||||
PASSWORD="<password"> npm start
|
||||
`;
|
||||
|
||||
console.log(message);
|
||||
@ -8,6 +8,13 @@ const floCrypto = require('../docs/scripts/floCrypto');
|
||||
|
||||
console.log(__dirname);
|
||||
|
||||
let _I = "";
|
||||
for (let arg of process.argv)
|
||||
if (/^-I=/.test(arg)) {
|
||||
_I = arg.split(/=(.*)/s)[1];
|
||||
break;
|
||||
}
|
||||
|
||||
function validateKey(privKey) {
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
@ -62,7 +69,7 @@ function resetPassword() {
|
||||
let encrypted = Crypto.AES.encrypt(privKey, password);
|
||||
let randNum = floCrypto.randInt(10, 15);
|
||||
let splitShares = floCrypto.createShamirsSecretShares(encrypted, randNum, randNum);
|
||||
fs.writeFile(__dirname + `/../args/keys${process.env.I || ""}.json`, JSON.stringify(splitShares), 'utf8', (err) => {
|
||||
fs.writeFile(__dirname + `/../args/keys${_I}.json`, JSON.stringify(splitShares), 'utf8', (err) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
return reject(false);
|
||||
|
||||
@ -161,7 +161,7 @@ function collectShares(floID, sinkID, share) {
|
||||
try {
|
||||
let sinkKey = floCrypto.retrieveShamirSecret([].concat(...Object.values(shares_collected[sinkID].shares)));
|
||||
if (floCrypto.verifyPrivKey(sinkKey, sinkID)) {
|
||||
console.log("Shares collected successfully for", sinkID);
|
||||
console.debug("Shares collected successfully for", sinkID);
|
||||
shares_collected[sinkID].callbacks.forEach(fn => fn instanceof Function ? fn(sinkKey) : null);
|
||||
delete shares_collected[sinkID];
|
||||
}
|
||||
@ -200,7 +200,7 @@ function connectToMaster(i = 0, init = false) {
|
||||
|
||||
//Node becomes master
|
||||
function serveAsMaster(init) {
|
||||
console.debug('Starting master process');
|
||||
console.info('Starting master process');
|
||||
slave.stop();
|
||||
_mode = MASTER_MODE;
|
||||
informLiveNodes(init);
|
||||
@ -208,7 +208,7 @@ function serveAsMaster(init) {
|
||||
}
|
||||
|
||||
function serveAsSlave(ws, init) {
|
||||
console.debug('Starting slave process');
|
||||
console.info('Starting slave process');
|
||||
app.pause();
|
||||
slave.start(ws, init);
|
||||
_mode = SLAVE_MODE;
|
||||
|
||||
@ -153,7 +153,7 @@ function storeSinkShare(sinkID, keyShare, decrypt = true) {
|
||||
if (decrypt)
|
||||
keyShare = floCrypto.decryptData(keyShare, global.myPrivKey)
|
||||
let encryptedShare = Crypto.AES.encrypt(keyShare, global.myPrivKey);
|
||||
console.log(Date.now(), '|sinkID:', sinkID, '|EnShare:', encryptedShare);
|
||||
console.debug(Date.now(), '|sinkID:', sinkID, '|EnShare:', encryptedShare);
|
||||
DB.query("INSERT INTO sinkShares (floID, share) VALUE (?) ON DUPLICATE KEY UPDATE share=?", [[sinkID, encryptedShare], encryptedShare])
|
||||
.then(_ => null).catch(error => console.error(error));
|
||||
}
|
||||
|
||||
@ -98,7 +98,7 @@ function recursiveCoupling(asset, cur_rate, flag = false) {
|
||||
}).catch(error => {
|
||||
//noBuy = error[0], noSell = error[1], reason = error[2]
|
||||
price.noOrder(asset, error[0], error[1]);
|
||||
console.error(error[2]);
|
||||
error[3] ? console.debug(error[2]) : console.error(error[2]);
|
||||
//set timeout for next coupling (if not order placement occurs)
|
||||
if (flag) {
|
||||
price.updateLastTime(asset);
|
||||
@ -145,7 +145,7 @@ function processCoupling(asset, cur_rate) {
|
||||
console.error(error.sell);
|
||||
noSell = null;
|
||||
}
|
||||
reject([noBuy, noSell, `No valid ${noSell? 'sellOrders': ''} | ${noBuy? 'buyOrders': ''} for Asset: ${asset}`]);
|
||||
reject([noBuy, noSell, `No valid ${noSell ? 'sellOrders' : ''} | ${noBuy ? 'buyOrders' : ''} for Asset: ${asset}`, true]);
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
12
src/main.js
12
src/main.js
@ -162,11 +162,17 @@ function setDB(db) {
|
||||
}
|
||||
|
||||
module.exports = function startServer(public_dir) {
|
||||
const config = require(`../args/config${process.env.I || ""}.json`);
|
||||
let _pass, _I = "";
|
||||
for (let arg of process.argv) {
|
||||
if (/^-I=/.test(arg))
|
||||
_I = arg.split(/=(.*)/s)[1];
|
||||
else if (/^-password=/i.test(arg))
|
||||
_pass = arg.split(/=(.*)/s)[1];
|
||||
}
|
||||
const config = require(`../args/config${_I}.json`);
|
||||
try {
|
||||
var _tmp = require(`../args/keys${process.env.I || ""}.json`);
|
||||
var _tmp = require(`../args/keys${_I}.json`);
|
||||
_tmp = floCrypto.retrieveShamirSecret(_tmp);
|
||||
var _pass = process.env.PASSWORD;
|
||||
if (!_pass) {
|
||||
console.error('Password not entered!');
|
||||
process.exit(1);
|
||||
|
||||
@ -501,7 +501,7 @@ function periodicProcess() {
|
||||
if (lastSyncBlockHeight < result.blocks[0].height) {
|
||||
lastSyncBlockHeight = result.blocks[0].height;
|
||||
background.process();
|
||||
console.debug("Last Block :", lastSyncBlockHeight);
|
||||
console.log("Last Block :", lastSyncBlockHeight);
|
||||
}
|
||||
}).catch(error => console.error(error));
|
||||
}
|
||||
|
||||
@ -144,7 +144,7 @@ function depositCurrencyFund(floID, txid, coin) {
|
||||
if (result.length)
|
||||
return reject(INVALID(eCode.DUPLICATE_ENTRY, "Transaction already in process"));
|
||||
DB.query("INSERT INTO ConvertFund(txid, mode, coin, r_status) VALUES (?)", [[txid, pCode.CONVERT_MODE_GET, coin, pCode.STATUS_PROCESSING]])
|
||||
.then(result => resolve("Add currency fund in process"))
|
||||
.then(result => resolve("Deposit currency fund in process"))
|
||||
.catch(error => reject(error))
|
||||
}).catch(error => reject(error))
|
||||
})
|
||||
@ -160,7 +160,7 @@ function depositCoinFund(floID, txid, coin) {
|
||||
if (result.length)
|
||||
return reject(INVALID(eCode.DUPLICATE_ENTRY, "Transaction already in process"));
|
||||
DB.query("INSERT INTO ConvertFund(txid, mode, coin, r_status) VALUES (?)", [[txid, pCode.CONVERT_MODE_PUT, coin, pCode.STATUS_PROCESSING]])
|
||||
.then(result => resolve("Add coin fund in process"))
|
||||
.then(result => resolve("Deposit coin fund in process"))
|
||||
.catch(error => reject(error))
|
||||
}).catch(error => reject(error))
|
||||
})
|
||||
@ -178,7 +178,7 @@ function withdrawCurrencyFund(floID, coin, amount) {
|
||||
if (available_amount < amount)
|
||||
return reject(INVALID(eCode.INSUFFICIENT_BALANCE, "Insufficient convert-fund deposits to withdraw"));
|
||||
DB.query("INSERT INTO ConvertFund(mode, coin, amount, r_status) VALUES (?)", [[pCode.CONVERT_MODE_PUT, coin, amount, pCode.STATUS_PENDING]])
|
||||
.then(result => resolve("Add currency fund in process"))
|
||||
.then(result => resolve("Withdraw currency fund in process"))
|
||||
.catch(error => reject(error))
|
||||
}).catch(error => reject(error))
|
||||
}).catch(error => reject(error))
|
||||
@ -197,7 +197,7 @@ function withdrawCoinFund(floID, coin, quantity) {
|
||||
if (available_quantity < quantity)
|
||||
return reject(INVALID(eCode.INSUFFICIENT_BALANCE, "Insufficient convert-fund deposits to withdraw"));
|
||||
DB.query("INSERT INTO ConvertFund(mode, coin, quantity, r_status) VALUES (?)", [[pCode.CONVERT_MODE_GET, coin, quantity, pCode.STATUS_PENDING]])
|
||||
.then(result => resolve("Add currency fund in process"))
|
||||
.then(result => resolve("Withdraw currency fund in process"))
|
||||
.catch(error => reject(error))
|
||||
}).catch(error => reject(error))
|
||||
}).catch(error => reject(error))
|
||||
|
||||
@ -13,6 +13,9 @@ try {
|
||||
global[p] = param[p];
|
||||
}
|
||||
|
||||
if (!process.argv.includes("--debug"))
|
||||
global.console.debug = () => null;
|
||||
|
||||
/*
|
||||
//Trace the debug logs in node js
|
||||
var debug = console.debug;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user