Bug fixes
- Added lastTx table to SQL schema - setup file 'reset-password' now accepts any private key (node keys) - Fixed minor SQL syntax
This commit is contained in:
parent
11b99c3e76
commit
8c1aad3d28
@ -113,6 +113,12 @@ PRIMARY KEY(id),
|
|||||||
FOREIGN KEY (floID) REFERENCES Users(floID)
|
FOREIGN KEY (floID) REFERENCES Users(floID)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE TABLE lastTx(
|
||||||
|
floID CHAR(34) NOT NULL,
|
||||||
|
num INT,
|
||||||
|
PRIMARY KEY(floID)
|
||||||
|
);
|
||||||
|
|
||||||
CREATE TABLE nodeList(
|
CREATE TABLE nodeList(
|
||||||
floID CHAR(34) NOT NULL,
|
floID CHAR(34) NOT NULL,
|
||||||
uri TINYTEXT,
|
uri TINYTEXT,
|
||||||
|
|||||||
@ -10,10 +10,15 @@ console.log(__dirname);
|
|||||||
|
|
||||||
function validateKey(privKey) {
|
function validateKey(privKey) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (floCrypto.verifyPrivKey(privKey, floGlobals.adminID))
|
try {
|
||||||
|
if (!privKey || privKey === "")
|
||||||
|
throw 'Private Key cannot be empty!';
|
||||||
|
let floID = floCrypto.getFloID(privKey);
|
||||||
|
if (!floID || !floCrypto.verifyPrivKey(privKey, floID))
|
||||||
|
throw 'Invalid Private Key!';
|
||||||
return resolve(privKey);
|
return resolve(privKey);
|
||||||
else {
|
} catch (error) {
|
||||||
getInput.Text('Incorrect Private Key! Re-Enter: (Cancel)', 'Cancel').then(value => {
|
getInput.Text(error + ' Re-Enter: (Cancel)', 'Cancel').then(value => {
|
||||||
if (value === 'Cancel')
|
if (value === 'Cancel')
|
||||||
return reject(true);
|
return reject(true);
|
||||||
validateKey(value)
|
validateKey(value)
|
||||||
@ -51,7 +56,7 @@ function getPassword() {
|
|||||||
|
|
||||||
function resetPassword() {
|
function resetPassword() {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
getInput.Text(`Enter private key for adminID (${floGlobals.adminID})`).then(value => {
|
getInput.Text(`Enter private key`).then(value => {
|
||||||
validateKey(value).then(privKey => {
|
validateKey(value).then(privKey => {
|
||||||
getPassword().then(password => {
|
getPassword().then(password => {
|
||||||
let encrypted = Crypto.AES.encrypt(privKey, password);
|
let encrypted = Crypto.AES.encrypt(privKey, password);
|
||||||
|
|||||||
27
src/main.js
27
src/main.js
@ -27,6 +27,7 @@ function refreshDataFromBlockchain() {
|
|||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
DB.query("SELECT num FROM lastTx WHERE floID=?", [floGlobals.adminID]).then(result => {
|
DB.query("SELECT num FROM lastTx WHERE floID=?", [floGlobals.adminID]).then(result => {
|
||||||
let lastTx = result.length ? result[0].num : 0;
|
let lastTx = result.length ? result[0].num : 0;
|
||||||
|
console.debug('lastTx', lastTx);
|
||||||
floBlockchainAPI.readData(floGlobals.adminID, {
|
floBlockchainAPI.readData(floGlobals.adminID, {
|
||||||
ignoreOld: lastTx,
|
ignoreOld: lastTx,
|
||||||
sentOnly: true,
|
sentOnly: true,
|
||||||
@ -37,6 +38,7 @@ function refreshDataFromBlockchain() {
|
|||||||
trusted_change = false;
|
trusted_change = false;
|
||||||
result.data.reverse().forEach(data => {
|
result.data.reverse().forEach(data => {
|
||||||
var content = JSON.parse(data)[floGlobals.application];
|
var content = JSON.parse(data)[floGlobals.application];
|
||||||
|
console.debug(content);
|
||||||
//Node List
|
//Node List
|
||||||
if (content.Nodes) {
|
if (content.Nodes) {
|
||||||
nodes_change = true;
|
nodes_change = true;
|
||||||
@ -45,7 +47,7 @@ function refreshDataFromBlockchain() {
|
|||||||
promises.push(DB.query("DELETE FROM nodeList WHERE floID=?", [n]));
|
promises.push(DB.query("DELETE FROM nodeList WHERE floID=?", [n]));
|
||||||
if (content.Nodes.add)
|
if (content.Nodes.add)
|
||||||
for (let n in content.Nodes.add)
|
for (let n in content.Nodes.add)
|
||||||
promises.push(DB.query("INSERT INTO nodeList (floID, uri) VALUE (?,?) ON DUPLICATE KEY UPDATE uri=NEW.uri", [n, content.Nodes.add[n]]));
|
promises.push(DB.query("INSERT INTO nodeList (floID, uri) VALUE (?,?) AS new ON DUPLICATE KEY UPDATE uri=new.uri", [n, content.Nodes.add[n]]));
|
||||||
}
|
}
|
||||||
//Trusted List
|
//Trusted List
|
||||||
if (content.Trusted) {
|
if (content.Trusted) {
|
||||||
@ -55,7 +57,7 @@ function refreshDataFromBlockchain() {
|
|||||||
promises.push(DB.query("DELETE FROM trustedList WHERE floID=?", [id]));
|
promises.push(DB.query("DELETE FROM trustedList WHERE floID=?", [id]));
|
||||||
if (content.Trusted.add)
|
if (content.Trusted.add)
|
||||||
for (let id of content.Trusted.add)
|
for (let id of content.Trusted.add)
|
||||||
promises.push(DB.query("INSERT INTO trustedList (floID) VALUE (?) ON DUPLICATE KEY UPDATE floID=NEW.floID", [id]));
|
promises.push(DB.query("INSERT INTO trustedList (floID) VALUE (?) AS new ON DUPLICATE KEY UPDATE floID=new.floID", [id]));
|
||||||
}
|
}
|
||||||
//Tag List with priority and API
|
//Tag List with priority and API
|
||||||
if (content.Tag) {
|
if (content.Tag) {
|
||||||
@ -64,16 +66,17 @@ function refreshDataFromBlockchain() {
|
|||||||
promises.push(DB.query("DELETE FROM TagList WHERE tag=?", [t]));
|
promises.push(DB.query("DELETE FROM TagList WHERE tag=?", [t]));
|
||||||
if (content.Tag.add)
|
if (content.Tag.add)
|
||||||
for (let t in content.Tag.add)
|
for (let t in content.Tag.add)
|
||||||
promises.push(DB.query("INSERT INTO TagList (tag, sellPriority, buyPriority, api) VALUE (?,?,?,?)", [t, content.Tag.add[t].sellPriority, content.Tag.add[t].buyPriority, content.Tag.add[t].api]));
|
promises.push(DB.query("INSERT INTO TagList (tag, sellPriority, buyPriority, api) VALUE (?,?,?,?) AS new ON DUPLICATE KEY UPDATE tag=new.tag", [t, content.Tag.add[t].sellPriority, content.Tag.add[t].buyPriority, content.Tag.add[t].api]));
|
||||||
if (content.Tag.update)
|
if (content.Tag.update)
|
||||||
for (let t in content.Tag.update)
|
for (let t in content.Tag.update)
|
||||||
for (let a in content.Tag.update[t])
|
for (let a in content.Tag.update[t])
|
||||||
promises.push(`UPDATE TagList WHERE tag=? SET ${a}=?`, [t, content.Tag.update[t][a]]);
|
promises.push(`UPDATE TagList WHERE tag=? SET ${a}=?`, [t, content.Tag.update[t][a]]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
promises.push(DB.query("INSERT INTO lastTx (floID, num) VALUE (?, ?) ON DUPLICATE KEY UPDATE num=NEW.num", [floGlobals.adminID, result.totalTxs]));
|
promises.push(DB.query("INSERT INTO lastTx (floID, num) VALUE (?, ?) AS new ON DUPLICATE KEY UPDATE num=new.num", [floGlobals.adminID, result.totalTxs]));
|
||||||
//Check if all save process were successful
|
//Check if all save process were successful
|
||||||
Promise.allSettled(promises).then(results => {
|
Promise.allSettled(promises).then(results => {
|
||||||
|
console.debug(results.filter(r => r.status === "rejected"));
|
||||||
if (results.reduce((a, r) => r.status === "rejected" ? ++a : a, 0))
|
if (results.reduce((a, r) => r.status === "rejected" ? ++a : a, 0))
|
||||||
console.warn("Some data might not have been saved in database correctly");
|
console.warn("Some data might not have been saved in database correctly");
|
||||||
});
|
});
|
||||||
@ -101,7 +104,7 @@ function loadDataFromDB(changes, startup) {
|
|||||||
|
|
||||||
loadDataFromDB.nodeList = function() {
|
loadDataFromDB.nodeList = function() {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
DB.query("SELECT (floID, uri) FROM nodeList").then(result => {
|
DB.query("SELECT * FROM nodeList").then(result => {
|
||||||
let nodes = {}
|
let nodes = {}
|
||||||
for (let i in result)
|
for (let i in result)
|
||||||
nodes[result[i].floID] = result[i].uri;
|
nodes[result[i].floID] = result[i].uri;
|
||||||
@ -140,15 +143,11 @@ module.exports = function startServer(public_dir) {
|
|||||||
console.error('Password not entered!');
|
console.error('Password not entered!');
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
_tmp = Crypto.AES.decrypt(_tmp, _pass);
|
global.myPrivKey = Crypto.AES.decrypt(_tmp, _pass);
|
||||||
if (floCrypto.verifyPrivKey(_tmp, floGlobals.adminID)) {
|
global.myPubKey = floCrypto.getPubKeyHex(global.myPrivKey);
|
||||||
global.myPrivKey = _tmp;
|
global.myFloID = floCrypto.getFloID(global.myPubKey);
|
||||||
global.myPubKey = floCrypto.getPubKeyHex(global.myPrivKey);
|
if (!global.myFloID || !global.myPubKey || !global.myPrivKey)
|
||||||
global.myFloID = floCrypto.getFloID(global.myPubKey);
|
throw "Invalid Keys";
|
||||||
} else {
|
|
||||||
console.error('Loaded wrong private key!');
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Unable to load private key!');
|
console.error('Unable to load private key!');
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user