- Adding rate column to DirectConvert table to store the rate of conversion
- Fixed: withdrawConvertFundCurrency not working correctly
- Fixed: closeBlockchainBond and closeBobsFundInvestment syntax bugs
- Adding request_timeout after with convert request will expire if tx from user is still unconfirmed
- Fixed: conversion result value has more than 8 decimal places
- Fixed minor syntax bugs
This commit is contained in:
sairajzero 2022-10-25 02:12:58 +05:30
parent 0389e833a5
commit 4b26ad60bd
5 changed files with 52 additions and 43 deletions

View File

@ -277,6 +277,7 @@ CREATE TABLE DirectConvert(
coin VARCHAR(8) NOT NULL,
quantity DECIMAL(16, 8),
mode TINYINT NOT NULL,
rate DECIMAL(16, 2),
in_txid VARCHAR(128),
out_txid VARCHAR(128),
locktime TIMESTAMP DEFAULT CURRENT_TIMESTAMP,

View File

@ -1352,7 +1352,7 @@
request.sign = signRequest({
type: "deposit_convert_coin_fund",
coin: request.coin,
txid: data.txid,
txid: txid,
timestamp: request.timestamp
}, privKey);
console.debug(request);
@ -1407,7 +1407,7 @@
})
}
exchangeAPI.withdrawConvertFundCurrency = function (quantity, floID, privKey) {
exchangeAPI.withdrawConvertFundCoin = function (quantity, 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));
@ -1454,8 +1454,8 @@
request.pubKey = floCrypto.getPubKeyHex(privKey);
request.sign = signRequest({
type: "close_blockchain_bond",
bond_id: data.bond_id,
timestamp: data.timestamp
bond_id: request.bond_id,
timestamp: request.timestamp
}, privKey);
console.debug(request);
@ -1485,8 +1485,8 @@
request.pubKey = floCrypto.getPubKeyHex(privKey);
request.sign = signRequest({
type: "close_bobs_fund",
fund_id: data.fund_id,
timestamp: data.timestamp
fund_id: request.fund_id,
timestamp: request.timestamp
}, privKey);
console.debug(request);

View File

@ -9,6 +9,7 @@ module.exports = {
market: {
PERIOD_INTERVAL: 5 * 60 * 1000, //5 min,
WAIT_TIME: 2 * 60 * 1000, //2 mins,
REQUEST_TIMEOUT: 24 * 60 * 60 * 1000, //1 day
LAUNCH_SELLER_TAG: "launch-seller",
MAXIMUM_LAUNCH_SELL_CHIPS: 100000,
TRADE_HASH_PREFIX: "z1",

View File

@ -8,6 +8,7 @@ const pCode = require('../docs/scripts/floExchangeAPI').processCode;
const {
LAUNCH_SELLER_TAG,
MAXIMUM_LAUNCH_SELL_CHIPS,
REQUEST_TIMEOUT,
} = require('./_constants')["market"];
var DB, assetList; //container for database and allowed assets
@ -209,6 +210,7 @@ verifyTx.BTC = function (sender, txid) {
}
function verifyConvert() {
DB.query("UPDATE DirectConvert SET r_status=? WHERE r_status=? AND locktime<?", [pCode.STATUS_REJECTED, pCode.STATUS_PENDING, new Date(Date.now() - REQUEST_TIMEOUT)]).then(result => {
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 => {
if (r.mode == pCode.CONVERT_MODE_GET) {
@ -216,7 +218,7 @@ function verifyConvert() {
if (r.amount !== amount)
throw ([true, "Transaction amount mismatched in blockchain"]);
conversion_rates.BTC_INR().then(rate => {
blockchain.convertToCoin.init(r.floID, "BTC", amount / rate, r.id)
blockchain.convertToCoin.init(r.floID, "BTC", amount, rate, r.id)
}).catch(error => console.error(error))
}).catch(error => {
console.error(error);
@ -229,7 +231,7 @@ function verifyConvert() {
if (r.quantity !== quantity)
throw ([true, "Transaction quantity mismatched in blockchain"]);
conversion_rates.BTC_INR().then(rate => {
blockchain.convertFromCoin.init(r.floID, quantity * rate, r.id)
blockchain.convertFromCoin.init(r.floID, quantity, rate, r.id)
}).catch(error => console.error(error))
}).catch(error => {
console.error(error);
@ -240,6 +242,7 @@ function verifyConvert() {
}
})
}).catch(error => console.error(error))
}).catch(error => reject(error))
}
function retryConvert() {
@ -261,7 +264,7 @@ function confirmConvert() {
if (!tx.blockhash || !tx.confirmations) //Still not confirmed
return;
DB.query("UPDATE DirectConvert SET r_status=? WHERE id=?", [pCode.STATUS_SUCCESS, r.id])
.then(result => console.info(`${r.floID} converted ${amount} to ${r.quantity} BTC`))
.then(result => console.info(`${r.floID} converted ${r.amount} to ${r.quantity} BTC`))
.catch(error => console.error(error))
}).catch(error => console.error(error));
else if (r.mode == pCode.CONVERT_MODE_PUT)
@ -269,7 +272,7 @@ function confirmConvert() {
if (!tx.transactionDetails.blockheight || !tx.transactionDetails.confirmations) //Still not confirmed
return;
DB.query("UPDATE DirectConvert SET r_status=? WHERE id=?", [pCode.STATUS_SUCCESS, r.id])
.then(result => console.info(`${r.floID} converted ${r.quantity} BTC to ${amount}`))
.then(result => console.info(`${r.floID} converted ${r.quantity} BTC to ${r.amount}`))
.catch(error => console.error(error));
}).catch(error => console.error(error));
})

