Bug fixes

- Fixed: get-sink, generate-sink, reshare-sink, discard-sink API not working
- Fixed:  API not working
- Fixed: SQL syntax in to_refund_sql in verifyConvert for timeout requests
- Fixed: key management init not invoked
- Fixed: Minor bug in getConvertValues. Also, have null value if not available.
- Added console.debug to rejected promise (SQL write) on readDataFromBlockchain in Blockchain bonds and Bob's fund
This commit is contained in:
sairajzero 2022-11-16 21:57:10 +05:30
parent c911ca671e
commit 506087e856
8 changed files with 120 additions and 107 deletions

View File

@ -610,7 +610,7 @@
exchangeAPI.getSink = function (service = serviceList.EXCHANGE) {
return new Promise((resolve, reject) => {
if (!(service in serviceList))
if (!(Object.values(serviceList).includes(service)))
return reject(ExchangeError(ExchangeError.BAD_REQUEST_CODE, 'service required', errorCode.INVALID_VALUE));
fetch_api('/get-sink?service=' + service)
.then(result => {
@ -1559,6 +1559,7 @@
}
exchangeAPI.generateSink = function (group, floID, privKey) {
return new Promise((resolve, reject) => {
if (!floCrypto.verifyPrivKey(privKey, floID))
return reject(ExchangeError(ExchangeError.BAD_REQUEST_CODE, "Invalid Private Key", errorCode.INVALID_PRIVATE_KEY));
if (floID !== DEFAULT.marketID)
@ -1587,9 +1588,11 @@
.then(result => resolve(result))
.catch(error => reject(error))
}).catch(error => reject(error))
})
}
exchangeAPI.reshareSink = function (sinkID, floID, privKey) {
return new Promise((resolve, reject) => {
if (!floCrypto.verifyPrivKey(privKey, floID))
return reject(ExchangeError(ExchangeError.BAD_REQUEST_CODE, "Invalid Private Key", errorCode.INVALID_PRIVATE_KEY));
if (floID !== DEFAULT.marketID)
@ -1618,9 +1621,11 @@
.then(result => resolve(result))
.catch(error => reject(error))
}).catch(error => reject(error))
})
}
exchangeAPI.discardSink = function (sinkID, floID, privKey) {
return new Promise((resolve, reject) => {
if (!floCrypto.verifyPrivKey(privKey, floID))
return reject(ExchangeError(ExchangeError.BAD_REQUEST_CODE, "Invalid Private Key", errorCode.INVALID_PRIVATE_KEY));
if (floID !== DEFAULT.marketID)
@ -1649,6 +1654,8 @@
.then(result => resolve(result))
.catch(error => reject(error))
}).catch(error => reject(error))
})
}
exchangeAPI.init = function refreshDataFromBlockchain() {

View File

@ -90,7 +90,7 @@ module.exports = function App(secret) {
//generate or discard sinks (admin only)
app.post('/generate-sink', Request.GenerateSink);
app.post('/reshare-sink', Request.DiscardSink);
app.post('/reshare-sink', Request.ReshareSink);
app.post('/discard-sink', Request.DiscardSink);
//convert from or to coin

View File

@ -221,7 +221,7 @@ function verifyConvert() {
//Set all timeout convert request to refund mode (thus, asset will be refund if tx gets confirmed later)
let req_timeout = new Date(Date.now() - REQUEST_TIMEOUT),
to_refund_sql = "INSERT INTO RefundConvert (floID, in_txid, asset_type, asset, r_status)" +
" SELECT floID, in_txid, ? AS asset_type, ? AS asset, r_status" +
" SELECT floID, in_txid, ? AS asset_type, ? AS asset, r_status FROM DirectConvert" +
" WHERE r_status=? AND locktime<? AND mode=?";
let txQueries = [];
txQueries.push([to_refund_sql, [pCode.ASSET_TYPE_TOKEN, floGlobals.currency, pCode.STATUS_PENDING, req_timeout, pCode.CONVERT_MODE_GET]]);

View File

@ -188,6 +188,8 @@ module.exports = function startServer() {
console.log("Logged in as", keys.node_id);
DB.connect(config["sql_user"], config["sql_pwd"], config["sql_db"], config["sql_host"]).then(result => {
keys.init().then(result => {
console.log(result);
app = new App(config['secret']);
refreshData(true).then(_ => {
app.start(config['port']).then(result => {
@ -196,5 +198,6 @@ module.exports = function startServer() {
setInterval(refreshData, BLOCKCHAIN_REFRESH_INTERVAL)
}).catch(error => console.error(error))
}).catch(error => console.error(error))
}).catch(error => console.error(error))
}).catch(error => console.error(error));
};

View File

@ -318,11 +318,12 @@ function GenerateSink(req, res) {
type: "generate_sink",
group: data.group,
timestamp: data.timestamp
}, () => sink.generate(group));
}, () => sink.generate(data.group));
}
function ReshareSink(req, res) {
let data = req.body;
console.debug(data)
if (data.floID !== floGlobals.adminID)
res.status(INVALID.e_code).send(INVALID.str(eCode.ACCESS_DENIED, "Access Denied"));
else if (!data.pubKey)
@ -333,7 +334,7 @@ function ReshareSink(req, res) {
type: "reshare_sink",
id: data.id,
timestamp: data.timestamp
}, () => sink.reshare(id));
}, () => sink.reshare(data.id));
}
function DiscardSink(req, res) {
@ -346,7 +347,7 @@ function DiscardSink(req, res) {
type: "discard_sink",
id: data.id,
timestamp: data.timestamp
}, () => sink.discard(id));
}, () => sink.discard(data.id));
}
function ConvertTo(req, res) {
@ -559,15 +560,15 @@ function GetSink(req, res) {
let service = req.query.service;
if (!service)
res.status(INVALID.e_code).send(INVALID.str(eCode.MISSING_PARAMETER, "Missing service parameter"));
else if (!(service in serviceList))
else if (!(Object.values(serviceList).includes(service)))
res.status(INVALID.e_code).send(INVALID.str(eCode.INVALID_VALUE, "Invalid service parameter"));
else {
let group;
switch (service) {
case serviceList[EXCHANGE]: group = keys.sink_groups.EXCHANGE; break;
case serviceList[CONVERT]: group = keys.sink_groups.CONVERT; break;
case serviceList[BLOCKCHAIN_BOND]: group = keys.sink_groups.BLOCKCHAIN_BONDS; break;
case serviceList[BOBS_FUND]: group = keys.sink_groups.BOBS_FUND; break;
case serviceList.EXCHANGE: group = keys.sink_groups.EXCHANGE; break;
case serviceList.CONVERT: group = keys.sink_groups.CONVERT; break;
case serviceList.BLOCKCHAIN_BOND: group = keys.sink_groups.BLOCKCHAIN_BONDS; break;
case serviceList.BOBS_FUND: group = keys.sink_groups.BOBS_FUND; break;
}
res.send(keys.sink_chest.active_pick(group));
}

View File

@ -237,9 +237,10 @@ function refreshBlockchainData(nodeList = []) {
}
});
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.debug(results.filter(r => r.status === "rejected"));
reject("Some fund data might not have been saved in database correctly");
}
else
DB.query("INSERT INTO LastTx (floID, num) VALUE (?) ON DUPLICATE KEY UPDATE num=?", [[bobsFund.config.adminID, result.totalTxs], result.totalTxs])
.then(_ => resolve(result.totalTxs))

