fixed type of crypto check during operations
This commit is contained in:
parent
63010c4ca3
commit
5427badb3b
@ -9085,7 +9085,7 @@
|
|||||||
let RMAssets = floData.slice(5);
|
let RMAssets = floData.slice(5);
|
||||||
|
|
||||||
// remove this line later
|
// remove this line later
|
||||||
// btcTradeMargin is tolerable difference between BTC trader should deposit and BTC he actually deposited
|
// btcTradeMargin is tolerable difference between Crypto trader should deposit and cryptos he actually deposited
|
||||||
RMAssets =
|
RMAssets =
|
||||||
`tradableAsset1=BTC,FLO#!#tradableAsset2=INR,USD,BTC,FLO#!#supernodes=127.0.0.1,212.88.88.2#!#MASTER_NODE=023B9F60692A17FAC805D012C5C8ADA3DD19A980A3C5F0D8A5B3500CC54D6E8B75
|
`tradableAsset1=BTC,FLO#!#tradableAsset2=INR,USD,BTC,FLO#!#supernodes=127.0.0.1,212.88.88.2#!#MASTER_NODE=023B9F60692A17FAC805D012C5C8ADA3DD19A980A3C5F0D8A5B3500CC54D6E8B75
|
||||||
#!#MASTER_RECEIVING_ADDRESS=oVRq2nka1GtALQT8pbuLHAGjqAQ7PAo6uy#!#validTradingAmount=10000,50000,100000#!#btcTradeMargin=5000
|
#!#MASTER_RECEIVING_ADDRESS=oVRq2nka1GtALQT8pbuLHAGjqAQ7PAo6uy#!#validTradingAmount=10000,50000,100000#!#btcTradeMargin=5000
|
||||||
@ -9663,7 +9663,7 @@
|
|||||||
case "sync_with_supernode":
|
case "sync_with_supernode":
|
||||||
localbitcoinplusplus.rpc.prototype.filter_legit_requests(function (is_valid_request) {
|
localbitcoinplusplus.rpc.prototype.filter_legit_requests(function (is_valid_request) {
|
||||||
if (is_valid_request === true && params.job=="SYNC_MY_LOCAL_DB_WITH_SUPERNODE_DB" && params.trader_flo_address.length>0) {
|
if (is_valid_request === true && params.job=="SYNC_MY_LOCAL_DB_WITH_SUPERNODE_DB" && params.trader_flo_address.length>0) {
|
||||||
const tableArray = ["deposit", "withdraw_cash", "withdraw_btc", "btc_balances", "cash_balances", "userPublicData"];
|
const tableArray = ["deposit", "withdraw_cash", "withdraw_btc", "crypto_balances", "cash_balances", "userPublicData"];
|
||||||
localbitcoinplusplus.actions.get_sharable_db_data(tableArray).then(function(su_db_data) {
|
localbitcoinplusplus.actions.get_sharable_db_data(tableArray).then(function(su_db_data) {
|
||||||
if (typeof su_db_data == "object") {
|
if (typeof su_db_data == "object") {
|
||||||
su_db_data.trader_flo_address = params.trader_flo_address;
|
su_db_data.trader_flo_address = params.trader_flo_address;
|
||||||
@ -9703,17 +9703,13 @@
|
|||||||
|
|
||||||
await localbitcoinplusplus.trade.prototype.resolve_current_btc_price_in_fiat(params.currency);
|
await localbitcoinplusplus.trade.prototype.resolve_current_btc_price_in_fiat(params.currency);
|
||||||
|
|
||||||
if (params.product == "BTC") {
|
if (localbitcoinplusplus.master_configurations.tradableAsset1.includes(params.product)) {
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
// YOU HAVE TO PROVIDE BTC KEYS HERE. CHANGE IT LATER
|
// YOU HAVE TO PROVIDE BTC KEYS HERE. CHANGE IT LATER
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
let generate_btc_keys_for_requester = localbitcoinplusplus.wallets.prototype
|
let generate_btc_keys_for_requester = localbitcoinplusplus.wallets.prototype
|
||||||
.generateFloKeys.call();
|
.generateFloKeys.call();
|
||||||
|
|
||||||
/************************************************************************************
|
|
||||||
// Need to do: Super Node saves the private keys and sends the BTC address to the requester
|
|
||||||
// THIS IS VERY DANGEROUS STEP BCOZ BTC PRIVATE KEY DATA CAN BE LEAKED HERE IF ANYTHING GOES WRONG
|
|
||||||
*****************************************************************************/
|
|
||||||
params.id = helper_functions.unique_id();
|
params.id = helper_functions.unique_id();
|
||||||
params.status = 1;
|
params.status = 1;
|
||||||
params.btc_address = generate_btc_keys_for_requester.address;
|
params.btc_address = generate_btc_keys_for_requester.address;
|
||||||
@ -9963,15 +9959,15 @@
|
|||||||
await localbitcoinplusplus.trade.prototype.resolve_current_btc_price_in_fiat(params.currency);
|
await localbitcoinplusplus.trade.prototype.resolve_current_btc_price_in_fiat(params.currency);
|
||||||
params.id = helper_functions.unique_id();
|
params.id = helper_functions.unique_id();
|
||||||
params.status = 1;
|
params.status = 1;
|
||||||
if (params.product == "BTC") {
|
if (localbitcoinplusplus.master_configurations.tradableAsset1.includes(params.product)) {
|
||||||
// Check how much Bitcoins the user can withdraw
|
// Check how much cryptos the user can withdraw
|
||||||
readDB("btc_balances", params.trader_flo_address).then(function (
|
let withdrawer_btc_id = `${params.trader_flo_address}_${params.product}`;
|
||||||
btc_balance_res) {
|
readDB("crypto_balances", withdrawer_btc_id).then(function (btc_balance_res) {
|
||||||
if (typeof btc_balance_res == "object" && typeof btc_balance_res
|
if (typeof btc_balance_res == "object" && typeof btc_balance_res
|
||||||
.trader_flo_address == "string" &&
|
.trader_flo_address == "string" &&
|
||||||
typeof btc_balance_res.btc_balance == "number" &&
|
typeof btc_balance_res.crypto_balance == "number" &&
|
||||||
btc_balance_res.btc_balance > 0) {
|
btc_balance_res.crypto_balance > 0) {
|
||||||
let withdrawer_btc_balance = parseFloat(btc_balance_res.btc_balance);
|
let withdrawer_btc_balance = parseFloat(btc_balance_res.crypto_balance);
|
||||||
let withdrawing_btc_amount_in_cash = parseFloat(params.withdrawing_amount);
|
let withdrawing_btc_amount_in_cash = parseFloat(params.withdrawing_amount);
|
||||||
if(!localbitcoinplusplus.master_configurations.tradableAsset2.includes(params.currency)) {
|
if(!localbitcoinplusplus.master_configurations.tradableAsset2.includes(params.currency)) {
|
||||||
throw new Error("Invalid or unsupported currency.");
|
throw new Error("Invalid or unsupported currency.");
|
||||||
@ -10001,7 +9997,7 @@
|
|||||||
deposit_list.length > 0) {
|
deposit_list.length > 0) {
|
||||||
deposit_list = deposit_list.filter(
|
deposit_list = deposit_list.filter(
|
||||||
deposits => deposits.status == 2
|
deposits => deposits.status == 2
|
||||||
&& deposits.product == "BTC");
|
&& localbitcoinplusplus.master_configurations.tradableAsset1.includes(deposits.product));
|
||||||
for (const dl in deposit_list) {
|
for (const dl in deposit_list) {
|
||||||
if (deposit_list.hasOwnProperty(dl)) {
|
if (deposit_list.hasOwnProperty(dl)) {
|
||||||
const deposit_dl = deposit_list[dl];
|
const deposit_dl = deposit_list[dl];
|
||||||
@ -10201,7 +10197,7 @@
|
|||||||
if (typeof res == "string" && res.length>0) {
|
if (typeof res == "string" && res.length>0) {
|
||||||
try {
|
try {
|
||||||
let resp_obj = JSON.parse(res);
|
let resp_obj = JSON.parse(res);
|
||||||
let msg = `Transaction Id for your withdrawn BTC: ${resp_obj.txid.result}`;
|
let msg = `Transaction Id for your withdrawn crypto asset: ${resp_obj.txid.result}`;
|
||||||
writeToScreen(msg);
|
writeToScreen(msg);
|
||||||
alert(msg);
|
alert(msg);
|
||||||
return true;
|
return true;
|
||||||
@ -10488,12 +10484,13 @@
|
|||||||
throw new Error("Invalid sell request.");
|
throw new Error("Invalid sell request.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check BTC balance of the seller
|
// Check crypto balance of the seller
|
||||||
readDB("btc_balances", params.trader_flo_address).then(function (res) {
|
let seller_btc_id = `${params.trader_flo_address}_${params.product}`;
|
||||||
|
readDB("crypto_balances", seller_btc_id).then(function (res) {
|
||||||
if (typeof res !== "undefined" && typeof res.trader_flo_address == "string" && res.trader_flo_address
|
if (typeof res !== "undefined" && typeof res.trader_flo_address == "string" && res.trader_flo_address
|
||||||
.length > 0 &&
|
.length > 0 &&
|
||||||
typeof res.btc_balance == "number" && res.btc_balance > 0) {
|
typeof res.crypto_balance == "number" && res.crypto_balance > 0) {
|
||||||
let seller_btc_balance = parseFloat(res.btc_balance);
|
let seller_btc_balance = parseFloat(res.crypto_balance);
|
||||||
let sell_price_in_inr = parseFloat(params.buy_price);
|
let sell_price_in_inr = parseFloat(params.buy_price);
|
||||||
let eqBTC = localbitcoinplusplus.trade.prototype.calculateBTCEquivalentOfCash(sell_price_in_inr, params.currency);
|
let eqBTC = localbitcoinplusplus.trade.prototype.calculateBTCEquivalentOfCash(sell_price_in_inr, params.currency);
|
||||||
eqBTC = parseFloat(eqBTC);
|
eqBTC = parseFloat(eqBTC);
|
||||||
@ -10777,11 +10774,12 @@
|
|||||||
eqBTCBuyer = parseFloat(eqBTCBuyer);
|
eqBTCBuyer = parseFloat(eqBTCBuyer);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check seller's BTC balance
|
// Check seller's crypto balance
|
||||||
readDB("btc_balances", sellPipeObj.trader_flo_address).then(function (sellPipeBTCRes) {
|
let seller_btc_id = `${sellPipeObj.trader_flo_address}_${sellPipeObj.product}`;
|
||||||
if (typeof sellPipeBTCRes == "object" && typeof sellPipeBTCRes.btc_balance ==
|
readDB("crypto_balances", seller_btc_id).then(function (sellPipeBTCRes) {
|
||||||
|
if (typeof sellPipeBTCRes == "object" && typeof sellPipeBTCRes.crypto_balance ==
|
||||||
"number") {
|
"number") {
|
||||||
let seller_btc_balance = parseFloat(sellPipeBTCRes.btc_balance)
|
let seller_btc_balance = parseFloat(sellPipeBTCRes.crypto_balance)
|
||||||
.toFixed(8);
|
.toFixed(8);
|
||||||
let sell_price_in_inr = parseFloat(sellPipeObj.buy_price);
|
let sell_price_in_inr = parseFloat(sellPipeObj.buy_price);
|
||||||
let eqBTCSeller = localbitcoinplusplus.trade.prototype.calculateBTCEquivalentOfCash(
|
let eqBTCSeller = localbitcoinplusplus.trade.prototype.calculateBTCEquivalentOfCash(
|
||||||
@ -10793,21 +10791,24 @@
|
|||||||
throw new Error("Insufficient BTC balance of seller.");
|
throw new Error("Insufficient BTC balance of seller.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Increase buyer's BTC balance
|
// Increase buyer's crypto balance
|
||||||
let buyerBTCResponseObject;
|
let buyerBTCResponseObject;
|
||||||
readDB("btc_balances", buyPipeObj.trader_flo_address).then(
|
let buyer_btc_id = `${buyPipeObj.trader_flo_address}_${buyPipeObj.product}`;
|
||||||
|
readDB("crypto_balances", buyPipeObj.trader_flo_address).then(
|
||||||
function (buyPipeBTCRes) {
|
function (buyPipeBTCRes) {
|
||||||
if (typeof buyPipeBTCRes == "object" && typeof buyPipeBTCRes
|
if (typeof buyPipeBTCRes == "object" && typeof buyPipeBTCRes
|
||||||
.btc_balance == "number") {
|
.crypto_balance == "number") {
|
||||||
buyPipeBTCRes.btc_balance = parseFloat(
|
buyPipeBTCRes.crypto_balance = parseFloat(
|
||||||
buyPipeBTCRes.btc_balance) +
|
buyPipeBTCRes.crypto_balance) +
|
||||||
eqBTCBuyer;
|
eqBTCBuyer;
|
||||||
buyerBTCResponseObject = buyPipeBTCRes;
|
buyerBTCResponseObject = buyPipeBTCRes;
|
||||||
} else {
|
} else {
|
||||||
// The user bought BTC for first time
|
// The user bought BTC for first time
|
||||||
buyerBTCResponseObject = {
|
buyerBTCResponseObject = {
|
||||||
|
id: `${buyPipeObj.trader_flo_address}_${buyPipeObj.product}`,
|
||||||
trader_flo_address: buyPipeObj.trader_flo_address,
|
trader_flo_address: buyPipeObj.trader_flo_address,
|
||||||
btc_balance: eqBTCBuyer
|
crypto_balance: eqBTCBuyer,
|
||||||
|
crypto_currency: buyPipeObj.product
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -10848,13 +10849,13 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Decrease seller BTC balance
|
// Decrease seller BTC balance
|
||||||
let new_seller_btc_balance =
|
let new_seller_btc_balance = seller_btc_balance - eqBTCSeller;
|
||||||
seller_btc_balance -
|
new_seller_btc_balance = parseFloat(new_seller_btc_balance).toFixed(8);
|
||||||
eqBTCSeller;
|
|
||||||
let sellerBTCResponseObject = {
|
let sellerBTCResponseObject = {
|
||||||
trader_flo_address: sellPipeObj
|
id: `${sellPipeObj.trader_flo_address}_${sellPipeObj.product}`,
|
||||||
.trader_flo_address,
|
trader_flo_address: sellPipeObj.trader_flo_address,
|
||||||
btc_balance: new_seller_btc_balance
|
crypto_balance: new_seller_btc_balance,
|
||||||
|
crypto_currency: sellPipeObj.product
|
||||||
}
|
}
|
||||||
|
|
||||||
// supernode data query
|
// supernode data query
|
||||||
@ -10895,13 +10896,13 @@
|
|||||||
.trader_flo_address
|
.trader_flo_address
|
||||||
);
|
);
|
||||||
updateinDB(
|
updateinDB(
|
||||||
"btc_balances",
|
"crypto_balances",
|
||||||
buyerBTCResponseObject,
|
buyerBTCResponseObject,
|
||||||
buyPipeObj
|
buyPipeObj
|
||||||
.trader_flo_address
|
.trader_flo_address
|
||||||
);
|
);
|
||||||
updateinDB(
|
updateinDB(
|
||||||
"btc_balances",
|
"crypto_balances",
|
||||||
sellerBTCResponseObject,
|
sellerBTCResponseObject,
|
||||||
sellPipeObj
|
sellPipeObj
|
||||||
.trader_flo_address
|
.trader_flo_address
|
||||||
@ -11342,7 +11343,7 @@
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
let obj = su_db_data[tableStoreName];
|
let obj = su_db_data[tableStoreName];
|
||||||
if (["btc_balances", "cash_balances", "userPublicData"].includes(tableStoreName)) {
|
if (["crypto_balances", "cash_balances", "userPublicData"].includes(tableStoreName)) {
|
||||||
if (obj.length>0) {
|
if (obj.length>0) {
|
||||||
for (var prop in obj) {
|
for (var prop in obj) {
|
||||||
if(!obj.hasOwnProperty(prop)) continue;
|
if(!obj.hasOwnProperty(prop)) continue;
|
||||||
@ -11449,9 +11450,9 @@
|
|||||||
trade_balance_res.trade_infos.buyer_flo_id);
|
trade_balance_res.trade_infos.buyer_flo_id);
|
||||||
updateinDB("cash_balances", trade_balance_res.seller_cash_data,
|
updateinDB("cash_balances", trade_balance_res.seller_cash_data,
|
||||||
trade_balance_res.trade_infos.seller_flo_id);
|
trade_balance_res.trade_infos.seller_flo_id);
|
||||||
updateinDB("btc_balances", trade_balance_res.buyer_btc_data,
|
updateinDB("crypto_balances", trade_balance_res.buyer_btc_data,
|
||||||
trade_balance_res.trade_infos.buyer_flo_id);
|
trade_balance_res.trade_infos.buyer_flo_id);
|
||||||
updateinDB("btc_balances", trade_balance_res.seller_btc_data,
|
updateinDB("crypto_balances", trade_balance_res.seller_btc_data,
|
||||||
trade_balance_res.trade_infos.seller_flo_id);
|
trade_balance_res.trade_infos.seller_flo_id);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
callback(false);
|
callback(false);
|
||||||
@ -11807,10 +11808,11 @@
|
|||||||
depositor_found_at: null
|
depositor_found_at: null
|
||||||
}
|
}
|
||||||
|
|
||||||
const btc_balances = {
|
const crypto_balances = {
|
||||||
id: null,
|
id: null,
|
||||||
trader_flo_address: null,
|
trader_flo_address: null,
|
||||||
btc_balance: null
|
crypto_balance: null,
|
||||||
|
crypto_currency:null
|
||||||
}
|
}
|
||||||
|
|
||||||
const cash_balances = {
|
const cash_balances = {
|
||||||
@ -11919,8 +11921,8 @@
|
|||||||
unique: true
|
unique: true
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (!db.objectStoreNames.contains('btc_balances')) {
|
if (!db.objectStoreNames.contains('crypto_balances')) {
|
||||||
var objectStore = db.createObjectStore("btc_balances", {
|
var objectStore = db.createObjectStore("crypto_balances", {
|
||||||
keyPath: 'id', autoIncrement: false
|
keyPath: 'id', autoIncrement: false
|
||||||
});
|
});
|
||||||
objectStore.createIndex('trader_flo_address', 'trader_flo_address', {
|
objectStore.createIndex('trader_flo_address', 'trader_flo_address', {
|
||||||
@ -12667,17 +12669,20 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let trader_depositor_cash_id = `${trader_deposits.trader_flo_address}_${trader_deposits.product}`;
|
||||||
let updatedBTCbalances = {
|
let updatedBTCbalances = {
|
||||||
|
id: trader_depositor_cash_id,
|
||||||
trader_flo_address: trader_deposits.trader_flo_address,
|
trader_flo_address: trader_deposits.trader_flo_address,
|
||||||
btc_balance: balance
|
crypto_balance: balance,
|
||||||
|
crypto_currency: trader_deposits.product
|
||||||
}
|
}
|
||||||
readDB('btc_balances', trader_deposits.trader_flo_address).then(function (res_btc_balances) {
|
readDB('crypto_balances', trader_depositor_cash_id).then(function (res_btc_balances) {
|
||||||
if (typeof res_btc_balances == "object" && typeof res_btc_balances.result ==
|
if (typeof res_btc_balances == "object" && typeof res_btc_balances.result ==
|
||||||
"object" && typeof res_btc_balances.result.btc_balance=="number") {
|
"object" && typeof res_btc_balances.crypto_balance=="number") {
|
||||||
updatedBTCbalances.btc_balance += parseFloat(res_btc_balances.result.btc_balance);
|
updatedBTCbalances.crypto_balance += parseFloat(res_btc_balances.crypto_balance);
|
||||||
}
|
}
|
||||||
// Update BTC balance of user in btc_balances
|
// Update crypto balance of user in crypto_balances
|
||||||
updateinDB("btc_balances", updatedBTCbalances, trader_deposits.btc_address);
|
updateinDB("crypto_balances", updatedBTCbalances, trader_deposits.btc_address);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -12690,7 +12695,7 @@
|
|||||||
setInterval(function () {
|
setInterval(function () {
|
||||||
readDBbyIndex("deposit", 'status', 1).then(function (res) {
|
readDBbyIndex("deposit", 'status', 1).then(function (res) {
|
||||||
res.map(function (deposit_trade) {
|
res.map(function (deposit_trade) {
|
||||||
if (deposit_trade.product == "BTC") {
|
if (localbitcoinplusplus.master_configurations.tradableAsset1.includes(deposit_trade.product)) {
|
||||||
validateDepositedBTCBalance(deposit_trade);
|
validateDepositedBTCBalance(deposit_trade);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user