Bug fixes
- Fixed SQL query in checkPoolBalance - Fixed: collectAndCall not set in app - Fixed assetList not set - Fixed: confirmDepositToken not working - Fixed: confirmRefund not working - Fixed bug: verifyTx.BTC - Fixed bugs in some multi-value insert queries in SQL - Fixed various syntax bugs - Changed success logs to console.info
This commit is contained in:
parent
9e31246b42
commit
64a81fc762
@ -10,7 +10,7 @@ const {
|
|||||||
MAXIMUM_LAUNCH_SELL_CHIPS,
|
MAXIMUM_LAUNCH_SELL_CHIPS,
|
||||||
} = require('./_constants')["market"];
|
} = require('./_constants')["market"];
|
||||||
|
|
||||||
var DB; //container for database
|
var DB, assetList; //container for database and allowed assets
|
||||||
var updateBalance; // container for updateBalance function
|
var updateBalance; // container for updateBalance function
|
||||||
|
|
||||||
const verifyTx = {};
|
const verifyTx = {};
|
||||||
@ -23,7 +23,7 @@ function confirmDepositFLO() {
|
|||||||
txQueries.push(updateBalance.add(r.floID, "FLO", amount));
|
txQueries.push(updateBalance.add(r.floID, "FLO", amount));
|
||||||
txQueries.push(["UPDATE VaultTransactions SET r_status=?, amount=? WHERE id=?", [pCode.STATUS_SUCCESS, amount, r.id]]);
|
txQueries.push(["UPDATE VaultTransactions SET r_status=?, amount=? WHERE id=?", [pCode.STATUS_SUCCESS, amount, r.id]]);
|
||||||
DB.transaction(txQueries)
|
DB.transaction(txQueries)
|
||||||
.then(result => console.debug("FLO deposited:", r.floID, amount))
|
.then(result => console.info("FLO deposited:", r.floID, amount))
|
||||||
.catch(error => console.error(error))
|
.catch(error => console.error(error))
|
||||||
}).catch(error => console.error(error))
|
}).catch(error => console.error(error))
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
@ -91,10 +91,10 @@ function addSellChipsIfLaunchSeller(floID, quantity) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function confirmDepositToken() {
|
function confirmDepositToken() {
|
||||||
DB.query("SELECT id, floID, txid FROM VaultTransactions WHERE mode=? AND asset_type=? AND r_status=?", [pCode.VAULT_MODE_DEPOSIT, pCode.ASSET_TYPE_COIN, pCode.STATUS_PENDING]).then(results => {
|
DB.query("SELECT id, floID, txid FROM VaultTransactions WHERE mode=? AND asset_type=? AND r_status=?", [pCode.VAULT_MODE_DEPOSIT, pCode.ASSET_TYPE_TOKEN, pCode.STATUS_PENDING]).then(results => {
|
||||||
results.forEach(r => {
|
results.forEach(r => {
|
||||||
verifyTx.token(r.floID, r.txid).then(({ token, amount, flo_amount }) => {
|
verifyTx.token(r.floID, r.txid).then(({ token, amount, flo_amount }) => {
|
||||||
DB.query("SELECT id FROM VaultTransactions where floID=? AND mode=? AND asset=? AND asset_type=? AND txid=?", [r.floID, pCode.VAULT_MODE_DEPOSIT, "FLO", pCode.ASSET_TYPE_TOKEN, r.txid]).then(result => {
|
DB.query("SELECT id FROM VaultTransactions where floID=? AND mode=? AND asset=? AND asset_type=? AND txid=?", [r.floID, pCode.VAULT_MODE_DEPOSIT, "FLO", pCode.ASSET_TYPE_COIN, r.txid]).then(result => {
|
||||||
let txQueries = [];
|
let txQueries = [];
|
||||||
//Add the FLO balance if necessary
|
//Add the FLO balance if necessary
|
||||||
if (!result.length) {
|
if (!result.length) {
|
||||||
@ -104,7 +104,7 @@ function confirmDepositToken() {
|
|||||||
txQueries.push(["UPDATE VaultTransactions SET r_status=?, asset=?, amount=? WHERE id=?", [pCode.STATUS_SUCCESS, token, amount, r.id]]);
|
txQueries.push(["UPDATE VaultTransactions SET r_status=?, asset=?, amount=? WHERE id=?", [pCode.STATUS_SUCCESS, token, amount, r.id]]);
|
||||||
txQueries.push(updateBalance.add(r.floID, token, amount));
|
txQueries.push(updateBalance.add(r.floID, token, amount));
|
||||||
DB.transaction(txQueries)
|
DB.transaction(txQueries)
|
||||||
.then(result => console.debug("Token deposited:", r.floID, token, amount))
|
.then(result => console.info("Token deposited:", r.floID, token, amount))
|
||||||
.catch(error => console.error(error));
|
.catch(error => console.error(error));
|
||||||
}).catch(error => console.error(error));
|
}).catch(error => console.error(error));
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
@ -163,7 +163,7 @@ function confirmVaultWithdraw() {
|
|||||||
if (!tx.blockheight || !tx.confirmations) //Still not confirmed
|
if (!tx.blockheight || !tx.confirmations) //Still not confirmed
|
||||||
return;
|
return;
|
||||||
DB.query("UPDATE VaultTransactions SET r_status=? WHERE id=?", [pCode.STATUS_SUCCESS, r.id])
|
DB.query("UPDATE VaultTransactions SET r_status=? WHERE id=?", [pCode.STATUS_SUCCESS, r.id])
|
||||||
.then(result => console.debug("FLO withdrawed:", r.floID, r.amount))
|
.then(result => console.info("FLO withdrawed:", r.floID, r.amount))
|
||||||
.catch(error => console.error(error))
|
.catch(error => console.error(error))
|
||||||
}).catch(error => console.error(error));
|
}).catch(error => console.error(error));
|
||||||
else if (r.asset == "BTC")
|
else if (r.asset == "BTC")
|
||||||
@ -171,7 +171,7 @@ function confirmVaultWithdraw() {
|
|||||||
if (!tx.blockhash || !tx.confirmations) //Still not confirmed
|
if (!tx.blockhash || !tx.confirmations) //Still not confirmed
|
||||||
return;
|
return;
|
||||||
DB.query("UPDATE VaultTransactions SET r_status=? WHERE id=?", [pCode.STATUS_SUCCESS, r.id])
|
DB.query("UPDATE VaultTransactions SET r_status=? WHERE id=?", [pCode.STATUS_SUCCESS, r.id])
|
||||||
.then(result => console.debug("BTC withdrawed:", r.floID, r.amount))
|
.then(result => console.info("BTC withdrawed:", r.floID, r.amount))
|
||||||
.catch(error => console.error(error))
|
.catch(error => console.error(error))
|
||||||
}).catch(error => console.error(error));
|
}).catch(error => console.error(error));
|
||||||
} else if (r.asset_type == pCode.ASSET_TYPE_TOKEN)
|
} else if (r.asset_type == pCode.ASSET_TYPE_TOKEN)
|
||||||
@ -179,7 +179,7 @@ function confirmVaultWithdraw() {
|
|||||||
if (!tx.transactionDetails.blockheight || !tx.transactionDetails.confirmations) //Still not confirmed
|
if (!tx.transactionDetails.blockheight || !tx.transactionDetails.confirmations) //Still not confirmed
|
||||||
return;
|
return;
|
||||||
DB.query("UPDATE VaultTransactions SET r_status=? WHERE id=?", [pCode.STATUS_SUCCESS, r.id])
|
DB.query("UPDATE VaultTransactions SET r_status=? WHERE id=?", [pCode.STATUS_SUCCESS, r.id])
|
||||||
.then(result => console.debug("Token withdrawed:", r.floID, r.asset, r.amount))
|
.then(result => console.info("Token withdrawed:", r.floID, r.asset, r.amount))
|
||||||
.catch(error => console.error(error));
|
.catch(error => console.error(error));
|
||||||
}).catch(error => console.error(error));
|
}).catch(error => console.error(error));
|
||||||
})
|
})
|
||||||
@ -192,7 +192,7 @@ verifyTx.BTC = function (sender, txid) {
|
|||||||
let vin_sender = tx.inputs.filter(v => floCrypto.isSameAddr(v.address, sender))
|
let vin_sender = tx.inputs.filter(v => floCrypto.isSameAddr(v.address, sender))
|
||||||
if (!vin_sender.length)
|
if (!vin_sender.length)
|
||||||
return reject([true, "Transaction not sent by the sender"]);
|
return reject([true, "Transaction not sent by the sender"]);
|
||||||
if (vin_sender.length !== tx.vin.length)
|
if (vin_sender.length !== tx.inputs.length)
|
||||||
return reject([true, "Transaction input containes other floIDs"]);
|
return reject([true, "Transaction input containes other floIDs"]);
|
||||||
if (!tx.block_no)
|
if (!tx.block_no)
|
||||||
return reject([false, "Transaction not included in any block yet"]);
|
return reject([false, "Transaction not included in any block yet"]);
|
||||||
@ -211,7 +211,7 @@ verifyTx.BTC = function (sender, txid) {
|
|||||||
function verifyConvert() {
|
function verifyConvert() {
|
||||||
DB.query("SELECT id, floID, mode, in_txid, amount, quantity FROM DirectConvert WHERE r_status=? AND coin=?", [pCode.STATUS_PENDING, "BTC"]).then(results => {
|
DB.query("SELECT id, floID, mode, in_txid, amount, quantity FROM DirectConvert WHERE r_status=? AND coin=?", [pCode.STATUS_PENDING, "BTC"]).then(results => {
|
||||||
results.forEach(r => {
|
results.forEach(r => {
|
||||||
if (r.mode == pCodeCONVERT_MODE_GET) {
|
if (r.mode == pCode.CONVERT_MODE_GET) {
|
||||||
verifyTx.token(r.floID, r.in_txid, true).then(({ amount }) => {
|
verifyTx.token(r.floID, r.in_txid, true).then(({ amount }) => {
|
||||||
if (r.amount !== amount)
|
if (r.amount !== amount)
|
||||||
throw ([true, "Transaction amount mismatched in blockchain"]);
|
throw ([true, "Transaction amount mismatched in blockchain"]);
|
||||||
@ -224,7 +224,7 @@ function verifyConvert() {
|
|||||||
DB.query("UPDATE DirectConvert SET r_status=? WHERE id=?", [pCode.STATUS_REJECTED, r.id])
|
DB.query("UPDATE DirectConvert SET r_status=? WHERE id=?", [pCode.STATUS_REJECTED, r.id])
|
||||||
.then(_ => null).catch(error => console.error(error));
|
.then(_ => null).catch(error => console.error(error));
|
||||||
});
|
});
|
||||||
} else if (r.mode == pCodeCONVERT_MODE_PUT) {
|
} else if (r.mode == pCode.CONVERT_MODE_PUT) {
|
||||||
verifyTx.BTC(r.floID, r.in_txid).then(quantity => {
|
verifyTx.BTC(r.floID, r.in_txid).then(quantity => {
|
||||||
if (r.quantity !== quantity)
|
if (r.quantity !== quantity)
|
||||||
throw ([true, "Transaction quantity mismatched in blockchain"]);
|
throw ([true, "Transaction quantity mismatched in blockchain"]);
|
||||||
@ -245,9 +245,9 @@ function verifyConvert() {
|
|||||||
function retryConvert() {
|
function retryConvert() {
|
||||||
DB.query("SELECT id, floID, mode, amount, quantity FROM DirectConvert WHERE r_status=? AND coin=?", [pCode.STATUS_PROCESSING, "BTC"]).then(results => {
|
DB.query("SELECT id, floID, mode, amount, quantity FROM DirectConvert WHERE r_status=? AND coin=?", [pCode.STATUS_PROCESSING, "BTC"]).then(results => {
|
||||||
results.forEach(r => {
|
results.forEach(r => {
|
||||||
if (r.mode == pCodeCONVERT_MODE_GET)
|
if (r.mode == pCode.CONVERT_MODE_GET)
|
||||||
blockchain.convertToCoin.retry(r.floID, "BTC", r.quantity, r.id);
|
blockchain.convertToCoin.retry(r.floID, "BTC", r.quantity, r.id);
|
||||||
else if (r.mode == pCodeCONVERT_MODE_PUT)
|
else if (r.mode == pCode.CONVERT_MODE_PUT)
|
||||||
blockchain.convertFromCoin.retry(r.floID, r.amount, r.id)
|
blockchain.convertFromCoin.retry(r.floID, r.amount, r.id)
|
||||||
})
|
})
|
||||||
}).catch(error => console.error(error))
|
}).catch(error => console.error(error))
|
||||||
@ -256,20 +256,20 @@ function retryConvert() {
|
|||||||
function confirmConvert() {
|
function confirmConvert() {
|
||||||
DB.query("SELECT id, floID, mode, amount, quantity, out_txid FROM DirectConvert WHERE r_status=? AND coin=?", [pCode.STATUS_CONFIRMATION, "BTC"]).then(results => {
|
DB.query("SELECT id, floID, mode, amount, quantity, out_txid FROM DirectConvert WHERE r_status=? AND coin=?", [pCode.STATUS_CONFIRMATION, "BTC"]).then(results => {
|
||||||
results.forEach(r => {
|
results.forEach(r => {
|
||||||
if (r.mode == pCodeCONVERT_MODE_GET)
|
if (r.mode == pCode.CONVERT_MODE_GET)
|
||||||
btcOperator.getTx(r.out_txid).then(tx => {
|
btcOperator.getTx(r.out_txid).then(tx => {
|
||||||
if (!tx.blockhash || !tx.confirmations) //Still not confirmed
|
if (!tx.blockhash || !tx.confirmations) //Still not confirmed
|
||||||
return;
|
return;
|
||||||
DB.query("UPDATE DirectConvert SET r_status=? WHERE id=?", [pCode.STATUS_SUCCESS, r.id])
|
DB.query("UPDATE DirectConvert SET r_status=? WHERE id=?", [pCode.STATUS_SUCCESS, r.id])
|
||||||
.then(result => console.debug(`${r.floID} converted ${amount} to ${r.quantity} BTC`))
|
.then(result => console.info(`${r.floID} converted ${amount} to ${r.quantity} BTC`))
|
||||||
.catch(error => console.error(error))
|
.catch(error => console.error(error))
|
||||||
}).catch(error => console.error(error));
|
}).catch(error => console.error(error));
|
||||||
else if (r.mode == pCodeCONVERT_MODE_PUT)
|
else if (r.mode == pCode.CONVERT_MODE_PUT)
|
||||||
floTokenAPI.getTx(r.out_txid).then(tx => {
|
floTokenAPI.getTx(r.out_txid).then(tx => {
|
||||||
if (!tx.transactionDetails.blockheight || !tx.transactionDetails.confirmations) //Still not confirmed
|
if (!tx.transactionDetails.blockheight || !tx.transactionDetails.confirmations) //Still not confirmed
|
||||||
return;
|
return;
|
||||||
DB.query("UPDATE DirectConvert SET r_status=? WHERE id=?", [pCode.STATUS_SUCCESS, r.id])
|
DB.query("UPDATE DirectConvert SET r_status=? WHERE id=?", [pCode.STATUS_SUCCESS, r.id])
|
||||||
.then(result => console.debug(`${r.floID} converted ${r.quantity} BTC to ${amount}`))
|
.then(result => console.info(`${r.floID} converted ${r.quantity} BTC to ${amount}`))
|
||||||
.catch(error => console.error(error));
|
.catch(error => console.error(error));
|
||||||
}).catch(error => console.error(error));
|
}).catch(error => console.error(error));
|
||||||
})
|
})
|
||||||
@ -277,22 +277,24 @@ function confirmConvert() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function verifyConvertFundDeposit() {
|
function verifyConvertFundDeposit() {
|
||||||
DB.query("SELECT id, mode, txid FROM ConvertFund WHERE r_status=? AND coin=?", [pCode.STATUS_PROCESSING, "BTC"]).then(results => {
|
DB.query("SELECT id, mode, txid, coin FROM ConvertFund WHERE r_status=? AND coin=?", [pCode.STATUS_PROCESSING, "BTC"]).then(results => {
|
||||||
results.forEach(r => {
|
results.forEach(r => {
|
||||||
if (r.mode == pCodeCONVERT_MODE_GET) { //deposit currency
|
if (r.mode == pCode.CONVERT_MODE_GET) { //deposit currency
|
||||||
verifyTx.token(floGlobals.adminID, r.txid, true).then(({ amount }) => {
|
verifyTx.token(floGlobals.adminID, r.txid, true).then(({ amount }) => {
|
||||||
DB.query("UPDATE ConvertFund SET r_status=?, amount=? WHERE id=?", [pCode.STATUS_SUCCESS, amount, r.id])
|
DB.query("UPDATE ConvertFund SET r_status=?, amount=? WHERE id=?", [pCode.STATUS_SUCCESS, amount, r.id])
|
||||||
.then(_ => null).catch(error => console.error(error));
|
.then(result => console.info(`Deposit-fund ${amount} ${floGlobals.currency} successful`))
|
||||||
|
.catch(error => console.error(error));
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
if (error[0])
|
if (error[0])
|
||||||
DB.query("UPDATE ConvertFund SET r_status=? WHERE id=?", [pCode.STATUS_REJECTED, r.id])
|
DB.query("UPDATE ConvertFund SET r_status=? WHERE id=?", [pCode.STATUS_REJECTED, r.id])
|
||||||
.then(_ => null).catch(error => console.error(error));
|
.then(_ => null).catch(error => console.error(error));
|
||||||
});
|
});
|
||||||
} else if (r.mode == pCodeCONVERT_MODE_PUT) {//deposit coin
|
} else if (r.mode == pCode.CONVERT_MODE_PUT) {//deposit coin
|
||||||
verifyTx.BTC(floGlobals.adminID, r.txid).then(quantity => {
|
verifyTx.BTC(floGlobals.adminID, r.txid).then(quantity => {
|
||||||
DB.query("UPDATE ConvertFund SET r_status=?, quantity=? WHERE id=?", [pCode.STATUS_SUCCESS, quantity, r.id])
|
DB.query("UPDATE ConvertFund SET r_status=?, quantity=? WHERE id=?", [pCode.STATUS_SUCCESS, quantity, r.id])
|
||||||
.then(_ => null).catch(error => console.error(error));
|
.then(result => console.info(`Deposit-fund ${quantity} ${r.coin} successful`))
|
||||||
|
.catch(error => console.error(error));
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
if (error[0])
|
if (error[0])
|
||||||
@ -307,9 +309,9 @@ function verifyConvertFundDeposit() {
|
|||||||
function retryConvertFundWithdraw() {
|
function retryConvertFundWithdraw() {
|
||||||
DB.query("SELECT id, mode, coin, quantity, amount FROM ConvertFund WHERE r_status=? AND coin=?", [pCode.STATUS_PENDING, "BTC"]).then(results => {
|
DB.query("SELECT id, mode, coin, quantity, amount FROM ConvertFund WHERE r_status=? AND coin=?", [pCode.STATUS_PENDING, "BTC"]).then(results => {
|
||||||
results.forEach(r => {
|
results.forEach(r => {
|
||||||
if (r.mode == pCodeCONVERT_MODE_GET) //withdraw coin
|
if (r.mode == pCode.CONVERT_MODE_GET) //withdraw coin
|
||||||
blockchain.convertFundWithdraw.retry(r.coin, r.quantity, r.id);
|
blockchain.convertFundWithdraw.retry(r.coin, r.quantity, r.id);
|
||||||
else if (r.mode == pCodeCONVERT_MODE_PUT) //withdraw currency
|
else if (r.mode == pCode.CONVERT_MODE_PUT) //withdraw currency
|
||||||
blockchain.convertFundWithdraw.retry(floGlobals.currency, r.amount, r.id);
|
blockchain.convertFundWithdraw.retry(floGlobals.currency, r.amount, r.id);
|
||||||
})
|
})
|
||||||
}).catch(error => console.error(error))
|
}).catch(error => console.error(error))
|
||||||
@ -318,20 +320,20 @@ function retryConvertFundWithdraw() {
|
|||||||
function confirmConvertFundWithdraw() {
|
function confirmConvertFundWithdraw() {
|
||||||
DB.query("SELECT * FROM ConvertFund WHERE r_status=? AND coin=?", [pCode.STATUS_CONFIRMATION, "BTC"]).then(results => {
|
DB.query("SELECT * FROM ConvertFund WHERE r_status=? AND coin=?", [pCode.STATUS_CONFIRMATION, "BTC"]).then(results => {
|
||||||
results.forEach(r => {
|
results.forEach(r => {
|
||||||
if (r.mode == pCodeCONVERT_MODE_GET) { //withdraw coin
|
if (r.mode == pCode.CONVERT_MODE_GET) { //withdraw coin
|
||||||
btcOperator.getTx(r.txid).then(tx => {
|
btcOperator.getTx(r.txid).then(tx => {
|
||||||
if (!tx.blockhash || !tx.confirmations) //Still not confirmed
|
if (!tx.blockhash || !tx.confirmations) //Still not confirmed
|
||||||
return;
|
return;
|
||||||
DB.query("UPDATE ConvertFund SET r_status=? WHERE id=?", [pCode.STATUS_SUCCESS, r.id])
|
DB.query("UPDATE ConvertFund SET r_status=? WHERE id=?", [pCode.STATUS_SUCCESS, r.id])
|
||||||
.then(result => console.debug(`Withdraw-fund ${r.quantity} ${r.coin} successful`))
|
.then(result => console.info(`Withdraw-fund ${r.quantity} ${r.coin} successful`))
|
||||||
.catch(error => console.error(error))
|
.catch(error => console.error(error))
|
||||||
}).catch(error => console.error(error));
|
}).catch(error => console.error(error));
|
||||||
} else if (r.mode == pCodeCONVERT_MODE_PUT) {//withdraw currency
|
} else if (r.mode == pCode.CONVERT_MODE_PUT) {//withdraw currency
|
||||||
floTokenAPI.getTx(r.txid).then(tx => {
|
floTokenAPI.getTx(r.txid).then(tx => {
|
||||||
if (!tx.transactionDetails.blockheight || !tx.transactionDetails.confirmations) //Still not confirmed
|
if (!tx.transactionDetails.blockheight || !tx.transactionDetails.confirmations) //Still not confirmed
|
||||||
return;
|
return;
|
||||||
DB.query("UPDATE ConvertFund SET r_status=? WHERE id=?", [pCode.STATUS_SUCCESS, r.id])
|
DB.query("UPDATE ConvertFund SET r_status=? WHERE id=?", [pCode.STATUS_SUCCESS, r.id])
|
||||||
.then(result => console.debug(`Withdraw-fund ${r.amount} ${floGlobals.currency} successful`))
|
.then(result => console.info(`Withdraw-fund ${r.amount} ${floGlobals.currency} successful`))
|
||||||
.catch(error => console.error(error));
|
.catch(error => console.error(error));
|
||||||
}).catch(error => console.error(error));
|
}).catch(error => console.error(error));
|
||||||
}
|
}
|
||||||
@ -363,11 +365,11 @@ function retryRefund() {
|
|||||||
function confirmRefund() {
|
function confirmRefund() {
|
||||||
DB.query("SELECT * FROM RefundTransact WHERE r_status=?", [pCode.STATUS_CONFIRMATION]).then(results => {
|
DB.query("SELECT * FROM RefundTransact WHERE r_status=?", [pCode.STATUS_CONFIRMATION]).then(results => {
|
||||||
results.forEach(r => {
|
results.forEach(r => {
|
||||||
floTokenAPI.getTx(r.txid).then(tx => {
|
floTokenAPI.getTx(r.out_txid).then(tx => {
|
||||||
if (!tx.transactionDetails.blockheight || !tx.transactionDetails.confirmations) //Still not confirmed
|
if (!tx.transactionDetails.blockheight || !tx.transactionDetails.confirmations) //Still not confirmed
|
||||||
return;
|
return;
|
||||||
DB.query("UPDATE RefundTransact SET r_status=? WHERE id=?", [pCode.STATUS_SUCCESS, r.id])
|
DB.query("UPDATE RefundTransact SET r_status=? WHERE id=?", [pCode.STATUS_SUCCESS, r.id])
|
||||||
.then(result => console.debug(`Refunded ${r.amount} to ${r.floID}`))
|
.then(result => console.info(`Refunded ${r.amount} to ${r.floID}`))
|
||||||
.catch(error => console.error(error));
|
.catch(error => console.error(error));
|
||||||
}).catch(error => console.error(error));
|
}).catch(error => console.error(error));
|
||||||
})
|
})
|
||||||
@ -389,7 +391,7 @@ function confirmBondClosing() {
|
|||||||
let closeBondString = bond_util.stringify.end(r.bond_id, r.end_date, r.btc_net, r.usd_net, r.amount, r.ref_sign, r.txid);
|
let closeBondString = bond_util.stringify.end(r.bond_id, r.end_date, r.btc_net, r.usd_net, r.amount, r.ref_sign, r.txid);
|
||||||
floBlockchainAPI.writeData(global.myFloID, closeBondString, global.myPrivKey, bond_util.config.adminID).then(txid => {
|
floBlockchainAPI.writeData(global.myFloID, closeBondString, global.myPrivKey, bond_util.config.adminID).then(txid => {
|
||||||
DB.query("UPDATE CloseBondTransact SET r_status=?, close_id=? WHERE id=?", [pCode.STATUS_SUCCESS, txid, r.id])
|
DB.query("UPDATE CloseBondTransact SET r_status=?, close_id=? WHERE id=?", [pCode.STATUS_SUCCESS, txid, r.id])
|
||||||
.then(result => console.debug("Bond closed:", r.bond_id))
|
.then(result => console.info("Bond closed:", r.bond_id))
|
||||||
.catch(error => console.error(error));
|
.catch(error => console.error(error));
|
||||||
}).catch(error => console.error(error))
|
}).catch(error => console.error(error))
|
||||||
}).catch(error => console.error(error));
|
}).catch(error => console.error(error));
|
||||||
@ -412,7 +414,7 @@ function confirmFundClosing() {
|
|||||||
let closeFundString = fund_util.stringify.end(r.fund_id, r.floID, r.end_date, r.btc_net, r.usd_net, r.amount, r.ref_sign, r.txid);
|
let closeFundString = fund_util.stringify.end(r.fund_id, r.floID, r.end_date, r.btc_net, r.usd_net, r.amount, r.ref_sign, r.txid);
|
||||||
floBlockchainAPI.writeData(global.myFloID, closeFundString, global.myPrivKey, fund_util.config.adminID).then(txid => {
|
floBlockchainAPI.writeData(global.myFloID, closeFundString, global.myPrivKey, fund_util.config.adminID).then(txid => {
|
||||||
DB.query("UPDATE CloseFundTransact SET r_status=?, close_id=? WHERE id=?", [pCode.STATUS_SUCCESS, txid, r.id])
|
DB.query("UPDATE CloseFundTransact SET r_status=?, close_id=? WHERE id=?", [pCode.STATUS_SUCCESS, txid, r.id])
|
||||||
.then(result => console.debug("Fund investment closed:", r.fund_id))
|
.then(result => console.info("Fund investment closed:", r.fund_id))
|
||||||
.catch(error => console.error(error));
|
.catch(error => console.error(error));
|
||||||
}).catch(error => console.error(error))
|
}).catch(error => console.error(error))
|
||||||
}).catch(error => console.error(error));
|
}).catch(error => console.error(error));
|
||||||
@ -448,6 +450,9 @@ function processAll() {
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
blockchain,
|
blockchain,
|
||||||
process: processAll,
|
process: processAll,
|
||||||
|
set assetList(assets) {
|
||||||
|
assetList = assets;
|
||||||
|
},
|
||||||
set DB(db) {
|
set DB(db) {
|
||||||
DB = db;
|
DB = db;
|
||||||
blockchain.DB = db;
|
blockchain.DB = db;
|
||||||
|
|||||||
@ -363,6 +363,7 @@ function startBackupTransmitter(server) {
|
|||||||
function initProcess(a) {
|
function initProcess(a) {
|
||||||
app = a;
|
app = a;
|
||||||
app.chests = chests;
|
app.chests = chests;
|
||||||
|
app.collectAndCall = collectAndCall;
|
||||||
startBackupTransmitter(app.server);
|
startBackupTransmitter(app.server);
|
||||||
connectToMaster(0, true);
|
connectToMaster(0, true);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -119,7 +119,7 @@ function sendAsset(floID, asset, quantity, type, id) {
|
|||||||
|
|
||||||
function withdrawAsset_init(floID, asset, amount) {
|
function withdrawAsset_init(floID, asset, amount) {
|
||||||
let asset_type = ["FLO", "BTC"].includes(asset) ? pCode.ASSET_TYPE_COIN : pCode.ASSET_TYPE_TOKEN;
|
let asset_type = ["FLO", "BTC"].includes(asset) ? pCode.ASSET_TYPE_COIN : pCode.ASSET_TYPE_TOKEN;
|
||||||
DB.query("INSERT INTO VaultTransactions (floID, mode, asset_type, asset, amount, r_status) VALUES (?)", [floID, pCode.VAULT_MODE_WITHDRAW, asset_type, asset, amount, pCode.STATUS_PENDING])
|
DB.query("INSERT INTO VaultTransactions (floID, mode, asset_type, asset, amount, r_status) VALUES (?)", [[floID, pCode.VAULT_MODE_WITHDRAW, asset_type, asset, amount, pCode.STATUS_PENDING]])
|
||||||
.then(result => sendAsset(floID, asset, amount, TYPE_VAULT, result.insertId))
|
.then(result => sendAsset(floID, asset, amount, TYPE_VAULT, result.insertId))
|
||||||
.catch(error => console.error(error))
|
.catch(error => console.error(error))
|
||||||
}
|
}
|
||||||
|
|||||||
@ -256,7 +256,7 @@ function getAccountDetails(floID) {
|
|||||||
|
|
||||||
function getUserTransacts(floID) {
|
function getUserTransacts(floID) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
DB.query("SELECT mode, asset, amount, txid, locktime, r_status, FROM VaultTransactions WHERE floID=?", [floID])
|
DB.query("SELECT mode, asset, amount, txid, locktime, r_status FROM VaultTransactions WHERE floID=?", [floID])
|
||||||
.then(result => resolve(result))
|
.then(result => resolve(result))
|
||||||
.catch(error => reject(error))
|
.catch(error => reject(error))
|
||||||
})
|
})
|
||||||
@ -382,7 +382,7 @@ function depositToken(floID, txid) {
|
|||||||
return reject(INVALID(eCode.DUPLICATE_ENTRY, "Transaction already used to add tokens"));
|
return reject(INVALID(eCode.DUPLICATE_ENTRY, "Transaction already used to add tokens"));
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
DB.query("INSERT INTO VaultTransactions(floID, mode, asset_type, txid, r_status) VALUES (?)", [floID, pCode.VAULT_MODE_DEPOSIT, pCode.ASSET_TYPE_TOKEN, txid, pCode.STATUS_PENDING])
|
DB.query("INSERT INTO VaultTransactions(floID, mode, asset_type, txid, r_status) VALUES (?)", [[floID, pCode.VAULT_MODE_DEPOSIT, pCode.ASSET_TYPE_TOKEN, txid, pCode.STATUS_PENDING]])
|
||||||
.then(result => resolve("Deposit request in process"))
|
.then(result => resolve("Deposit request in process"))
|
||||||
.catch(error => reject(error));
|
.catch(error => reject(error));
|
||||||
}).catch(error => reject(error))
|
}).catch(error => reject(error))
|
||||||
@ -549,6 +549,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
set assetList(assets) {
|
set assetList(assets) {
|
||||||
assetList = assets;
|
assetList = assets;
|
||||||
|
background.assetList = assets;
|
||||||
},
|
},
|
||||||
get assetList() {
|
get assetList() {
|
||||||
return assetList
|
return assetList
|
||||||
|
|||||||
@ -51,23 +51,23 @@ function checkPoolBalance(coin, req_value, mode) {
|
|||||||
let q = "SELECT mode, SUM(quantity) AS coin_val, SUM(amount) AS cash_val FROM (" +
|
let q = "SELECT mode, SUM(quantity) AS coin_val, SUM(amount) AS cash_val FROM (" +
|
||||||
"(SELECT amount, coin, quantity, mode, r_status FROM DirectConvert) UNION " +
|
"(SELECT amount, coin, quantity, mode, r_status FROM DirectConvert) UNION " +
|
||||||
"(SELECT amount, coin, quantity, mode, r_status FROM ConvertFund) " +
|
"(SELECT amount, coin, quantity, mode, r_status FROM ConvertFund) " +
|
||||||
") WHERE coin=? AND r_status NOT IN (?) GROUP BY mode"
|
") AS T1 WHERE T1.coin=? AND T1.r_status NOT IN (?) GROUP BY T1.mode"
|
||||||
DB.query(q, [coin, [pCode.STATUS_REJECTED, "REFUND"]]).then(result => {
|
DB.query(q, [coin, [pCode.STATUS_REJECTED]]).then(result => {
|
||||||
let coin_net = 0, cash_net = 0;
|
let coin_net = 0, cash_net = 0;
|
||||||
for (let r of result)
|
for (let r of result)
|
||||||
if (r.mode == pCodeCONVERT_MODE_GET) {
|
if (r.mode == pCode.CONVERT_MODE_GET) {
|
||||||
coin_net -= r.coin_val;
|
coin_net -= r.coin_val;
|
||||||
cash_net += r.cash_val;
|
cash_net += r.cash_val;
|
||||||
} else if (r.mode == pCodeCONVERT_MODE_PUT) {
|
} else if (r.mode == pCode.CONVERT_MODE_PUT) {
|
||||||
coin_net += r.coin_val;
|
coin_net += r.coin_val;
|
||||||
cash_net -= r.cash_val;
|
cash_net -= r.cash_val;
|
||||||
}
|
}
|
||||||
BTC_INR().then(rate => {
|
BTC_INR().then(rate => {
|
||||||
coin_net = coin_net * rate;
|
coin_net = coin_net * rate;
|
||||||
let availability = -1;
|
let availability = -1;
|
||||||
if (mode == pCodeCONVERT_MODE_GET)
|
if (mode == pCode.CONVERT_MODE_GET)
|
||||||
availability = coin_net - cash_net * MIN_FUND;
|
availability = coin_net - cash_net * MIN_FUND;
|
||||||
else if (mode == pCodeCONVERT_MODE_PUT) {
|
else if (mode == pCode.CONVERT_MODE_PUT) {
|
||||||
availability = cash_net - coin_net * MIN_FUND;
|
availability = cash_net - coin_net * MIN_FUND;
|
||||||
req_value = req_value * rate; //convert to currency value
|
req_value = req_value * rate; //convert to currency value
|
||||||
}
|
}
|
||||||
@ -86,16 +86,16 @@ function convertToCoin(floID, txid, coin, amount) {
|
|||||||
return reject(INVALID(eCode.INVALID_TOKEN_NAME, `Invalid coin (${coin})`));
|
return reject(INVALID(eCode.INVALID_TOKEN_NAME, `Invalid coin (${coin})`));
|
||||||
else if (typeof amount !== "number" || amount <= 0)
|
else if (typeof amount !== "number" || amount <= 0)
|
||||||
return reject(INVALID(eCode.INVALID_NUMBER, `Invalid amount (${amount})`));
|
return reject(INVALID(eCode.INVALID_NUMBER, `Invalid amount (${amount})`));
|
||||||
DB.query("SELECT r_status FROM DirectConvert WHERE in_txid=? AND floID=? AND mode=?", [txid, floID, pCodeCONVERT_MODE_GET]).then(result => {
|
DB.query("SELECT r_status FROM DirectConvert WHERE in_txid=? AND floID=? AND mode=?", [txid, floID, pCode.CONVERT_MODE_GET]).then(result => {
|
||||||
if (result.length)
|
if (result.length)
|
||||||
return reject(INVALID(eCode.DUPLICATE_ENTRY, "Transaction already in process"));
|
return reject(INVALID(eCode.DUPLICATE_ENTRY, "Transaction already in process"));
|
||||||
checkPoolBalance(coin, amount, pCodeCONVERT_MODE_GET).then(result => {
|
checkPoolBalance(coin, amount, pCode.CONVERT_MODE_GET).then(result => {
|
||||||
DB.query("INSERT INTO DirectConvert(floID, in_txid, mode, coin, amount, r_status) VALUES (?)", [[floID, txid, pCodeCONVERT_MODE_GET, coin, amount, pCode.STATUS_PENDING]])
|
DB.query("INSERT INTO DirectConvert(floID, in_txid, mode, coin, amount, r_status) VALUES (?)", [[floID, txid, pCode.CONVERT_MODE_GET, coin, amount, pCode.STATUS_PENDING]])
|
||||||
.then(result => resolve("Conversion request in process"))
|
.then(result => resolve("Conversion request in process"))
|
||||||
.catch(error => reject(error));
|
.catch(error => reject(error));
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
if (error instanceof INVALID && error.ecode === eCode.INSUFFICIENT_FUND)
|
if (error instanceof INVALID && error.ecode === eCode.INSUFFICIENT_FUND)
|
||||||
DB.query("INSERT INTO DirectConvert(floID, in_txid, mode, coin, amount, r_status) VALUES (?)", [[floID, txid, pCodeCONVERT_MODE_GET, coin, amount, "REFUND"]]).then(result => {
|
DB.query("INSERT INTO DirectConvert(floID, in_txid, mode, coin, amount, r_status) VALUES (?)", [[floID, txid, pCode.CONVERT_MODE_GET, coin, amount, pCode.STATUS_REJECTED]]).then(result => {
|
||||||
DB.query("INSERT INTO RefundTransact(floID, in_txid, amount, r_status) VALUES (?)", [[floID, txid, amount, pCode.STATUS_PENDING]])
|
DB.query("INSERT INTO RefundTransact(floID, in_txid, amount, r_status) VALUES (?)", [[floID, txid, amount, pCode.STATUS_PENDING]])
|
||||||
.then(_ => null).catch(error => console.error(error));
|
.then(_ => null).catch(error => console.error(error));
|
||||||
}).catch(error => console.error(error))
|
}).catch(error => console.error(error))
|
||||||
@ -113,14 +113,14 @@ function convertFromCoin(floID, txid, tx_hex, coin, quantity) {
|
|||||||
return reject(INVALID(eCode.INVALID_NUMBER, `Invalid quantity (${quantity})`));
|
return reject(INVALID(eCode.INVALID_NUMBER, `Invalid quantity (${quantity})`));
|
||||||
else if (btcOperator.transactionID(tx_hex) !== txid)
|
else if (btcOperator.transactionID(tx_hex) !== txid)
|
||||||
return reject(INVALID(eCode.INVALID_TX_ID, `txid ${txid} doesnt match the tx-hex`));
|
return reject(INVALID(eCode.INVALID_TX_ID, `txid ${txid} doesnt match the tx-hex`));
|
||||||
DB.query("SELECT r_status FROM DirectConvert WHERE in_txid=? AND floID=? AND mode=?", [txid, floID, pCodeCONVERT_MODE_PUT]).then(result => {
|
DB.query("SELECT r_status FROM DirectConvert WHERE in_txid=? AND floID=? AND mode=?", [txid, floID, pCode.CONVERT_MODE_PUT]).then(result => {
|
||||||
if (result.length)
|
if (result.length)
|
||||||
return reject(INVALID(eCode.DUPLICATE_ENTRY, "Transaction already in process"));
|
return reject(INVALID(eCode.DUPLICATE_ENTRY, "Transaction already in process"));
|
||||||
checkPoolBalance(coin, quantity, pCodeCONVERT_MODE_PUT).then(result => {
|
checkPoolBalance(coin, quantity, pCode.CONVERT_MODE_PUT).then(result => {
|
||||||
btcOperator.broadcastTx(tx_hex).then(b_txid => {
|
btcOperator.broadcastTx(tx_hex).then(b_txid => {
|
||||||
if (b_txid !== txid)
|
if (b_txid !== txid)
|
||||||
console.warn("broadcast TX-ID is not same as calculated TX-ID");
|
console.warn("broadcast TX-ID is not same as calculated TX-ID");
|
||||||
DB.query("INSERT INTO DirectConvert(floID, in_txid, mode, coin, quantity, r_status) VALUES (?)", [[floID, b_txid, pCodeCONVERT_MODE_PUT, coin, quantity, pCode.STATUS_PENDING]])
|
DB.query("INSERT INTO DirectConvert(floID, in_txid, mode, coin, quantity, r_status) VALUES (?)", [[floID, b_txid, pCode.CONVERT_MODE_PUT, coin, quantity, pCode.STATUS_PENDING]])
|
||||||
.then(result => resolve("Conversion request in process"))
|
.then(result => resolve("Conversion request in process"))
|
||||||
.catch(error => reject(error));
|
.catch(error => reject(error));
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
@ -140,10 +140,10 @@ function depositCurrencyFund(floID, txid, coin) {
|
|||||||
return reject(INVALID(eCode.ACCESS_DENIED, 'Access Denied'));
|
return reject(INVALID(eCode.ACCESS_DENIED, 'Access Denied'));
|
||||||
else if (!allowedConversion.includes(coin))
|
else if (!allowedConversion.includes(coin))
|
||||||
return reject(INVALID(eCode.INVALID_TOKEN_NAME, `Invalid coin (${coin})`));
|
return reject(INVALID(eCode.INVALID_TOKEN_NAME, `Invalid coin (${coin})`));
|
||||||
DB.query("SELECT r_status FROM ConvertFund WHERE txid=? AND mode=?", [txid, pCodeCONVERT_MODE_GET]).then(result => {
|
DB.query("SELECT r_status FROM ConvertFund WHERE txid=? AND mode=?", [txid, pCode.CONVERT_MODE_GET]).then(result => {
|
||||||
if (result.length)
|
if (result.length)
|
||||||
return reject(INVALID(eCode.DUPLICATE_ENTRY, "Transaction already in process"));
|
return reject(INVALID(eCode.DUPLICATE_ENTRY, "Transaction already in process"));
|
||||||
DB.query("INSERT INTO ConvertFund(txid, mode, coin, r_status) VALUES (?)", [[b_txid, pCodeCONVERT_MODE_GET, coin, pCode.STATUS_PROCESSING]])
|
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("Add currency fund in process"))
|
||||||
.catch(error => reject(error))
|
.catch(error => reject(error))
|
||||||
}).catch(error => reject(error))
|
}).catch(error => reject(error))
|
||||||
@ -156,10 +156,10 @@ function depositCoinFund(floID, txid, coin) {
|
|||||||
return reject(INVALID(eCode.ACCESS_DENIED, 'Access Denied'));
|
return reject(INVALID(eCode.ACCESS_DENIED, 'Access Denied'));
|
||||||
else if (!allowedConversion.includes(coin))
|
else if (!allowedConversion.includes(coin))
|
||||||
return reject(INVALID(eCode.INVALID_TOKEN_NAME, `Invalid coin (${coin})`));
|
return reject(INVALID(eCode.INVALID_TOKEN_NAME, `Invalid coin (${coin})`));
|
||||||
DB.query("SELECT r_status FROM ConvertFund WHERE txid=? AND mode=?", [txid, pCodeCONVERT_MODE_PUT]).then(result => {
|
DB.query("SELECT r_status FROM ConvertFund WHERE txid=? AND mode=?", [txid, pCode.CONVERT_MODE_PUT]).then(result => {
|
||||||
if (result.length)
|
if (result.length)
|
||||||
return reject(INVALID(eCode.DUPLICATE_ENTRY, "Transaction already in process"));
|
return reject(INVALID(eCode.DUPLICATE_ENTRY, "Transaction already in process"));
|
||||||
DB.query("INSERT INTO ConvertFund(txid, mode, coin, r_status) VALUES (?)", [[b_txid, pCodeCONVERT_MODE_PUT, coin, pCode.STATUS_PROCESSING]])
|
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("Add coin fund in process"))
|
||||||
.catch(error => reject(error))
|
.catch(error => reject(error))
|
||||||
}).catch(error => reject(error))
|
}).catch(error => reject(error))
|
||||||
@ -172,12 +172,12 @@ function withdrawCurrencyFund(floID, coin, amount) {
|
|||||||
return reject(INVALID(eCode.ACCESS_DENIED, 'Access Denied'));
|
return reject(INVALID(eCode.ACCESS_DENIED, 'Access Denied'));
|
||||||
else if (!allowedConversion.includes(coin))
|
else if (!allowedConversion.includes(coin))
|
||||||
return reject(INVALID(eCode.INVALID_TOKEN_NAME, `Invalid coin (${coin})`));
|
return reject(INVALID(eCode.INVALID_TOKEN_NAME, `Invalid coin (${coin})`));
|
||||||
DB.query("SELECT SUM(amount) AS deposit_amount FROM ConvertFund WHERE mode=? AND r_status=?", [pCodeCONVERT_MODE_GET, pCode.STATUS_SUCCESS]).then(r1 => {
|
DB.query("SELECT SUM(amount) AS deposit_amount FROM ConvertFund WHERE mode=? AND r_status=?", [pCode.CONVERT_MODE_GET, pCode.STATUS_SUCCESS]).then(r1 => {
|
||||||
DB.query("SELECT SUM(amount) AS withdraw_amount FROM ConvertFund WHERE mode=? AND r_status IN (?)", [pCodeCONVERT_MODE_PUT, [pCode.STATUS_SUCCESS, pCode.STATUS_PENDING, pCode.STATUS_CONFIRMATION]]).then(r2 => {
|
DB.query("SELECT SUM(amount) AS withdraw_amount FROM ConvertFund WHERE mode=? AND r_status IN (?)", [pCode.CONVERT_MODE_PUT, [pCode.STATUS_SUCCESS, pCode.STATUS_PENDING, pCode.STATUS_CONFIRMATION]]).then(r2 => {
|
||||||
let available_amount = (r1[0].deposit_amount || 0) - (r2[0].withdraw_amount || 0);
|
let available_amount = (r1[0].deposit_amount || 0) - (r2[0].withdraw_amount || 0);
|
||||||
if (available_amount < amount)
|
if (available_amount < amount)
|
||||||
return reject(INVALID(eCode.INSUFFICIENT_BALANCE, "Insufficient convert-fund deposits to withdraw"));
|
return reject(INVALID(eCode.INSUFFICIENT_BALANCE, "Insufficient convert-fund deposits to withdraw"));
|
||||||
DB.query("INSERT INTO ConvertFund(mode, coin, amount, r_status) VALUES (?)", [[pCodeCONVERT_MODE_PUT, coin, amount, pCode.STATUS_PENDING]])
|
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("Add currency fund in process"))
|
||||||
.catch(error => reject(error))
|
.catch(error => reject(error))
|
||||||
}).catch(error => reject(error))
|
}).catch(error => reject(error))
|
||||||
@ -191,12 +191,12 @@ function withdrawCoinFund(floID, coin, quantity) {
|
|||||||
return reject(INVALID(eCode.ACCESS_DENIED, 'Access Denied'));
|
return reject(INVALID(eCode.ACCESS_DENIED, 'Access Denied'));
|
||||||
else if (!allowedConversion.includes(coin))
|
else if (!allowedConversion.includes(coin))
|
||||||
return reject(INVALID(eCode.INVALID_TOKEN_NAME, `Invalid coin (${coin})`));
|
return reject(INVALID(eCode.INVALID_TOKEN_NAME, `Invalid coin (${coin})`));
|
||||||
DB.query("SELECT SUM(quantity) AS deposit_quantity FROM ConvertFund WHERE mode=? AND r_status=?", [pCodeCONVERT_MODE_PUT, pCode.STATUS_SUCCESS]).then(r1 => {
|
DB.query("SELECT SUM(quantity) AS deposit_quantity FROM ConvertFund WHERE mode=? AND r_status=?", [pCode.CONVERT_MODE_PUT, pCode.STATUS_SUCCESS]).then(r1 => {
|
||||||
DB.query("SELECT SUM(quantity) AS withdraw_quantity FROM ConvertFund WHERE mode=? AND r_status IN (?)", [pCodeCONVERT_MODE_GET, [pCode.STATUS_SUCCESS, pCode.STATUS_PENDING]]).then(r2 => {
|
DB.query("SELECT SUM(quantity) AS withdraw_quantity FROM ConvertFund WHERE mode=? AND r_status IN (?)", [pCode.CONVERT_MODE_GET, [pCode.STATUS_SUCCESS, pCode.STATUS_PENDING]]).then(r2 => {
|
||||||
let available_quantity = (r1[0].deposit_quantity || 0) - (r2[0].withdraw_quantity || 0);
|
let available_quantity = (r1[0].deposit_quantity || 0) - (r2[0].withdraw_quantity || 0);
|
||||||
if (available_quantity < quantity)
|
if (available_quantity < quantity)
|
||||||
return reject(INVALID(eCode.INSUFFICIENT_BALANCE, "Insufficient convert-fund deposits to withdraw"));
|
return reject(INVALID(eCode.INSUFFICIENT_BALANCE, "Insufficient convert-fund deposits to withdraw"));
|
||||||
DB.query("INSERT INTO ConvertFund(mode, coin, quantity, r_status) VALUES (?)", [[pCodeCONVERT_MODE_GET, coin, quantity, pCode.STATUS_PENDING]])
|
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("Add currency fund in process"))
|
||||||
.catch(error => reject(error))
|
.catch(error => reject(error))
|
||||||
}).catch(error => reject(error))
|
}).catch(error => reject(error))
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user