Distributor feature and Balance structure change

- Distributor feature allows to mark floIDs as distributors for certain asset.
- Added 2 APIs: add-distributor, remove-distributor
- Changing structure for token balance in exchange system. (requirement for new rule update).
This commit is contained in:
sairajzero 2022-04-13 01:06:01 +05:30
parent deb746ef9e
commit 9caf3fc9ec
8 changed files with 195 additions and 108 deletions

View File

@ -885,7 +885,7 @@
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (typeof quantity !== "number" || quantity <= floGlobals.fee) if (typeof quantity !== "number" || quantity <= floGlobals.fee)
return reject(`Invalid quantity (${quantity})`); return reject(`Invalid quantity (${quantity})`);
floBlockchainAPI.sendTx(floID, sinkID, quantity, privKey, 'Deposit FLO in market').then(txid => { floBlockchainAPI.sendTx(floID, sinkID, quantity, privKey, '(deposit in market)').then(txid => {
let request = { let request = {
floID: floID, floID: floID,
txid: txid, txid: txid,
@ -947,7 +947,7 @@
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (!floCrypto.verifyPrivKey(privKey, floID)) if (!floCrypto.verifyPrivKey(privKey, floID))
return reject("Invalid Private Key"); return reject("Invalid Private Key");
floTokenAPI.sendToken(privKey, quantity, sinkID, 'Deposit Rupee in market', token).then(txid => { floTokenAPI.sendToken(privKey, quantity, sinkID, '(deposit in market)', token).then(txid => {
let request = { let request = {
floID: floID, floID: floID,
txid: txid, txid: txid,
@ -1069,6 +1069,68 @@
}) })
} }
exchangeAPI.addDistributor = function(distributor, asset, floID, proxySecret) {
return new Promise((resolve, reject) => {
let request = {
floID: floID,
distributor: distributor,
asset: asset,
timestamp: Date.now()
};
if (floCrypto.getFloID(proxySecret) === floID) //Direct signing (without proxy)
request.pubKey = floCrypto.getPubKeyHex(proxySecret);
request.sign = signRequest({
type: "add_distributor",
distributor: distributor,
asset: asset,
timestamp: request.timestamp
}, proxySecret);
console.debug(request);
fetch_api('/add-distributor', {
method: "POST",
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(request)
}).then(result => responseParse(result, false)
.then(result => resolve(result))
.catch(error => reject(error)))
.catch(error => reject(error))
})
}
exchangeAPI.removeDistributor = function(distributor, asset, floID, proxySecret) {
return new Promise((resolve, reject) => {
let request = {
floID: floID,
distributor: distributor,
asset: asset,
timestamp: Date.now()
};
if (floCrypto.getFloID(proxySecret) === floID) //Direct signing (without proxy)
request.pubKey = floCrypto.getPubKeyHex(proxySecret);
request.sign = signRequest({
type: "remove_distributor",
distributor: distributor,
asset: asset,
timestamp: request.timestamp
}, proxySecret);
console.debug(request);
fetch_api('/remove-distributor', {
method: "POST",
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(request)
}).then(result => responseParse(result, false)
.then(result => resolve(result))
.catch(error => reject(error)))
.catch(error => reject(error))
})
}
exchangeAPI.init = function refreshDataFromBlockchain(adminID = floGlobals.adminID, appName = floGlobals.application) { exchangeAPI.init = function refreshDataFromBlockchain(adminID = floGlobals.adminID, appName = floGlobals.application) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let nodes, lastTx; let nodes, lastTx;

View File

@ -42,7 +42,7 @@
return reject("Invalid amount"); return reject("Invalid amount");
this.getBalance(senderID, token).then(bal => { this.getBalance(senderID, token).then(bal => {
if (amount > bal) if (amount > bal)
return reject("Insufficiant token balance"); return reject("Insufficient token balance");
floBlockchainAPI.writeData(senderID, `send ${amount} ${token}# ${message}`, privKey, receiverID) floBlockchainAPI.writeData(senderID, `send ${amount} ${token}# ${message}`, privKey, receiverID)
.then(txid => resolve(txid)) .then(txid => resolve(txid))
.catch(error => reject(error)) .catch(error => reject(error))

View File

@ -91,6 +91,8 @@ module.exports = function App(secret, DB) {
//Manage user tags (Access to trusted IDs only) //Manage user tags (Access to trusted IDs only)
app.post('/add-tag', Request.AddUserTag); app.post('/add-tag', Request.AddUserTag);
app.post('/remove-tag', Request.RemoveUserTag); app.post('/remove-tag', Request.RemoveUserTag);
app.post('/add-distributor', Request.AddDistributor);
app.post('/remove-distributor', Request.RemoveDistributor);
Request.DB = DB; Request.DB = DB;
Request.secret = secret; Request.secret = secret;

View File

@ -186,7 +186,7 @@ function processBackupData(response) {
console.log("Backup Sync completed successfully"); console.log("Backup Sync completed successfully");
self.close(); self.close();
} else } else
console.log("Waiting for come re-sync data"); console.log("Waiting for re-sync data");
}).catch(_ => { }).catch(_ => {
console.warn("Backup Sync was not successful"); console.warn("Backup Sync was not successful");
self.close(); self.close();

View File

@ -178,10 +178,7 @@ function auditBalance(sellerID, buyerID, asset) {
module.exports = { module.exports = {
initiate: startCouplingForAsset, initiate: startCouplingForAsset,
group: { group: group,
addTag: group.addTag,
removeTag: group.removeTag
},
price, price,
set DB(db) { set DB(db) {
DB = db; DB = db;

View File

@ -10,7 +10,7 @@ function addTag(floID, tag) {
if (error.code === "ER_DUP_ENTRY") if (error.code === "ER_DUP_ENTRY")
reject(INVALID(`${floID} already in ${tag}`)); reject(INVALID(`${floID} already in ${tag}`));
else if (error.code === "ER_NO_REFERENCED_ROW") else if (error.code === "ER_NO_REFERENCED_ROW")
reject(INVALID(`Invalid user-floID and/or Tag`)); reject(INVALID(`Invalid Tag`));
else else
reject(error); reject(error);
}); });
@ -25,6 +25,37 @@ function removeTag(floID, tag) {
}) })
} }
function addDistributor(floID, asset) {
return new Promise((resolve, reject) => {
DB.query("INSERT INTO Distributors (floID, asset) VALUE (?,?)", [floID, asset])
.then(result => resolve(`Added ${asset} distributor: ${floID}`))
.catch(error => {
if (error.code === "ER_DUP_ENTRY")
reject(INVALID(`${floID} is already ${asset} disributor`));
else if (error.code === "ER_NO_REFERENCED_ROW")
reject(INVALID(`Invalid Asset`));
else
reject(error);
});
});
}
function removeDistributor(floID, asset) {
return new Promise((resolve, reject) => {
DB.query("DELETE FROM Distributors WHERE floID=? AND tag=?", [floID, asset])
.then(result => resolve(`Removed ${asset} distributor: ${floID}`))
.catch(error => reject(error));
})
}
function checkDistributor(floID, asset) {
new Promise((resolve, reject) => {
DB.query("SELECT id FROM Distributors WHERE floID=? AND asset=?", [floID, asset])
.then(result => resolve(result.length ? true : false))
.catch(error => reject(error))
})
}
function getBestPairs(asset, cur_rate) { function getBestPairs(asset, cur_rate) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
DB.query("SELECT tag, sellPriority, buyPriority FROM TagList").then(result => { DB.query("SELECT tag, sellPriority, buyPriority FROM TagList").then(result => {
@ -378,6 +409,9 @@ function verifyBuyOrder(buyOrder, cur_price) {
module.exports = { module.exports = {
addTag, addTag,
removeTag, removeTag,
addDistributor,
removeDistributor,
checkDistributor,
getBestPairs, getBestPairs,
set DB(db) { set DB(db) {
DB = db; DB = db;

View File

@ -63,37 +63,27 @@ function getBalance(floID, token) {
} }
getBalance.floID_token = (floID, token) => new Promise((resolve, reject) => { getBalance.floID_token = (floID, token) => new Promise((resolve, reject) => {
(token === floGlobals.currency ? DB.query("SELECT quantity AS balance FROM UserBalance WHERE floID=? AND token=?", [floID, token]).then(result => resolve({
DB.query("SELECT IFNULL(SUM(balance), 0) AS balance FROM Cash WHERE floID=?", [floID]) :
DB.query("SELECT IFNULL(SUM(quantity), 0) AS balance FROM Vault WHERE floID=? AND asset=?", [floID, token])
).then(result => resolve({
floID, floID,
token, token,
balance: result[0].balance.toFixed(8) balance: result.length ? result[0].balance.toFixed(8) : 0
})).catch(error => reject(error)) })).catch(error => reject(error))
}); });
getBalance.floID = (floID) => new Promise((resolve, reject) => { getBalance.floID = (floID) => new Promise((resolve, reject) => {
Promise.all([ DB.query("SELECT token, quantity AS balance FROM UserBalance WHERE floID=?", [floID]).then(result => {
DB.query("SELECT IFNULL(SUM(balance), 0) AS balance FROM Cash WHERE floID=?", [floID]),
DB.query("SELECT asset, IFNULL(SUM(quantity), 0) AS balance FROM Vault WHERE floID=? GROUP BY asset", [floID])
]).then(result => {
let response = { let response = {
floID, floID,
balance: {} balance: {}
}; };
response.balance[floGlobals.currency] = result[0][0].balance.toFixed(8); for (let row of result)
for (let row of result[1]) response.balance[row.token] = row.balance.toFixed(8);
response.balance[row.asset] = row.balance.toFixed(8);
resolve(response); resolve(response);
}).catch(error => reject(error)) }).catch(error => reject(error))
}); });
getBalance.token = (token) => new Promise((resolve, reject) => { getBalance.token = (token) => new Promise((resolve, reject) => {
(token === floGlobals.currency ? DB.query("SELECT floID, quantity AS balance FROM UserBalance WHERE token=?", [token]).then(result => {
DB.query("SELECT floID, balance FROM Cash") :
DB.query("SELECT floID, IFNULL(SUM(quantity), 0) AS balance FROM Vault WHERE asset = ? GROUP BY floID", [token])
).then(result => {
let response = { let response = {
token: token, token: token,
balance: {} balance: {}
@ -105,13 +95,12 @@ getBalance.token = (token) => new Promise((resolve, reject) => {
}); });
const getAssetBalance = (floID, asset) => new Promise((resolve, reject) => { const getAssetBalance = (floID, asset) => new Promise((resolve, reject) => {
let promises = (asset === floGlobals.currency) ? [ let promises = [];
DB.query("SELECT IFNULL(SUM(balance), 0) AS balance FROM Cash WHERE floID=?", [floID]), promises.push(DB.query("SELECT IFNULL(SUM(quantity), 0) AS balance FROM UserBalance WHERE floID=? AND token=?", [floID, asset]));
DB.query("SELECT IFNULL(SUM(quantity*maxPrice), 0) AS locked FROM BuyOrder WHERE floID=?", [floID]) promises.push(asset === floGlobals.currency ?
] : [ DB.query("SELECT IFNULL(SUM(quantity*maxPrice), 0) AS locked FROM BuyOrder WHERE floID=?", [floID]) :
DB.query("SELECT IFNULL(SUM(quantity), 0) AS balance FROM Vault WHERE floID=? AND asset=?", [floID, asset]),
DB.query("SELECT IFNULL(SUM(quantity), 0) AS locked FROM SellOrder WHERE floID=? AND asset=?", [floID, asset]) DB.query("SELECT IFNULL(SUM(quantity), 0) AS locked FROM SellOrder WHERE floID=? AND asset=?", [floID, asset])
]; );
Promise.all(promises).then(result => resolve({ Promise.all(promises).then(result => resolve({
total: result[0][0].balance, total: result[0][0].balance,
locked: result[1][0].locked, locked: result[1][0].locked,
@ -130,29 +119,9 @@ getAssetBalance.check = (floID, asset, amount) => new Promise((resolve, reject)
}).catch(error => reject(error)) }).catch(error => reject(error))
}); });
const consumeAsset = (floID, asset, amount, txQueries = []) => new Promise((resolve, reject) => { const updateBalance = {};
//If asset/token is currency update Cash else consume from Vault updateBalance.consume = (floID, token, amount) => ["UPDATE UserBalance SET quantity=quantity-? WHERE floID=? AND token=?", [amount, floID, token]];
if (asset === floGlobals.currency) { updateBalance.add = (floID, token, amount) => ["INSERT INTO UserBalance (floID, token, quantity) VALUE (?, ?, ?) ON DUPLICATE KEY UPDATE quantity=quantity+?", [floID, token, amount, amount]];
txQueries.push(["UPDATE Cash SET balance=balance-? WHERE floID=?", [amount, floID]]);
return resolve(txQueries);
} else
DB.query("SELECT id, quantity FROM Vault WHERE floID=? AND asset=? ORDER BY locktime", [floID, asset]).then(coins => {
let rem = amount;
for (let i = 0; i < coins.length && rem > 0; i++) {
if (rem < coins[i].quantity) {
txQueries.push(["UPDATE Vault SET quantity=quantity-? WHERE id=?", [rem, coins[i].id]]);
rem = 0;
} else {
txQueries.push(["DELETE FROM Vault WHERE id=?", [coins[i].id]]);
rem -= coins[i].quantity;
}
}
if (rem > 0) //should not happen AS the total and net is checked already
reject(INVALID("Insufficient Asset"));
else
resolve(txQueries);
}).catch(error => reject(error));
});
function addSellOrder(floID, asset, quantity, min_price) { function addSellOrder(floID, asset, quantity, min_price) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
@ -233,8 +202,7 @@ function cancelOrder(type, id, floID) {
function getAccountDetails(floID) { function getAccountDetails(floID) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let select = []; let select = [];
select.push(["balance", "Cash"]); select.push(["token, quantity", "UserBalance"]);
select.push(["asset, AVG(base) AS avg_base, IFNULL(SUM(quantity), 0) AS quantity", "Vault", "GROUP BY asset"]);
select.push(["id, asset, quantity, minPrice, time_placed", "SellOrder"]); select.push(["id, asset, quantity, minPrice, time_placed", "SellOrder"]);
select.push(["id, asset, quantity, maxPrice, time_placed", "BuyOrder"]); select.push(["id, asset, quantity, maxPrice, time_placed", "BuyOrder"]);
let promises = select.map(a => DB.query(`SELECT ${a[0]} FROM ${a[1]} WHERE floID=? ${a[2] || ""}`, [floID])); let promises = select.map(a => DB.query(`SELECT ${a[0]} FROM ${a[1]} WHERE floID=? ${a[2] || ""}`, [floID]));
@ -249,15 +217,12 @@ function getAccountDetails(floID) {
else else
switch (i) { switch (i) {
case 0: case 0:
response.cash = a.value.length ? a.value[0].balance : 0; response.tokenBalance = a.value;
break; break;
case 1: case 1:
response.vault = a.value;
break;
case 2:
response.sellOrders = a.value; response.sellOrders = a.value;
break; break;
case 3: case 2:
response.buyOrders = a.value; response.buyOrders = a.value;
break; break;
} }
@ -311,13 +276,14 @@ function transferToken(sender, receivers, token) {
if (invalidIDs.length) if (invalidIDs.length)
reject(INVALID(`Invalid receiver (${invalidIDs})`)); reject(INVALID(`Invalid receiver (${invalidIDs})`));
else getAssetBalance.check(sender, token, totalAmount).then(_ => { else getAssetBalance.check(sender, token, totalAmount).then(_ => {
consumeAsset(sender, token, totalAmount).then(txQueries => { let txQueries = [];
if (token === floGlobals.currency) txQueries.push(updateBalance.consume(sender, token, totalAmount));
for (let floID in receivers)
txQueries.push(updateBalance.add(floID, token, receivers[floID]));
coupling.group.checkDistributor(sender, token).then(result => {
if (result)
for (let floID in receivers) for (let floID in receivers)
txQueries.push(["INSERT INTO Cash (floID, balance) VALUE (?, ?) ON DUPLICATE KEY UPDATE balance=balance+?", [floID, receivers[floID], receivers[floID]]]); txQueries.push(["INSERT INTO Vault (floID, asset, quantity) VALUES (?, ?, ?)", [floID, token, receivers[floID]]]);
else
for (let floID in receivers)
txQueries.push(["INSERT INTO Vault(floID, quantity, asset) VALUES (?, ?, ?)", [floID, receivers[floID], token]]);
let time = Date.now(); let time = Date.now();
let hash = TRANSFER_HASH_PREFIX + Crypto.SHA256(JSON.stringify({ let hash = TRANSFER_HASH_PREFIX + Crypto.SHA256(JSON.stringify({
sender: sender, sender: sender,
@ -364,7 +330,7 @@ function confirmDepositFLO() {
results.forEach(req => { results.forEach(req => {
confirmDepositFLO.checkTx(req.floID, req.txid).then(amount => { confirmDepositFLO.checkTx(req.floID, req.txid).then(amount => {
let txQueries = []; let txQueries = [];
txQueries.push(["INSERT INTO Vault(floID, quantity, asset) VALUES (?, ?, ?)", [req.floID, amount, "FLO"]]); txQueries.push(updateBalance.add(req.floID, "FLO", amount));
txQueries.push(["UPDATE InputFLO SET status=?, amount=? WHERE id=?", ["SUCCESS", amount, req.id]]); txQueries.push(["UPDATE InputFLO SET status=?, amount=? WHERE id=?", ["SUCCESS", amount, req.id]]);
DB.transaction(txQueries) DB.transaction(txQueries)
.then(result => console.debug("FLO deposited:", req.floID, amount)) .then(result => console.debug("FLO deposited:", req.floID, amount))
@ -410,23 +376,23 @@ function withdrawFLO(floID, amount) {
else if (typeof amount !== "number" || amount <= 0) else if (typeof amount !== "number" || amount <= 0)
return reject(INVALID(`Invalid amount (${amount})`)); return reject(INVALID(`Invalid amount (${amount})`));
getAssetBalance.check(floID, "FLO", amount).then(_ => { getAssetBalance.check(floID, "FLO", amount).then(_ => {
consumeAsset(floID, "FLO", amount).then(txQueries => { let txQueries = [];
DB.transaction(txQueries).then(result => { txQueries.push(updateBalance.consume(floID, "FLO", amount));
//Send FLO to user via blockchain API DB.transaction(txQueries).then(result => {
floBlockchainAPI.sendTx(global.sinkID, floID, amount, global.sinkPrivKey, 'Withdraw FLO Coins from Market').then(txid => { //Send FLO to user via blockchain API
if (!txid) floBlockchainAPI.sendTx(global.sinkID, floID, amount, global.sinkPrivKey, '(withdrawal from market)').then(txid => {
throw Error("Transaction not successful"); if (!txid)
//Transaction was successful, Add in DB throw Error("Transaction not successful");
DB.query("INSERT INTO OutputFLO (floID, amount, txid, status) VALUES (?, ?, ?, ?)", [floID, amount, txid, "WAITING_CONFIRMATION"]) //Transaction was successful, Add in DB
.then(_ => null).catch(error => console.error(error)) DB.query("INSERT INTO OutputFLO (floID, amount, txid, status) VALUES (?, ?, ?, ?)", [floID, amount, txid, "WAITING_CONFIRMATION"])
.finally(_ => resolve("Withdrawal was successful")); .then(_ => null).catch(error => console.error(error))
}).catch(error => { .finally(_ => resolve("Withdrawal was successful"));
console.error(error); }).catch(error => {
DB.query("INSERT INTO OutputFLO (floID, amount, status) VALUES (?, ?, ?)", [floID, amount, "PENDING"]) console.error(error);
.then(_ => null).catch(error => console.error(error)) DB.query("INSERT INTO OutputFLO (floID, amount, status) VALUES (?, ?, ?)", [floID, amount, "PENDING"])
.finally(_ => resolve("Withdrawal request is in process")); .then(_ => null).catch(error => console.error(error))
}); .finally(_ => resolve("Withdrawal request is in process"));
}).catch(error => reject(error)); });
}).catch(error => reject(error)); }).catch(error => reject(error));
}).catch(error => reject(error)); }).catch(error => reject(error));
}); });
@ -491,14 +457,11 @@ function confirmDepositToken() {
//Add the FLO balance if necessary //Add the FLO balance if necessary
if (!result.length) { if (!result.length) {
let amount_flo = amounts[2]; let amount_flo = amounts[2];
txQueries.push(["INSERT INTO Vault(floID, asset, quantity) VALUES (?, ?, ?)", [req.floID, "FLO", amount_flo]]); txQueries.push(updateBalance.add(req.floID, "FLO", amount_flo));
txQueries.push(["INSERT INTO InputFLO(txid, floID, amount, status) VALUES (?, ?, ?, ?)", [req.txid, req.floID, amount_flo, "SUCCESS"]]); txQueries.push(["INSERT INTO InputFLO(txid, floID, amount, status) VALUES (?, ?, ?, ?)", [req.txid, req.floID, amount_flo, "SUCCESS"]]);
} }
txQueries.push(["UPDATE InputToken SET status=?, token=?, amount=? WHERE id=?", ["SUCCESS", token_name, amount_token, req.id]]); txQueries.push(["UPDATE InputToken SET status=?, token=?, amount=? WHERE id=?", ["SUCCESS", token_name, amount_token, req.id]]);
if (token_name === floGlobals.currency) txQueries.push(updateBalance.add(req.floID, token_name, amount_token));
txQueries.push(["INSERT INTO Cash (floID, balance) VALUE (?, ?) ON DUPLICATE KEY UPDATE balance=balance+?", [req.floID, amount_token, amount_token]]);
else
txQueries.push(["INSERT INTO Vault(floID, asset, quantity) VALUES (?, ?, ?)", [req.floID, token_name, amount_token]]);
DB.transaction(txQueries) DB.transaction(txQueries)
.then(result => console.debug("Token deposited:", req.floID, token_name, amount_token)) .then(result => console.debug("Token deposited:", req.floID, token_name, amount_token))
.catch(error => console.error(error)); .catch(error => console.error(error));
@ -551,24 +514,23 @@ function withdrawToken(floID, token, amount) {
let required_flo = floGlobals.sendAmt + floGlobals.fee; let required_flo = floGlobals.sendAmt + floGlobals.fee;
getAssetBalance.check(floID, "FLO", required_flo).then(_ => { getAssetBalance.check(floID, "FLO", required_flo).then(_ => {
getAssetBalance.check(floID, token, amount).then(_ => { getAssetBalance.check(floID, token, amount).then(_ => {
consumeAsset(floID, "FLO", required_flo).then(txQueries => { let txQueries = [];
consumeAsset(floID, token, amount, txQueries).then(txQueries => { txQueries.push(updateBalance.consume(floID, "FLO", required_flo));
DB.transaction(txQueries).then(result => { txQueries.push(updateBalance.consume(floID, token, amount));
//Send FLO to user via blockchain API DB.transaction(txQueries).then(result => {
floTokenAPI.sendToken(global.sinkPrivKey, amount, floID, '(withdrawal from market)', token).then(txid => { //Send FLO to user via blockchain API
if (!txid) throw Error("Transaction not successful"); floTokenAPI.sendToken(global.sinkPrivKey, amount, floID, '(withdrawal from market)', token).then(txid => {
//Transaction was successful, Add in DB if (!txid) throw Error("Transaction not successful");
DB.query("INSERT INTO OutputToken (floID, token, amount, txid, status) VALUES (?, ?, ?, ?, ?)", [floID, token, amount, txid, "WAITING_CONFIRMATION"]) //Transaction was successful, Add in DB
.then(_ => null).catch(error => console.error(error)) DB.query("INSERT INTO OutputToken (floID, token, amount, txid, status) VALUES (?, ?, ?, ?, ?)", [floID, token, amount, txid, "WAITING_CONFIRMATION"])
.finally(_ => resolve("Withdrawal was successful")); .then(_ => null).catch(error => console.error(error))
}).catch(error => { .finally(_ => resolve("Withdrawal was successful"));
console.error(error); }).catch(error => {
DB.query("INSERT INTO OutputToken (floID, token, amount, status) VALUES (?, ?, ?, ?)", [floID, token, amount, "PENDING"]) console.error(error);
.then(_ => null).catch(error => console.error(error)) DB.query("INSERT INTO OutputToken (floID, token, amount, status) VALUES (?, ?, ?, ?)", [floID, token, amount, "PENDING"])
.finally(_ => resolve("Withdrawal request is in process")); .then(_ => null).catch(error => console.error(error))
}); .finally(_ => resolve("Withdrawal request is in process"));
}).catch(error => reject(error)); });
}).catch(error => reject(error));
}).catch(error => reject(error)); }).catch(error => reject(error));
}).catch(error => reject(error)); }).catch(error => reject(error));
}).catch(error => reject(error)); }).catch(error => reject(error));

View File

@ -281,6 +281,34 @@ function RemoveUserTag(req, res) {
); );
} }
function AddDistributor(req, res) {
let data = req.body;
if (!trustedIDs.includes(data.floID))
res.status(INVALID.e_code).send("Access Denied");
else processRequest(res, "Add distributor", {
type: "add_distributor",
distributor: data.distributor,
asset: data.asset,
timestamp: data.timestamp
}, data.sign, data.floID, data.pubKey,
() => market.group.addDistributor(data.distributor, data.asset)
);
}
function RemoveDistributor(req, res) {
let data = req.body;
if (!trustedIDs.includes(data.floID))
res.status(INVALID.e_code).send("Access Denied");
else processRequest(res, "Remove distributor", {
type: "remove_distributor",
distributor: data.distributor,
asset: data.asset,
timestamp: data.timestamp
}, data.sign, data.floID, data.pubKey,
() => market.group.removeDistributor(data.distributor, data.asset)
);
}
/* Public Requests */ /* Public Requests */
function GetLoginCode(req, res) { function GetLoginCode(req, res) {
@ -415,6 +443,8 @@ module.exports = {
periodicProcess: market.periodicProcess, periodicProcess: market.periodicProcess,
AddUserTag, AddUserTag,
RemoveUserTag, RemoveUserTag,
AddDistributor,
RemoveDistributor,
set trustedIDs(ids) { set trustedIDs(ids) {
trustedIDs = ids; trustedIDs = ids;
}, },