Merge branch 'sairajzero:main' into main
This commit is contained in:
commit
9fa8c683bc
@ -1,13 +1,23 @@
|
|||||||
|
/* Node data */
|
||||||
TRUNCATE _backup;
|
TRUNCATE _backup;
|
||||||
TRUNCATE buyorder;
|
TRUNCATE auditTransaction;
|
||||||
TRUNCATE cash;
|
TRUNCATE BuyOrder;
|
||||||
TRUNCATE inputflo;
|
TRUNCATE Cash;
|
||||||
TRUNCATE inputrupee;
|
TRUNCATE inputFLO;
|
||||||
TRUNCATE outputflo;
|
TRUNCATE inputRupee;
|
||||||
TRUNCATE outputrupee;
|
TRUNCATE outputFLO;
|
||||||
TRUNCATE request_log;
|
TRUNCATE outputRupee;
|
||||||
TRUNCATE sellorder;
|
TRUNCATE priceHistory;
|
||||||
TRUNCATE sessions;
|
TRUNCATE Request_Log;
|
||||||
TRUNCATE transactions;
|
TRUNCATE SellOrder;
|
||||||
TRUNCATE users;
|
TRUNCATE Sessions;
|
||||||
TRUNCATE vault;
|
TRUNCATE Tags;
|
||||||
|
TRUNCATE Transactions;
|
||||||
|
TRUNCATE Vault;
|
||||||
|
TRUNCATE Users;
|
||||||
|
|
||||||
|
/* Blockchain data */
|
||||||
|
TRUNCATE lastTx;
|
||||||
|
TRUNCATE nodeList;
|
||||||
|
TRUNCATE trustedList;
|
||||||
|
TRUNCATE TagList;
|
||||||
10
public/fn.js
10
public/fn.js
@ -52,7 +52,7 @@ const tokenAPI = {
|
|||||||
}).catch(error => reject(error))
|
}).catch(error => reject(error))
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
sendToken: function(privKey, amount, message = "", receiverID = floGlobals.adminID, token = 'rupee') {
|
sendToken: function(privKey, amount, receiverID, message = "", token = 'rupee') {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let senderID = floCrypto.getFloID(privKey);
|
let senderID = floCrypto.getFloID(privKey);
|
||||||
if (typeof amount !== "number" || amount <= 0)
|
if (typeof amount !== "number" || amount <= 0)
|
||||||
@ -364,11 +364,11 @@ function cancelOrder(type, id, floID, proxySecret) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function depositFLO(quantity, floID, privKey, proxySecret) {
|
function depositFLO(quantity, floID, sinkID, privKey, proxySecret) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (typeof quantity !== "number" || quantity <= floGlobals.fee)
|
if (typeof quantity !== "number" || quantity <= floGlobals.fee)
|
||||||
return reject(`Invalid quantity (${quantity})`);
|
return reject(`Invalid quantity (${quantity})`);
|
||||||
floBlockchainAPI.sendTx(floID, floGlobals.adminID, quantity, privKey, 'Deposit FLO in market').then(txid => {
|
floBlockchainAPI.sendTx(floID, sinkID, quantity, privKey, 'Deposit FLO in market').then(txid => {
|
||||||
let request = {
|
let request = {
|
||||||
floID: floID,
|
floID: floID,
|
||||||
txid: txid,
|
txid: txid,
|
||||||
@ -422,11 +422,11 @@ function withdrawFLO(quantity, floID, proxySecret) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function depositRupee(quantity, floID, privKey, proxySecret) {
|
function depositRupee(quantity, floID, sinkID, privKey, proxySecret) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (!floCrypto.verifyPrivKey(privKey, floID))
|
if (!floCrypto.verifyPrivKey(privKey, floID))
|
||||||
return reject("Invalid Private Key");
|
return reject("Invalid Private Key");
|
||||||
tokenAPI.sendToken(privKey, quantity, 'Deposit Rupee in market').then(txid => {
|
tokenAPI.sendToken(privKey, quantity, sinkID, 'Deposit Rupee in market').then(txid => {
|
||||||
let request = {
|
let request = {
|
||||||
floID: floID,
|
floID: floID,
|
||||||
txid: txid,
|
txid: txid,
|
||||||
|
|||||||
@ -382,6 +382,7 @@
|
|||||||
<h4 id="wallet_popup__title" class="capitalize"></h4>
|
<h4 id="wallet_popup__title" class="capitalize"></h4>
|
||||||
</header>
|
</header>
|
||||||
<sm-form id="wallet_form">
|
<sm-form id="wallet_form">
|
||||||
|
<input type="text" id="sink_id" style="display: none;" hidden />
|
||||||
<sm-input id="get_user_amount" variant="outlined" placeholder="Quantity" type="number" min="0.01"
|
<sm-input id="get_user_amount" variant="outlined" placeholder="Quantity" type="number" min="0.01"
|
||||||
step="0.00001" required hiderequired animate>
|
step="0.00001" required hiderequired animate>
|
||||||
</sm-input>
|
</sm-input>
|
||||||
@ -1194,9 +1195,9 @@
|
|||||||
if (type === 'deposit') {
|
if (type === 'deposit') {
|
||||||
const privKey = getRef('get_private_key').value;
|
const privKey = getRef('get_private_key').value;
|
||||||
if (asset === 'FLO') {
|
if (asset === 'FLO') {
|
||||||
await depositFLO(quantity, proxy.userID, privKey, proxySecret)
|
await depositFLO(quantity, proxy.userID, proxy.sinkID, privKey, proxySecret)
|
||||||
} else {
|
} else {
|
||||||
await depositRupee(quantity, proxy.userID, privKey, proxySecret)
|
await depositRupee(quantity, proxy.userID, proxy.sinkID, privKey, proxySecret)
|
||||||
}
|
}
|
||||||
showWalletResult('success', `Sent ${asset} deposit request`, 'This may take upto 30 mins to reflect in your wallet.')
|
showWalletResult('success', `Sent ${asset} deposit request`, 'This may take upto 30 mins to reflect in your wallet.')
|
||||||
} else {
|
} else {
|
||||||
@ -1565,6 +1566,9 @@
|
|||||||
this.private = null;
|
this.private = null;
|
||||||
this.public = null;
|
this.public = null;
|
||||||
},
|
},
|
||||||
|
get sinkID(){
|
||||||
|
return getRef("sink_id").value;
|
||||||
|
},
|
||||||
set userID(id){
|
set userID(id){
|
||||||
localStorage.setItem("user_ID", id);
|
localStorage.setItem("user_ID", id);
|
||||||
this.user = id;
|
this.user = id;
|
||||||
@ -1680,6 +1684,7 @@
|
|||||||
document.querySelectorAll(".user-content").forEach(elem => elem.classList.remove('hide-completely'))
|
document.querySelectorAll(".user-content").forEach(elem => elem.classList.remove('hide-completely'))
|
||||||
getRef('trade_form').classList.remove('hide-completely')
|
getRef('trade_form').classList.remove('hide-completely')
|
||||||
getRef("user_id").value = acc.floID;
|
getRef("user_id").value = acc.floID;
|
||||||
|
getRef("sink_id").value = acc.sinkID;
|
||||||
//FLO Balance
|
//FLO Balance
|
||||||
let flo_total = acc.coins.reduce((a, x) => a + x.quantity, 0);
|
let flo_total = acc.coins.reduce((a, x) => a + x.quantity, 0);
|
||||||
let flo_locked = acc.sellOrders.reduce((a, x) => a + x.quantity, 0);
|
let flo_locked = acc.sellOrders.reduce((a, x) => a + x.quantity, 0);
|
||||||
|
|||||||
@ -13,7 +13,7 @@ function createSchema() {
|
|||||||
let txQueries = data.split(';');
|
let txQueries = data.split(';');
|
||||||
txQueries.pop();
|
txQueries.pop();
|
||||||
txQueries = txQueries.map(q => q.trim().replace(/\n/g, ' '));
|
txQueries = txQueries.map(q => q.trim().replace(/\n/g, ' '));
|
||||||
console.log(txQueries);
|
//console.log(txQueries);
|
||||||
DB.transaction(txQueries).then(_ => {
|
DB.transaction(txQueries).then(_ => {
|
||||||
console.log('SQL Schema created successfully!');
|
console.log('SQL Schema created successfully!');
|
||||||
resolve(true);
|
resolve(true);
|
||||||
|
|||||||
@ -276,9 +276,10 @@ function informLiveNodes(init) {
|
|||||||
} else
|
} else
|
||||||
console.warn(`Node(${nodes[i]}) is offline`);
|
console.warn(`Node(${nodes[i]}) is offline`);
|
||||||
if (init) {
|
if (init) {
|
||||||
if (flag === true)
|
if (flag === true) {
|
||||||
collectShares.active = true;
|
collectShares.active = true;
|
||||||
else {
|
syncRequest();
|
||||||
|
} else {
|
||||||
//No other node is active (possible 1st node to start exchange)
|
//No other node is active (possible 1st node to start exchange)
|
||||||
console.debug("Starting the exchange...")
|
console.debug("Starting the exchange...")
|
||||||
let newSink = generateNewSink();
|
let newSink = generateNewSink();
|
||||||
@ -294,8 +295,19 @@ function informLiveNodes(init) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function syncRequest(cur = global.myFloID) {
|
||||||
|
//Sync data from next available node
|
||||||
|
console.debug("syncRequest", cur);
|
||||||
|
let nextNode = nodeKBucket.nextNode(cur);
|
||||||
|
if (!nextNode)
|
||||||
|
return console.warn("No nodes available to Sync");
|
||||||
|
connectWS(nextNode)
|
||||||
|
.then(ws => slave.syncRequest(ws))
|
||||||
|
.catch(_ => syncRequest(nextNode));
|
||||||
|
}
|
||||||
|
|
||||||
function updateMaster(floID) {
|
function updateMaster(floID) {
|
||||||
let currentMaster = mod === MASTER_MODE ? global.floID : slave.masterWS.floID;
|
let currentMaster = mod === MASTER_MODE ? global.myFloID : slave.masterWS.floID;
|
||||||
if (nodeList.indexOf(floID) < nodeList.indexOf(currentMaster))
|
if (nodeList.indexOf(floID) < nodeList.indexOf(currentMaster))
|
||||||
connectToMaster();
|
connectToMaster();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const WAIT_TIME = 30 * 60 * 1000,
|
const WAIT_TIME = 10 * 60 * 1000,
|
||||||
BACKUP_INTERVAL = 10 * 60 * 1000;
|
BACKUP_INTERVAL = 1 * 60 * 1000;
|
||||||
|
|
||||||
var DB; //Container for Database connection
|
var DB; //Container for Database connection
|
||||||
var masterWS = null; //Container for Master websocket connection
|
var masterWS = null; //Container for Master websocket connection
|
||||||
@ -17,7 +17,7 @@ function startSlaveProcess(ws) {
|
|||||||
masterWS = ws;
|
masterWS = ws;
|
||||||
//inform master
|
//inform master
|
||||||
let message = {
|
let message = {
|
||||||
floID: global.floID,
|
floID: global.myFloID,
|
||||||
pubKey: global.pubKey,
|
pubKey: global.pubKey,
|
||||||
req_time: Date.now(),
|
req_time: Date.now(),
|
||||||
type: "SLAVE_CONNECT"
|
type: "SLAVE_CONNECT"
|
||||||
@ -46,11 +46,11 @@ function requestBackupSync(ws) {
|
|||||||
Users: "created",
|
Users: "created",
|
||||||
Request_Log: "request_time",
|
Request_Log: "request_time",
|
||||||
Transactions: "tx_time",
|
Transactions: "tx_time",
|
||||||
priceHistory: "rec_time",
|
//priceHistory: "rec_time",
|
||||||
_backup: "timestamp"
|
_backup: "timestamp"
|
||||||
};
|
};
|
||||||
let subs = [];
|
let subs = [];
|
||||||
for (t in tables)
|
for (let t in tables)
|
||||||
subs.push(`SELECT MAX(${tables[t]}) as ts FROM ${t}`);
|
subs.push(`SELECT MAX(${tables[t]}) as ts FROM ${t}`);
|
||||||
DB.query(`SELECT MAX(ts) as last_time FROM (${subs.join(' UNION ')}) AS Z`).then(result => {
|
DB.query(`SELECT MAX(ts) as last_time FROM (${subs.join(' UNION ')}) AS Z`).then(result => {
|
||||||
let request = {
|
let request = {
|
||||||
@ -61,7 +61,6 @@ function requestBackupSync(ws) {
|
|||||||
req_time: Date.now()
|
req_time: Date.now()
|
||||||
};
|
};
|
||||||
request.sign = floCrypto.signData(request.type + "|" + request.req_time, global.myPrivKey);
|
request.sign = floCrypto.signData(request.type + "|" + request.req_time, global.myPrivKey);
|
||||||
console.debug("REQUEST: ", request);
|
|
||||||
ws.send(JSON.stringify(request));
|
ws.send(JSON.stringify(request));
|
||||||
resolve(request);
|
resolve(request);
|
||||||
}).catch(error => reject(error))
|
}).catch(error => reject(error))
|
||||||
@ -77,10 +76,11 @@ const requestInstance = {
|
|||||||
add_data: null,
|
add_data: null,
|
||||||
total_add: null,
|
total_add: null,
|
||||||
request: null,
|
request: null,
|
||||||
|
onetime: null,
|
||||||
last_response_time: null
|
last_response_time: null
|
||||||
};
|
};
|
||||||
|
|
||||||
requestInstance.open = function() {
|
requestInstance.open = function(ws = null) {
|
||||||
const self = this;
|
const self = this;
|
||||||
//Check if there is an active request
|
//Check if there is an active request
|
||||||
if (self.request) {
|
if (self.request) {
|
||||||
@ -90,16 +90,25 @@ requestInstance.open = function() {
|
|||||||
else
|
else
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!masterWS)
|
//Use websocket connection if passed, else use masterWS if available
|
||||||
return console.warn("Not connected to master");
|
if (ws) {
|
||||||
requestBackupSync(masterWS).then(request => {
|
ws.on('message', processDataFromMaster);
|
||||||
|
self.onetime = true;
|
||||||
|
} else if (masterWS)
|
||||||
|
ws = masterWS;
|
||||||
|
else return console.warn("Not connected to master");
|
||||||
|
|
||||||
|
requestBackupSync(ws).then(request => {
|
||||||
self.request = request;
|
self.request = request;
|
||||||
self.ws = masterWS;
|
self.ws = ws;
|
||||||
}).catch(error => console.error(error))
|
}).catch(error => console.error(error))
|
||||||
}
|
}
|
||||||
|
|
||||||
requestInstance.close = function() {
|
requestInstance.close = function() {
|
||||||
const self = this;
|
const self = this;
|
||||||
|
if (self.onetime)
|
||||||
|
self.ws.close();
|
||||||
|
self.onetime = null;
|
||||||
self.ws = null;
|
self.ws = null;
|
||||||
self.delete_sync = null;
|
self.delete_sync = null;
|
||||||
self.add_sync = null;
|
self.add_sync = null;
|
||||||
@ -215,9 +224,11 @@ function deleteData(data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function addUpdateData(table, data) {
|
function addUpdateData(table, data) {
|
||||||
|
if (!data.length)
|
||||||
|
return;
|
||||||
let cols = Object.keys(data[0]),
|
let cols = Object.keys(data[0]),
|
||||||
_mark = "(" + Array(cols.length).fill('?') + ")";
|
_mark = "(" + Array(cols.length).fill('?') + ")";
|
||||||
values = data.map(r => cols.map(c => validateValue(r[c]))).flat();
|
let values = data.map(r => cols.map(c => validateValue(r[c]))).flat();
|
||||||
let statement = `INSERT INTO ${table} (${cols}) VALUES ${Array(data.length).fill(_mark)} AS new` +
|
let statement = `INSERT INTO ${table} (${cols}) VALUES ${Array(data.length).fill(_mark)} AS new` +
|
||||||
" ON DUPLICATE KEY UPDATE " + cols.filter(c => c != 'id').map(c => c + " = new." + c);
|
" ON DUPLICATE KEY UPDATE " + cols.filter(c => c != 'id').map(c => c + " = new." + c);
|
||||||
DB.query(statement, values).then(_ => null).catch(error => console.error(error));
|
DB.query(statement, values).then(_ => null).catch(error => console.error(error));
|
||||||
@ -231,7 +242,7 @@ function addImmutableData(table, data) {
|
|||||||
};
|
};
|
||||||
let cols = Object.keys(data[0]),
|
let cols = Object.keys(data[0]),
|
||||||
_mark = "(" + Array(cols.length).fill('?') + ")";
|
_mark = "(" + Array(cols.length).fill('?') + ")";
|
||||||
values = data.map(r => cols.map(c => validateValue(r[c]))).flat();
|
let values = data.map(r => cols.map(c => validateValue(r[c]))).flat();
|
||||||
let statement = `INSERT INTO ${table} (${cols}) VALUES ${Array(data.length).fill(_mark)}`;
|
let statement = `INSERT INTO ${table} (${cols}) VALUES ${Array(data.length).fill(_mark)}`;
|
||||||
if (table in primaryKeys)
|
if (table in primaryKeys)
|
||||||
statement += ` ON DUPLICATE KEY UPDATE ${primaryKeys[table]}=${primaryKeys[table]}`;
|
statement += ` ON DUPLICATE KEY UPDATE ${primaryKeys[table]}=${primaryKeys[table]}`;
|
||||||
@ -248,5 +259,6 @@ module.exports = {
|
|||||||
return masterWS;
|
return masterWS;
|
||||||
},
|
},
|
||||||
start: startSlaveProcess,
|
start: startSlaveProcess,
|
||||||
stop: stopSlaveProcess
|
stop: stopSlaveProcess,
|
||||||
|
syncRequest: ws => requestInstance.open(ws)
|
||||||
}
|
}
|
||||||
@ -278,6 +278,7 @@ function Account(req, res) {
|
|||||||
timestamp: data.timestamp
|
timestamp: data.timestamp
|
||||||
}, data.sign, data.floID).then(req_str => {
|
}, data.sign, data.floID).then(req_str => {
|
||||||
market.getAccountDetails(data.floID).then(result => {
|
market.getAccountDetails(data.floID).then(result => {
|
||||||
|
result.sinkID = global.sinkID;
|
||||||
if (trustedIDs.includes(data.floID))
|
if (trustedIDs.includes(data.floID))
|
||||||
result.subAdmin = true;
|
result.subAdmin = true;
|
||||||
res.send(result);
|
res.send(result);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user