diff --git a/docs/scripts/floExchangeAPI.js b/docs/scripts/floExchangeAPI.js index ba5ebe5..4057c88 100644 --- a/docs/scripts/floExchangeAPI.js +++ b/docs/scripts/floExchangeAPI.js @@ -600,6 +600,26 @@ CONVERT_MODE_PUT: 0, } + const serviceList = exchangeAPI.serviceList = { + EXCHANGE: "exchange", + CONVERT: "convert", + BLOCKCHAIN_BOND: "blockchain-bond", + BOBS_FUND: "bobs-fund" + } + + exchangeAPI.getSink = function (service = serviceList.EXCHANGE) { + return new Promise((resolve, reject) => { + if (!(service in serviceList)) + return reject(ExchangeError(ExchangeError.BAD_REQUEST_CODE, 'service required', errorCode.INVALID_TYPE)); + fetch_api('/get-sink?service=' + service) + .then(result => { + responseParse(result, false) + .then(result => resolve(result)) + .catch(error => reject(error)) + }).catch(error => reject(error)); + }) + } + exchangeAPI.getAccount = function (floID, proxySecret) { return new Promise((resolve, reject) => { let request = { @@ -1241,6 +1261,17 @@ }) } + exchangeAPI.getConvertValues = function () { + return new Promise((resolve, reject) => { + fetch_api('/get-convert-values') + .then(result => { + responseParse(result) + .then(result => resolve(result)) + .catch(error => reject(error)) + }).catch(error => reject(error)); + }) + } + exchangeAPI.convertToBTC = function (amount, floID, sinkID, privKey) { return new Promise((resolve, reject) => { if (!floCrypto.verifyPrivKey(privKey, floID)) diff --git a/src/app.js b/src/app.js index a97b52e..55ed7ec 100644 --- a/src/app.js +++ b/src/app.js @@ -76,6 +76,7 @@ module.exports = function App(secret) { app.get('/rate-history', Request.GetRateHistory); app.get('/get-balance', Request.GetBalance); app.get('/get-transaction', Request.GetTransaction); + app.get('/get-sink', Request.GetSink); //get account details app.post('/account', Request.Account); @@ -88,6 +89,7 @@ module.exports = function App(secret) { app.post('/get-transact', Request.GetUserTransacts); //convert from or to coin + app.get('/get-convert-values', Request.GetConvertValues); app.post('/convert-to', Request.ConvertTo); app.post('/convert-from', Request.ConvertFrom); app.post('/deposit-convert-coin-fund', Request.DepositConvertCoinFund); @@ -127,14 +129,6 @@ module.exports = function App(secret) { set: (assets) => Request.assetList = assets }); - Object.defineProperty(self, "chests", { - set: (chests) => Request.chests = chests - }); - - Object.defineProperty(self, "collectAndCall", { - set: (fn) => Request.collectAndCall = fn - }); - //Refresh data (from blockchain) self.refreshData = (nodeList) => Request.refreshData(nodeList); diff --git a/src/coupling.js b/src/coupling.js index 90d3b01..bbe95bc 100644 --- a/src/coupling.js +++ b/src/coupling.js @@ -248,6 +248,5 @@ function auditBalance(sellerID, buyerID, asset) { module.exports = { initiate: startCouplingForAsset, stopAll: stopAllInstance, - updateBalance, - price + updateBalance } \ No newline at end of file diff --git a/src/request.js b/src/request.js index 03e997c..c08a19e 100644 --- a/src/request.js +++ b/src/request.js @@ -5,6 +5,8 @@ const market = require("./market"); const conversion = require('./services/conversion'); const blockchain_bonds = require("./services/bonds"); const bobs_fund = require("./services/bobs-fund"); +const background = require("./background"); +const keys = require("./keys"); const { SIGN_EXPIRE_TIME, @@ -12,6 +14,7 @@ const { } = require("./_constants")["request"]; const eCode = require('../docs/scripts/floExchangeAPI').errorCode; +const serviceList = require('../docs/scripts/floExchangeAPI').serviceList; var trustedIDs, secret; //containers for trusted IDs and secret @@ -132,7 +135,6 @@ function Account(req, res) { timestamp: data.timestamp }, data.sign, data.floID, data.pubKey).then(req_str => { market.getAccountDetails(data.floID).then(result => { - result.sinkID = market.chests.pick; if (trustedIDs.includes(data.floID)) result.subAdmin = true; res.send(result); @@ -493,6 +495,43 @@ function ListTradeTransactions(req, res) { } } +function GetConvertValues(req, res) { + if (!serving) + res.status(INVALID.e_code).send(INCORRECT_SERVER_ERROR.toString()); + else conversion.getConvertValues() + .then(result => res.send(result)) + .catch(error => { + if (error instanceof INVALID) + res.status(INVALID.e_code).send(error.toString()); + else { + console.error(error); + res.status(INTERNAL.e_code).send(INTERNAL.str("Unable to process! Try again later!")); + } + }); +} + +function GetSink(req, res) { + if (!serving) + res.status(INVALID.e_code).send(INCORRECT_SERVER_ERROR.toString()); + else { + 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)) + res.status(INVALID.e_code).send(INVALID.str(eCode.INVALID_TYPE, "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; + } + res.send(keys.sink_chest.active_pick(group)); + } + } +} + function GetRates(req, res) { if (!serving) res.status(INVALID.e_code).send(INCORRECT_SERVER_ERROR.toString()); @@ -590,6 +629,7 @@ module.exports = { GetRateHistory, GetTransaction, GetBalance, + GetSink, Account, DepositFLO, WithdrawFLO, @@ -600,6 +640,7 @@ module.exports = { RemoveUserTag, AddDistributor, RemoveDistributor, + GetConvertValues, ConvertTo, ConvertFrom, DepositConvertCoinFund, @@ -614,12 +655,6 @@ module.exports = { set assetList(assets) { market.assetList = assets; }, - set chests(c) { - market.chests = c; - }, - set collectAndCall(fn) { - market.collectAndCall = fn; - }, set secret(s) { secret = s; }, @@ -629,10 +664,10 @@ module.exports = { }, pause() { serving = false; - market.periodicProcess.stop(); + background.periodicProcess.stop(); }, resume() { serving = true; - market.periodicProcess.start(); + background.periodicProcess.start(); } }; \ No newline at end of file