Bug fix
- 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:
parent
0389e833a5
commit
4b26ad60bd
@ -277,6 +277,7 @@ CREATE TABLE DirectConvert(
|
|||||||
coin VARCHAR(8) NOT NULL,
|
coin VARCHAR(8) NOT NULL,
|
||||||
quantity DECIMAL(16, 8),
|
quantity DECIMAL(16, 8),
|
||||||
mode TINYINT NOT NULL,
|
mode TINYINT NOT NULL,
|
||||||
|
rate DECIMAL(16, 2),
|
||||||
in_txid VARCHAR(128),
|
in_txid VARCHAR(128),
|
||||||
out_txid VARCHAR(128),
|
out_txid VARCHAR(128),
|
||||||
locktime TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
locktime TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
|||||||
@ -1352,7 +1352,7 @@
|
|||||||
request.sign = signRequest({
|
request.sign = signRequest({
|
||||||
type: "deposit_convert_coin_fund",
|
type: "deposit_convert_coin_fund",
|
||||||
coin: request.coin,
|
coin: request.coin,
|
||||||
txid: data.txid,
|
txid: txid,
|
||||||
timestamp: request.timestamp
|
timestamp: request.timestamp
|
||||||
}, privKey);
|
}, privKey);
|
||||||
console.debug(request);
|
console.debug(request);
|
||||||
@ -1407,7 +1407,7 @@
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
exchangeAPI.withdrawConvertFundCurrency = function (quantity, floID, privKey) {
|
exchangeAPI.withdrawConvertFundCoin = function (quantity, floID, privKey) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (!floCrypto.verifyPrivKey(privKey, floID))
|
if (!floCrypto.verifyPrivKey(privKey, floID))
|
||||||
return reject(ExchangeError(ExchangeError.BAD_REQUEST_CODE, "Invalid Private Key", errorCode.INVALID_PRIVATE_KEY));
|
return reject(ExchangeError(ExchangeError.BAD_REQUEST_CODE, "Invalid Private Key", errorCode.INVALID_PRIVATE_KEY));
|
||||||
@ -1454,8 +1454,8 @@
|
|||||||
request.pubKey = floCrypto.getPubKeyHex(privKey);
|
request.pubKey = floCrypto.getPubKeyHex(privKey);
|
||||||
request.sign = signRequest({
|
request.sign = signRequest({
|
||||||
type: "close_blockchain_bond",
|
type: "close_blockchain_bond",
|
||||||
bond_id: data.bond_id,
|
bond_id: request.bond_id,
|
||||||
timestamp: data.timestamp
|
timestamp: request.timestamp
|
||||||
}, privKey);
|
}, privKey);
|
||||||
console.debug(request);
|
console.debug(request);
|
||||||
|
|
||||||
@ -1485,8 +1485,8 @@
|
|||||||
request.pubKey = floCrypto.getPubKeyHex(privKey);
|
request.pubKey = floCrypto.getPubKeyHex(privKey);
|
||||||
request.sign = signRequest({
|
request.sign = signRequest({
|
||||||
type: "close_bobs_fund",
|
type: "close_bobs_fund",
|
||||||
fund_id: data.fund_id,
|
fund_id: request.fund_id,
|
||||||
timestamp: data.timestamp
|
timestamp: request.timestamp
|
||||||
}, privKey);
|
}, privKey);
|
||||||
console.debug(request);
|
console.debug(request);
|
||||||
|
|
||||||
|
|||||||
@ -9,6 +9,7 @@ module.exports = {
|
|||||||
market: {
|
market: {
|
||||||
PERIOD_INTERVAL: 5 * 60 * 1000, //5 min,
|
PERIOD_INTERVAL: 5 * 60 * 1000, //5 min,
|
||||||
WAIT_TIME: 2 * 60 * 1000, //2 mins,
|
WAIT_TIME: 2 * 60 * 1000, //2 mins,
|
||||||
|
REQUEST_TIMEOUT: 24 * 60 * 60 * 1000, //1 day
|
||||||
LAUNCH_SELLER_TAG: "launch-seller",
|
LAUNCH_SELLER_TAG: "launch-seller",
|
||||||
MAXIMUM_LAUNCH_SELL_CHIPS: 100000,
|
MAXIMUM_LAUNCH_SELL_CHIPS: 100000,
|
||||||
TRADE_HASH_PREFIX: "z1",
|
TRADE_HASH_PREFIX: "z1",
|
||||||
|
|||||||
@ -8,6 +8,7 @@ const pCode = require('../docs/scripts/floExchangeAPI').processCode;
|
|||||||
const {
|
const {
|
||||||
LAUNCH_SELLER_TAG,
|
LAUNCH_SELLER_TAG,
|
||||||
MAXIMUM_LAUNCH_SELL_CHIPS,
|
MAXIMUM_LAUNCH_SELL_CHIPS,
|
||||||
|
REQUEST_TIMEOUT,
|
||||||
} = require('./_constants')["market"];
|
} = require('./_constants')["market"];
|
||||||
|
|
||||||
var DB, assetList; //container for database and allowed assets
|
var DB, assetList; //container for database and allowed assets
|
||||||
@ -209,6 +210,7 @@ verifyTx.BTC = function (sender, txid) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function verifyConvert() {
|
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 => {
|
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 == pCode.CONVERT_MODE_GET) {
|
if (r.mode == pCode.CONVERT_MODE_GET) {
|
||||||
@ -216,7 +218,7 @@ function verifyConvert() {
|
|||||||
if (r.amount !== amount)
|
if (r.amount !== amount)
|
||||||
throw ([true, "Transaction amount mismatched in blockchain"]);
|
throw ([true, "Transaction amount mismatched in blockchain"]);
|
||||||
conversion_rates.BTC_INR().then(rate => {
|
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))
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
@ -229,7 +231,7 @@ function verifyConvert() {
|
|||||||
if (r.quantity !== quantity)
|
if (r.quantity !== quantity)
|
||||||
throw ([true, "Transaction quantity mismatched in blockchain"]);
|
throw ([true, "Transaction quantity mismatched in blockchain"]);
|
||||||
conversion_rates.BTC_INR().then(rate => {
|
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))
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
@ -240,6 +242,7 @@ function verifyConvert() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}).catch(error => console.error(error))
|
}).catch(error => console.error(error))
|
||||||
|
}).catch(error => reject(error))
|
||||||
}
|
}
|
||||||
|
|
||||||
function retryConvert() {
|
function retryConvert() {
|
||||||
@ -261,7 +264,7 @@ function confirmConvert() {
|
|||||||
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.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))
|
||||||
}).catch(error => console.error(error));
|
}).catch(error => console.error(error));
|
||||||
else if (r.mode == pCode.CONVERT_MODE_PUT)
|
else if (r.mode == pCode.CONVERT_MODE_PUT)
|
||||||
@ -269,7 +272,7 @@ function confirmConvert() {
|
|||||||
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.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));
|
||||||
}).catch(error => console.error(error));
|
}).catch(error => console.error(error));
|
||||||
})
|
})
|
||||||
|
|||||||
@ -118,6 +118,7 @@ function sendAsset(floID, asset, quantity, type, id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function withdrawAsset_init(floID, asset, amount) {
|
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;
|
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))
|
||||||
@ -130,8 +131,9 @@ function withdrawAsset_retry(floID, asset, amount, id) {
|
|||||||
else sendAsset(floID, asset, amount, TYPE_VAULT, id);
|
else sendAsset(floID, asset, amount, TYPE_VAULT, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
function convertToCoin_init(floID, coin, coin_quantity, id) {
|
function convertToCoin_init(floID, coin, currency_amount, rate, id) {
|
||||||
DB.query("UPDATE DirectConvert SET quantity=?, r_status=?, locktime=DEFAULT WHERE id=?", [coin_quantity, pCode.STATUS_PROCESSING, 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))
|
.then(result => sendAsset(floID, coin, coin_quantity, TYPE_CONVERT, id))
|
||||||
.catch(error => console.error(error))
|
.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);
|
else sendAsset(floID, coin, coin_quantity, TYPE_CONVERT, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
function convertFromCoin_init(floID, currency_amount, id) {
|
function convertFromCoin_init(floID, coin_quantity, rate, id) {
|
||||||
DB.query("UPDATE DirectConvert SET amount=?, r_status=?, locktime=DEFAULT WHERE id=?", [currency_amount, pCode.STATUS_PROCESSING, 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))
|
.then(result => sendAsset(floID, floGlobals.currency, currency_amount, TYPE_CONVERT, id))
|
||||||
.catch(error => console.error(error))
|
.catch(error => console.error(error))
|
||||||
}
|
}
|
||||||
@ -173,6 +176,7 @@ function fundTransact_retry(floID, amount, id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function refundTransact_init(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])
|
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))
|
.then(result => sendAsset(floID, floGlobals.currency, amount, TYPE_REFUND, id))
|
||||||
.catch(error => console.error(error))
|
.catch(error => console.error(error))
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user