fixed db functions for primary and backup db
This commit is contained in:
parent
ab6fab887c
commit
701db7da42
@ -10143,9 +10143,10 @@
|
||||
get_sharable_db_data: async function (dbTableNamesArray, backup_db="") {
|
||||
let arr = {};
|
||||
if (typeof backup_db=="string" && backup_db.length>0) {
|
||||
let _readAllDB = readAllDB;
|
||||
if (typeof localbitcoinplusplus.newBackupDatabase.db[backup_db] == "object") {
|
||||
const foreign_db = localbitcoinplusplus.newBackupDatabase.db[backup_db];
|
||||
readAllDB = foreign_db.backup_readAllDB.bind(foreign_db);
|
||||
_readAllDB = foreign_db.backup_readAllDB.bind(foreign_db);
|
||||
} else {
|
||||
err_msg = `WARNING: Invalid Backup DB Instance Id: ${backup_db}.`;
|
||||
showMessage(err_msg);
|
||||
@ -10153,17 +10154,18 @@
|
||||
}
|
||||
}
|
||||
for (const elem of dbTableNamesArray) {
|
||||
await readAllDB(elem).then(e => arr[elem] = e);
|
||||
await _readAllDB(elem).then(e => arr[elem] = e);
|
||||
}
|
||||
return arr;
|
||||
},
|
||||
|
||||
get_sharable_db_data_for_single_user: async function (dbTableNamesArray, backup_db="") {
|
||||
let arr = {};
|
||||
let _readDBbyIndex = readDBbyIndex;
|
||||
if (typeof backup_db=="string" && backup_db.length>0) {
|
||||
if (typeof localbitcoinplusplus.newBackupDatabase.db[backup_db] == "object") {
|
||||
const foreign_db = localbitcoinplusplus.newBackupDatabase.db[backup_db];
|
||||
readAllDB = foreign_db.backup_readAllDB.bind(foreign_db);
|
||||
_readDBbyIndex = foreign_db.backup_readDBbyIndex.bind(foreign_db);
|
||||
} else {
|
||||
err_msg = `WARNING: Invalid Backup DB Instance Id: ${backup_db}.`;
|
||||
showMessage(err_msg);
|
||||
@ -10171,7 +10173,7 @@
|
||||
}
|
||||
}
|
||||
for (const elem of dbTableNamesArray) {
|
||||
await readDBbyIndex(elem).then(e => arr[elem] = e);
|
||||
await _readDBbyIndex(elem).then(e => arr[elem] = e);
|
||||
}
|
||||
return arr;
|
||||
},
|
||||
@ -13924,16 +13926,12 @@
|
||||
}
|
||||
|
||||
if (typeof backup_db=="string" && backup_db.length>0) {
|
||||
let _addDB = addDB;
|
||||
let _readDB = readDB;
|
||||
if (typeof localbitcoinplusplus.newBackupDatabase.db[backup_db] == "object") {
|
||||
const foreign_db = localbitcoinplusplus.newBackupDatabase.db[backup_db];
|
||||
addDB = foreign_db.backup_addDB.bind(foreign_db);
|
||||
readDB = foreign_db.backup_readDB.bind(foreign_db);
|
||||
readDBbyIndex = foreign_db.backup_readDBbyIndex.bind(foreign_db);
|
||||
readAllDB = foreign_db.backup_readAllDB.bind(foreign_db);
|
||||
updateinDB = foreign_db.backup_updateinDB.bind(foreign_db);
|
||||
removeinDB = foreign_db.backup_removeinDB.bind(foreign_db);
|
||||
removeByIndex = foreign_db.backup_removeByIndex.bind(foreign_db);
|
||||
removeAllinDB = foreign_db.backup_removeAllinDB.bind(foreign_db);
|
||||
_addDB = foreign_db.backup_addDB.bind(foreign_db);
|
||||
_readDB = foreign_db.backup_readDB.bind(foreign_db);
|
||||
} else {
|
||||
err_msg = `WARNING: Invalid Backup DB Instance Id: ${backup_db}.`;
|
||||
showMessage(err_msg);
|
||||
@ -13947,7 +13945,7 @@
|
||||
|
||||
//Check buyer's fiat balance
|
||||
const trader_cash_id = `${params.trader_flo_address}_${params.currency}`;
|
||||
readDB("cash_balances", trader_cash_id).then(function (res) {
|
||||
_readDB("cash_balances", trader_cash_id).then(function (res) {
|
||||
if (typeof res !== "undefined" && typeof res.cash_balance == "number" && !isNaN(res.cash_balance)) {
|
||||
let buyer_cash_balance = parseFloat(res.cash_balance);
|
||||
let buy_price_btc = parseFloat(params.buy_price);
|
||||
@ -13965,7 +13963,7 @@
|
||||
let res_btc;
|
||||
|
||||
// supernode data query
|
||||
readDB('localbitcoinUser', '00-01').then(function (user_data) {
|
||||
_readDB('localbitcoinUser', '00-01').then(function (user_data) {
|
||||
if (typeof user_data == "object" && typeof localbitcoinplusplus.wallets
|
||||
.MY_SUPERNODE_PRIVATE_KEY ==
|
||||
"string" && localbitcoinplusplus.wallets.MY_SUPERNODE_PRIVATE_KEY
|
||||
@ -13985,7 +13983,7 @@
|
||||
params["supernodePubKey"] = user_data.myLocalFLOPublicKey;
|
||||
params["status"] = 1;
|
||||
|
||||
addDB("buyOrders", params);
|
||||
_addDB("buyOrders", params);
|
||||
|
||||
// Send data for further action
|
||||
callback(params);
|
||||
@ -14029,16 +14027,12 @@
|
||||
}
|
||||
|
||||
if (typeof backup_db=="string" && backup_db.length>0) {
|
||||
let _addDB = addDB;
|
||||
let _readDB = readDB;
|
||||
if (typeof localbitcoinplusplus.newBackupDatabase.db[backup_db] == "object") {
|
||||
const foreign_db = localbitcoinplusplus.newBackupDatabase.db[backup_db];
|
||||
addDB = foreign_db.backup_addDB.bind(foreign_db);
|
||||
readDB = foreign_db.backup_readDB.bind(foreign_db);
|
||||
readDBbyIndex = foreign_db.backup_readDBbyIndex.bind(foreign_db);
|
||||
readAllDB = foreign_db.backup_readAllDB.bind(foreign_db);
|
||||
updateinDB = foreign_db.backup_updateinDB.bind(foreign_db);
|
||||
removeinDB = foreign_db.backup_removeinDB.bind(foreign_db);
|
||||
removeByIndex = foreign_db.backup_removeByIndex.bind(foreign_db);
|
||||
removeAllinDB = foreign_db.backup_removeAllinDB.bind(foreign_db);
|
||||
_addDB = foreign_db.backup_addDB.bind(foreign_db);
|
||||
_readDB = foreign_db.backup_readDB.bind(foreign_db);
|
||||
} else {
|
||||
err_msg = `WARNING: Invalid Backup DB Instance Id: ${backup_db}.`;
|
||||
showMessage(err_msg);
|
||||
@ -14052,7 +14046,7 @@
|
||||
|
||||
// Check crypto balance of the seller
|
||||
let seller_btc_id = `${params.trader_flo_address}_${params.product}`;
|
||||
readDB("crypto_balances", seller_btc_id).then(function (res) {
|
||||
_readDB("crypto_balances", seller_btc_id).then(function (res) {
|
||||
if (typeof res !== "undefined" && typeof res.trader_flo_address == "string" && res.trader_flo_address
|
||||
.length > 0 && res.crypto_balance > 0) {
|
||||
let seller_btc_balance = parseFloat(res.crypto_balance);
|
||||
@ -14069,7 +14063,7 @@
|
||||
}
|
||||
|
||||
// supernode data query
|
||||
readDB('localbitcoinUser', '00-01').then(function (user_data) {
|
||||
_readDB('localbitcoinUser', '00-01').then(function (user_data) {
|
||||
if (typeof user_data == "object" && typeof localbitcoinplusplus.wallets
|
||||
.MY_SUPERNODE_PRIVATE_KEY ==
|
||||
"string" && localbitcoinplusplus.wallets.MY_SUPERNODE_PRIVATE_KEY
|
||||
@ -14088,7 +14082,7 @@
|
||||
params["supernodePubKey"] = user_data.myLocalFLOPublicKey;
|
||||
params["status"] = 1;
|
||||
|
||||
addDB("sellOrders", params);
|
||||
_addDB("sellOrders", params);
|
||||
|
||||
callback(params);
|
||||
}
|
||||
@ -14345,16 +14339,10 @@
|
||||
/*Finds the best buy sell id match for a trade*/
|
||||
createTradePipes(trading_currency = "USD", backup_db="") {
|
||||
if (typeof backup_db=="string" && backup_db.length>0) {
|
||||
let _readAllDB = readAllDB;
|
||||
if (typeof localbitcoinplusplus.newBackupDatabase.db[backup_db] == "object") {
|
||||
const foreign_db = localbitcoinplusplus.newBackupDatabase.db[backup_db];
|
||||
addDB = foreign_db.backup_addDB.bind(foreign_db);
|
||||
readDB = foreign_db.backup_readDB.bind(foreign_db);
|
||||
readDBbyIndex = foreign_db.backup_readDBbyIndex.bind(foreign_db);
|
||||
readAllDB = foreign_db.backup_readAllDB.bind(foreign_db);
|
||||
updateinDB = foreign_db.backup_updateinDB.bind(foreign_db);
|
||||
removeinDB = foreign_db.backup_removeinDB.bind(foreign_db);
|
||||
removeByIndex = foreign_db.backup_removeByIndex.bind(foreign_db);
|
||||
removeAllinDB = foreign_db.backup_removeAllinDB.bind(foreign_db);
|
||||
_readAllDB = foreign_db.backup_readAllDB.bind(foreign_db);
|
||||
} else {
|
||||
err_msg = `WARNING: Invalid Backup DB Instance Id: ${backup_db}.`;
|
||||
showMessage(err_msg);
|
||||
@ -14362,11 +14350,11 @@
|
||||
}
|
||||
}
|
||||
try {
|
||||
readAllDB("sellOrders").then(function (sellOrdersList) {
|
||||
_readAllDB("sellOrders").then(function (sellOrdersList) {
|
||||
if (sellOrdersList.length > 0) {
|
||||
sellOrdersList = sellOrdersList.filter(sellOrder => sellOrder.currency ==
|
||||
trading_currency);
|
||||
readAllDB("buyOrders").then(function (buyOrdersList) {
|
||||
_readAllDB("buyOrders").then(function (buyOrdersList) {
|
||||
if (buyOrdersList.length > 0) {
|
||||
buyOrdersList = buyOrdersList.filter(buyOrder => buyOrder.currency ==
|
||||
trading_currency);
|
||||
@ -14425,16 +14413,24 @@
|
||||
},
|
||||
launchTrade(buyPipeObj, sellPipeObj, callback, backup_db="") {
|
||||
if (typeof backup_db=="string" && backup_db.length>0) {
|
||||
let _addDB = addDB;
|
||||
let _readDB = readDB;
|
||||
let _readDBbyIndex = readDBbyIndex;
|
||||
let _readAllDB = readAllDB;
|
||||
let _updateinDB = updateinDB;
|
||||
let _removeinDB = removeinDB;
|
||||
let _removeByIndex = removeByIndex;
|
||||
let _removeAllinDB = removeAllinDB;
|
||||
if (typeof localbitcoinplusplus.newBackupDatabase.db[backup_db] == "object") {
|
||||
const foreign_db = localbitcoinplusplus.newBackupDatabase.db[backup_db];
|
||||
addDB = foreign_db.backup_addDB.bind(foreign_db);
|
||||
readDB = foreign_db.backup_readDB.bind(foreign_db);
|
||||
readDBbyIndex = foreign_db.backup_readDBbyIndex.bind(foreign_db);
|
||||
readAllDB = foreign_db.backup_readAllDB.bind(foreign_db);
|
||||
updateinDB = foreign_db.backup_updateinDB.bind(foreign_db);
|
||||
removeinDB = foreign_db.backup_removeinDB.bind(foreign_db);
|
||||
removeByIndex = foreign_db.backup_removeByIndex.bind(foreign_db);
|
||||
removeAllinDB = foreign_db.backup_removeAllinDB.bind(foreign_db);
|
||||
_addDB = foreign_db.backup_addDB.bind(foreign_db);
|
||||
_readDB = foreign_db.backup_readDB.bind(foreign_db);
|
||||
_readDBbyIndex = foreign_db.backup_readDBbyIndex.bind(foreign_db);
|
||||
_readAllDB = foreign_db.backup_readAllDB.bind(foreign_db);
|
||||
_updateinDB = foreign_db.backup_updateinDB.bind(foreign_db);
|
||||
_removeinDB = foreign_db.backup_removeinDB.bind(foreign_db);
|
||||
_removeByIndex = foreign_db.backup_removeByIndex.bind(foreign_db);
|
||||
_removeAllinDB = foreign_db.backup_removeAllinDB.bind(foreign_db);
|
||||
} else {
|
||||
err_msg = `WARNING: Invalid Backup DB Instance Id: ${backup_db}.`;
|
||||
showMessage(err_msg);
|
||||
@ -14451,7 +14447,7 @@
|
||||
let err_msg;
|
||||
// Check buyer's cash balance
|
||||
const buyer_cash_id = `${buyPipeObj.trader_flo_address}_${buyPipeObj.currency}`;
|
||||
readDB("cash_balances", buyer_cash_id).then(function (buyPipeCashRes) {
|
||||
_readDB("cash_balances", buyer_cash_id).then(function (buyPipeCashRes) {
|
||||
if (typeof buyPipeCashRes == "object" && typeof buyPipeCashRes.cash_balance ==
|
||||
"number") {
|
||||
let buyer_cash_balance = parseFloat(buyPipeCashRes.cash_balance);
|
||||
@ -14471,7 +14467,7 @@
|
||||
|
||||
// Check seller's crypto balance
|
||||
let seller_btc_id = `${sellPipeObj.trader_flo_address}_${sellPipeObj.product}`;
|
||||
readDB("crypto_balances", seller_btc_id).then(function (sellPipeBTCRes) {
|
||||
_readDB("crypto_balances", seller_btc_id).then(function (sellPipeBTCRes) {
|
||||
if (typeof sellPipeBTCRes == "object" && typeof sellPipeBTCRes.crypto_balance ==
|
||||
"number") {
|
||||
let seller_btc_balance = Number(parseFloat(sellPipeBTCRes.crypto_balance)
|
||||
@ -14493,7 +14489,7 @@
|
||||
let buyerBTCResponseObject;
|
||||
let buyer_btc_id =
|
||||
`${buyPipeObj.trader_flo_address}_${buyPipeObj.product}`;
|
||||
readDB("crypto_balances", buyPipeObj.trader_flo_address).then(
|
||||
_readDB("crypto_balances", buyPipeObj.trader_flo_address).then(
|
||||
function (buyPipeBTCRes) {
|
||||
if (typeof buyPipeBTCRes == "object" && typeof buyPipeBTCRes
|
||||
.crypto_balance == "number") {
|
||||
@ -14526,7 +14522,7 @@
|
||||
let sellerCashResponseObject;
|
||||
const seller_cash_id =
|
||||
`${sellPipeObj.trader_flo_address}_${buyPipeObj.currency}`;
|
||||
readDB("cash_balances", seller_cash_id).then(
|
||||
_readDB("cash_balances", seller_cash_id).then(
|
||||
function (sellPipeCashRes) {
|
||||
if (typeof sellPipeCashRes ==
|
||||
"object" && typeof sellPipeCashRes
|
||||
@ -14566,7 +14562,7 @@
|
||||
}
|
||||
|
||||
// supernode data query
|
||||
readDB('localbitcoinUser', '00-01')
|
||||
_readDB('localbitcoinUser', '00-01')
|
||||
.then(
|
||||
function (user_data) {
|
||||
if (typeof user_data ==
|
||||
@ -14578,11 +14574,11 @@
|
||||
.length > 0) {
|
||||
// Delete orders
|
||||
try {
|
||||
removeinDB(
|
||||
_removeinDB(
|
||||
"buyOrders",
|
||||
buyPipeObj
|
||||
.id);
|
||||
removeinDB(
|
||||
_removeinDB(
|
||||
"sellOrders",
|
||||
sellPipeObj
|
||||
.id);
|
||||
@ -14594,25 +14590,25 @@
|
||||
|
||||
// Update balances
|
||||
try {
|
||||
updateinDB(
|
||||
_updateinDB(
|
||||
"cash_balances",
|
||||
buyerCashResponseObject,
|
||||
buyPipeObj
|
||||
.trader_flo_address
|
||||
);
|
||||
updateinDB(
|
||||
_updateinDB(
|
||||
"cash_balances",
|
||||
sellerCashResponseObject,
|
||||
sellPipeObj
|
||||
.trader_flo_address
|
||||
);
|
||||
updateinDB(
|
||||
_updateinDB(
|
||||
"crypto_balances",
|
||||
buyerBTCResponseObject,
|
||||
buyPipeObj
|
||||
.trader_flo_address
|
||||
);
|
||||
updateinDB(
|
||||
_updateinDB(
|
||||
"crypto_balances",
|
||||
sellerBTCResponseObject,
|
||||
sellPipeObj
|
||||
@ -14729,16 +14725,12 @@
|
||||
getAssetTradeAndWithdrawLimit(flo_id, crypto, fiat, backup_db="") {
|
||||
|
||||
if (typeof backup_db=="string" && backup_db.length>0) {
|
||||
let _readDB = readDB;
|
||||
let _readDBbyIndex = readDBbyIndex;
|
||||
if (typeof localbitcoinplusplus.newBackupDatabase.db[backup_db] == "object") {
|
||||
const foreign_db = localbitcoinplusplus.newBackupDatabase.db[backup_db];
|
||||
addDB = foreign_db.backup_addDB.bind(foreign_db);
|
||||
readDB = foreign_db.backup_readDB.bind(foreign_db);
|
||||
readDBbyIndex = foreign_db.backup_readDBbyIndex.bind(foreign_db);
|
||||
readAllDB = foreign_db.backup_readAllDB.bind(foreign_db);
|
||||
updateinDB = foreign_db.backup_updateinDB.bind(foreign_db);
|
||||
removeinDB = foreign_db.backup_removeinDB.bind(foreign_db);
|
||||
removeByIndex = foreign_db.backup_removeByIndex.bind(foreign_db);
|
||||
removeAllinDB = foreign_db.backup_removeAllinDB.bind(foreign_db);
|
||||
_readDB = foreign_db.backup_readDB.bind(foreign_db);
|
||||
_readDBbyIndex = foreign_db.backup_readDBbyIndex.bind(foreign_db);
|
||||
} else {
|
||||
err_msg = `WARNING: Invalid Backup DB Instance Id: ${backup_db}.`;
|
||||
showMessage(err_msg);
|
||||
@ -14751,15 +14743,15 @@
|
||||
let user_crypto_id = `${flo_id}_${crypto}`;
|
||||
let user_fiat_id = `${flo_id}_${fiat}`;
|
||||
|
||||
const user_balance_crypto_promise = readDB("crypto_balances", user_crypto_id);
|
||||
const user_balance_fiat_promise = readDB("cash_balances", user_fiat_id);
|
||||
const user_sell_orders_promise = readDBbyIndex("sellOrders", "trader_flo_address", flo_id)
|
||||
const user_balance_crypto_promise = _readDB("crypto_balances", user_crypto_id);
|
||||
const user_balance_fiat_promise = _readDB("cash_balances", user_fiat_id);
|
||||
const user_sell_orders_promise = _readDBbyIndex("sellOrders", "trader_flo_address", flo_id)
|
||||
.then((res) => res.filter(resp => resp.currency == fiat && resp.product == crypto));
|
||||
const user_buy_orders_promise = readDBbyIndex("buyOrders", "trader_flo_address", flo_id)
|
||||
const user_buy_orders_promise = _readDBbyIndex("buyOrders", "trader_flo_address", flo_id)
|
||||
.then((res) => res.filter(resp => resp.currency == fiat && resp.product == crypto));
|
||||
const user_fiat_withdraw_request_promise = readDBbyIndex("withdraw_cash", "trader_flo_address",
|
||||
const user_fiat_withdraw_request_promise = _readDBbyIndex("withdraw_cash", "trader_flo_address",
|
||||
flo_id);
|
||||
const user_crypto_withdraw_request_promise = readDBbyIndex("withdraw_btc", "trader_flo_address",
|
||||
const user_crypto_withdraw_request_promise = _readDBbyIndex("withdraw_btc", "trader_flo_address",
|
||||
flo_id);
|
||||
|
||||
return Promise.all([user_balance_crypto_promise, user_balance_fiat_promise,
|
||||
@ -15160,7 +15152,7 @@
|
||||
wsUri = await localbitcoinplusplus.kademlia.getSupernodeSeed(idbData.myLocalFLOAddress);
|
||||
|
||||
if (localbitcoinplusplus.master_configurations.supernodesPubKeys.includes(idbData.myLocalFLOPublicKey)) {
|
||||
const getClosestSuList = await readAllDB('closestSupernodesTable');
|
||||
const getClosestSuList = await readAllDB('myClosestSupernodes');
|
||||
if (wsUri[0].trader_flo_address !== idbData.myLocalFLOAddress || getClosestSuList.length < 3) {
|
||||
showMessage(`INFO: Invalid connection. Refreshing the closest supernode list in DB.`);
|
||||
wsUri = await localbitcoinplusplus.kademlia.updateClosestSupernodeSeeds(idbData.myLocalFLOAddress);
|
||||
@ -17236,15 +17228,18 @@
|
||||
return;
|
||||
}
|
||||
|
||||
let ifAllPrevSuAreDead = await localbitcoinplusplus.actions
|
||||
if (localbitcoinplusplus.master_configurations.supernodesPubKeys
|
||||
.includes(localbitcoinplusplus.wallets.my_local_flo_public_key)) {
|
||||
let ifAllPrevSuAreDead = await localbitcoinplusplus.actions
|
||||
.checkIfAllPreviousSupernodesAreDeadForAUserNode(res_obj.params[0].trader_flo_address);
|
||||
|
||||
console.log("ifAllPrevSuAreDead: ", ifAllPrevSuAreDead);
|
||||
console.log("ifAllPrevSuAreDead: ", ifAllPrevSuAreDead);
|
||||
|
||||
if (ifAllPrevSuAreDead !== true) {
|
||||
console.log(res_obj);
|
||||
showMessage(`INFO: "checkIfAllPreviousSupernodesAreDeadForAUserNode" check failed.`)
|
||||
return;
|
||||
if (ifAllPrevSuAreDead !== true) {
|
||||
console.log(res_obj);
|
||||
showMessage(`INFO: "checkIfAllPreviousSupernodesAreDeadForAUserNode" check failed.`)
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof res_obj.method !== "undefined") {
|
||||
@ -18049,22 +18044,9 @@
|
||||
doSend(JSON.stringify(response_from_sever)); // send response to client
|
||||
break;
|
||||
|
||||
case "updateUserCryptoBalanceRequest":
|
||||
case "updateUserCryptoBalanceRequest":
|
||||
let updateUserCryptoBalanceResponseObject = res_obj.params[0];
|
||||
|
||||
if(typeof res_obj.params[0].trader_flo_address !="string") return;
|
||||
localbitcoinplusplus.kademlia.determineClosestSupernode(res_obj.params[0].trader_flo_address)
|
||||
.then(my_closest_su_list=>{
|
||||
const primarySupernodeOfThisUser = my_closest_su_list[0].data.id;
|
||||
const backup_server_db_instance = localbitcoinplusplus.newBackupDatabase.db[primarySupernodeOfThisUser];
|
||||
|
||||
if(typeof backup_server_db_instance !== "object") {
|
||||
let backup_db_error_msg = `WARNING: Unknown DB instance. DB Backup failed.`;
|
||||
showMessage(backup_db_error_msg);
|
||||
throw new Error(backup_db_error_msg);
|
||||
};
|
||||
|
||||
let SuPubKey = backup_server_db_instance.backup_readDB('userPublicData', updateUserCryptoBalanceResponseObject.trader_flo_address)
|
||||
let SuPubKey = readDB('userPublicData', updateUserCryptoBalanceResponseObject.trader_flo_address)
|
||||
.then(user_data => {
|
||||
if (typeof user_data !== "object" || user_data.supernode_flo_public_key.length <
|
||||
1)
|
||||
@ -18076,7 +18058,7 @@
|
||||
user_data.supernode_flo_public_key
|
||||
);
|
||||
if (isBalanceLegit) {
|
||||
backup_server_db_instance.backup_updateinDB("crypto_balances", updateUserCryptoBalanceResponseObject.updatedBTCBalanceObject,
|
||||
updateinDB("crypto_balances", updateUserCryptoBalanceResponseObject.updatedBTCBalanceObject,
|
||||
user_data.trader_flo_address);
|
||||
if (localbitcoinplusplus.wallets.my_local_flo_address ==
|
||||
updateUserCryptoBalanceResponseObject.trader_flo_address) {
|
||||
@ -18088,8 +18070,6 @@
|
||||
showMessage(`WARNING: Failed to update balance in your DB. Please refresh.`);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
break;
|
||||
|
||||
case "addNewKbucketNode":
|
||||
@ -18191,25 +18171,11 @@
|
||||
let flo_addr_for_pubkey = bitjs.FLO_TEST.pubkey2address(req_params.requesters_pub_key);
|
||||
if(typeof flo_addr_for_pubkey !== "string") return;
|
||||
if(flo_addr_for_pubkey !== res_obj.globalParams.senderFloId) return;
|
||||
|
||||
if(typeof res_obj.params[0].trader_flo_address !="string") return;
|
||||
localbitcoinplusplus.kademlia.determineClosestSupernode(res_obj.params[0].trader_flo_address)
|
||||
.then(my_closest_su_list=>{
|
||||
const primarySupernodeOfThisUser = my_closest_su_list[0].data.id;
|
||||
const backup_server_db_instance = localbitcoinplusplus.newBackupDatabase.db[primarySupernodeOfThisUser];
|
||||
|
||||
if(typeof backup_server_db_instance !== "object") {
|
||||
let backup_db_error_msg = `WARNING: Unknown DB instance. DB Backup failed.`;
|
||||
showMessage(backup_db_error_msg);
|
||||
throw new Error(backup_db_error_msg);
|
||||
};
|
||||
|
||||
backup_server_db_instance.backup_updateinDB('ipTable', {
|
||||
'flo_public_key': req_params.requesters_pub_key,
|
||||
'temporary_ip': incoming_msg_local_ip
|
||||
}).then((ipRes)=>{
|
||||
reactor.dispatchEvent('fireNodeWelcomeBackEvent', ipRes);
|
||||
});
|
||||
updateinDB('ipTable', {
|
||||
'flo_public_key': req_params.requesters_pub_key,
|
||||
'temporary_ip': incoming_msg_local_ip
|
||||
}).then((ipRes)=>{
|
||||
reactor.dispatchEvent('fireNodeWelcomeBackEvent', ipRes);
|
||||
});
|
||||
}
|
||||
break;
|
||||
@ -19257,11 +19223,22 @@
|
||||
unique: false
|
||||
});
|
||||
}
|
||||
if (!db.objectStoreNames.contains('ipTable')) {
|
||||
var objectStore = db.createObjectStore("ipTable", {
|
||||
if (!this.db.objectStoreNames.contains('ipTable')) {
|
||||
var objectStore = this.db.createObjectStore("ipTable", {
|
||||
keyPath: 'flo_public_key'
|
||||
});
|
||||
}
|
||||
if (!this.db.objectStoreNames.contains('myClosestSupernodes')) {
|
||||
var objectStore = this.db.createObjectStore("myClosestSupernodes", {
|
||||
keyPath: 'id'
|
||||
});
|
||||
objectStore.createIndex('trader_flo_address', 'trader_flo_address', {
|
||||
unique: true
|
||||
});
|
||||
objectStore.createIndex('ip', 'ip', {
|
||||
unique: false
|
||||
});
|
||||
}
|
||||
|
||||
}.bind(this)
|
||||
|
||||
@ -20163,23 +20140,21 @@
|
||||
if (!localbitcoinplusplus.master_configurations.tradableAsset1
|
||||
.includes(trader_deposits.product)) return false;
|
||||
|
||||
if (typeof backup_db=="string" && backup_db.length>0) {
|
||||
if (typeof localbitcoinplusplus.newBackupDatabase.db[backup_db] == "object") {
|
||||
const foreign_db = localbitcoinplusplus.newBackupDatabase.db[backup_db];
|
||||
addDB = foreign_db.backup_addDB.bind(foreign_db);
|
||||
readDB = foreign_db.backup_readDB.bind(foreign_db);
|
||||
readDBbyIndex = foreign_db.backup_readDBbyIndex.bind(foreign_db);
|
||||
readAllDB = foreign_db.backup_readAllDB.bind(foreign_db);
|
||||
updateinDB = foreign_db.backup_updateinDB.bind(foreign_db);
|
||||
removeinDB = foreign_db.backup_removeinDB.bind(foreign_db);
|
||||
removeByIndex = foreign_db.backup_removeByIndex.bind(foreign_db);
|
||||
removeAllinDB = foreign_db.backup_removeAllinDB.bind(foreign_db);
|
||||
} else {
|
||||
err_msg = `WARNING: Invalid Backup DB Instance Id: ${backup_db}.`;
|
||||
showMessage(err_msg);
|
||||
throw new Error(err_msg);
|
||||
if (typeof backup_db=="string" && backup_db.length>0) {
|
||||
let _readDB = readDB;
|
||||
let _readDBbyIndex = readDBbyIndex;
|
||||
let _updateinDB = updateinDB;
|
||||
if (typeof localbitcoinplusplus.newBackupDatabase.db[backup_db] == "object") {
|
||||
const foreign_db = localbitcoinplusplus.newBackupDatabase.db[backup_db];
|
||||
_readDB = foreign_db.backup_readDB.bind(foreign_db);
|
||||
_readDBbyIndex = foreign_db.backup_readDBbyIndex.bind(foreign_db);
|
||||
_updateinDB = foreign_db.backup_updateinDB.bind(foreign_db);
|
||||
} else {
|
||||
err_msg = `WARNING: Invalid Backup DB Instance Id: ${backup_db}.`;
|
||||
showMessage(err_msg);
|
||||
throw new Error(err_msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let explorer;
|
||||
let decimal = 100000000;
|
||||
@ -20223,14 +20198,14 @@
|
||||
//Deposit successful. Update user balance and status to 2. Its Private key can be
|
||||
// now given to a random trader
|
||||
trader_deposits.status = 2;
|
||||
updateinDB("deposit", trader_deposits, trader_deposits.trader_flo_address);
|
||||
_updateinDB("deposit", trader_deposits, trader_deposits.trader_flo_address);
|
||||
|
||||
readDBbyIndex('system_btc_reserves_private_keys', 'btc_address', trader_deposits.btc_address)
|
||||
_readDBbyIndex('system_btc_reserves_private_keys', 'btc_address', trader_deposits.btc_address)
|
||||
.then(function (reserve_res) {
|
||||
if (typeof reserve_res == "object") {
|
||||
reserve_res.map(reserves => {
|
||||
reserves.balance = balance;
|
||||
updateinDB('system_btc_reserves_private_keys', reserves,
|
||||
_updateinDB('system_btc_reserves_private_keys', reserves,
|
||||
reserves.id);
|
||||
});
|
||||
}
|
||||
@ -20244,14 +20219,14 @@
|
||||
crypto_balance: balance,
|
||||
crypto_currency: trader_deposits.product
|
||||
}
|
||||
readDB('crypto_balances', trader_depositor_cash_id).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 ==
|
||||
"object" && typeof res_btc_balances.crypto_balance == "number") {
|
||||
updatedCryptobalances.crypto_balance += parseFloat(res_btc_balances
|
||||
.crypto_balance);
|
||||
}
|
||||
// Update crypto balance of user in crypto_balances
|
||||
updateinDB("crypto_balances", updatedCryptobalances, trader_deposits.btc_address)
|
||||
_updateinDB("crypto_balances", updatedCryptobalances, trader_deposits.btc_address)
|
||||
.then(updatedBTCBalanceObject => {
|
||||
|
||||
const RM_WALLET = new localbitcoinplusplus.wallets;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user