View File

@ -206,9 +206,10 @@ function refreshBlockchainData(nodeList = []) {
}
});
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)) {
reject("Some bond data might not have been saved in database correctly");
console.debug(results.filter(r => r.status === "rejected"));
}
else
DB.query("INSERT INTO LastTx (floID, num) VALUE (?) ON DUPLICATE KEY UPDATE num=?", [[blockchainBond.config.adminID, result.totalTxs], result.totalTxs])
.then(_ => resolve(result.totalTxs))

View File

@ -114,16 +114,16 @@ function getConvertValues() {
result[pCode.CONVERT_MODE_GET] = { min: 0 };
result[pCode.CONVERT_MODE_GET].max = (!TO_MAX_VALUE || TO_MIN_VALUE >= coin_availability) ? coin_availability : TO_MAX_VALUE;
}
}
} else result[pCode.CONVERT_MODE_GET] = null;
if (avail.cash > 0) {
let cash_availability = avail.cash / avail.rate; //convert to coin value
if (Array.isArray(FROM_FIXED_VALUES) && FROM_FIXED_VALUES.length)
result[pCode.CONVERT_MODE_GET] = FROM_FIXED_VALUES.filter(a => a < cash_availability);
result[pCode.CONVERT_MODE_PUT] = FROM_FIXED_VALUES.filter(a => a < cash_availability);
else if (!FROM_MIN_VALUE || FROM_MIN_VALUE <= cash_availability) {
result[pCode.CONVERT_MODE_GET] = { min: 0 };
result[pCode.CONVERT_MODE_GET].max = (!FROM_MAX_VALUE || FROM_MIN_VALUE >= cash_availability) ? cash_availability : FROM_MAX_VALUE;
}
result[pCode.CONVERT_MODE_PUT] = { min: 0 };
result[pCode.CONVERT_MODE_PUT].max = (!FROM_MAX_VALUE || FROM_MIN_VALUE >= cash_availability) ? cash_availability : FROM_MAX_VALUE;
}
} else result[pCode.CONVERT_MODE_PUT] = null;
resolve(result)
}).catch(error => reject(error))
})