View File

@ -118,6 +118,7 @@ function sendAsset(floID, asset, quantity, type, id) {
}
function withdrawAsset_init(floID, asset, amount) {
amount = parseFloat(amount.toFixed(8));
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]])
.then(result => sendAsset(floID, asset, amount, TYPE_VAULT, result.insertId))
@ -130,8 +131,9 @@ function withdrawAsset_retry(floID, asset, amount, id) {
else sendAsset(floID, asset, amount, TYPE_VAULT, id);
}
function convertToCoin_init(floID, coin, coin_quantity, id) {
DB.query("UPDATE DirectConvert SET quantity=?, r_status=?, locktime=DEFAULT WHERE id=?", [coin_quantity, pCode.STATUS_PROCESSING, id])
function convertToCoin_init(floID, coin, currency_amount, rate, id) {
let coin_quantity = parseFloat((currency_amount / rate).toFixed(8));
DB.query("UPDATE DirectConvert SET quantity=?, r_status=?, rate=?, locktime=DEFAULT WHERE id=?", [coin_quantity, pCode.STATUS_PROCESSING, rate, id])
.then(result => sendAsset(floID, coin, coin_quantity, TYPE_CONVERT, id))
.catch(error => console.error(error))
}
@ -142,8 +144,9 @@ function convertToCoin_retry(floID, coin, coin_quantity, id) {
else sendAsset(floID, coin, coin_quantity, TYPE_CONVERT, id);
}
function convertFromCoin_init(floID, currency_amount, id) {
DB.query("UPDATE DirectConvert SET amount=?, r_status=?, locktime=DEFAULT WHERE id=?", [currency_amount, pCode.STATUS_PROCESSING, id])
function convertFromCoin_init(floID, coin_quantity, rate, id) {
let currency_amount = parseFloat((coin_quantity * rate).toFixed(8));
DB.query("UPDATE DirectConvert SET amount=?, r_status=?, rate=?, locktime=DEFAULT WHERE id=?", [currency_amount, pCode.STATUS_PROCESSING, rate, id])
.then(result => sendAsset(floID, floGlobals.currency, currency_amount, TYPE_CONVERT, id))
.catch(error => console.error(error))
}
@ -173,6 +176,7 @@ function fundTransact_retry(floID, amount, id) {
}
function refundTransact_init(floID, amount, id) {
amount = parseFloat(amount.toFixed(8));
DB.query("UPDATE RefundTransact SET amount=?, r_status=?, locktime=DEFAULT WHERE id=?", [amount, pCode.STATUS_PROCESSING, id])
.then(result => sendAsset(floID, floGlobals.currency, amount, TYPE_REFUND, id))
.catch(error => console.error(error))