fixed db functions for primary and backup db
This commit is contained in:
parent
701db7da42
commit
cff3ef5b18
@ -10142,8 +10142,8 @@
|
||||
|
||||
get_sharable_db_data: async function (dbTableNamesArray, backup_db="") {
|
||||
let arr = {};
|
||||
let _readAllDB = readAllDB;
|
||||
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);
|
||||
@ -13907,6 +13907,8 @@
|
||||
},
|
||||
trade_buy(params, callback, backup_db="") {
|
||||
let err_msg;
|
||||
let _addDB = addDB;
|
||||
let _readDB = readDB;
|
||||
for (var key in params) {
|
||||
if (params.hasOwnProperty(key)) {
|
||||
if (typeof key == undefined || key.trim() == "" || key == null) {
|
||||
@ -13926,8 +13928,6 @@
|
||||
}
|
||||
|
||||
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);
|
||||
@ -14008,6 +14008,8 @@
|
||||
},
|
||||
trade_sell(params, callback, backup_db="") {
|
||||
let err_msg;
|
||||
let _addDB = addDB;
|
||||
let _readDB = readDB;
|
||||
for (var key in params) {
|
||||
if (params.hasOwnProperty(key)) {
|
||||
if (typeof key == "undefined" || key.trim() == "" || key == null) {
|
||||
@ -14027,8 +14029,6 @@
|
||||
}
|
||||
|
||||
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);
|
||||
@ -14338,8 +14338,8 @@
|
||||
},
|
||||
/*Finds the best buy sell id match for a trade*/
|
||||
createTradePipes(trading_currency = "USD", backup_db="") {
|
||||
let _readAllDB = readAllDB;
|
||||
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);
|
||||
@ -14412,15 +14412,15 @@
|
||||
}
|
||||
},
|
||||
launchTrade(buyPipeObj, sellPipeObj, callback, backup_db="") {
|
||||
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 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);
|
||||
@ -14673,20 +14673,23 @@
|
||||
.wallets.MY_SUPERNODE_PRIVATE_KEY
|
||||
);
|
||||
|
||||
let
|
||||
response_for_client = {
|
||||
"trade_infos": trade_infos,
|
||||
"buyer_cash_data": buyerCashResponseObject,
|
||||
"seller_cash_data": sellerCashResponseObject,
|
||||
"buyer_btc_data": buyerBTCResponseObject,
|
||||
"seller_btc_data": sellerBTCResponseObject,
|
||||
"data_hash": hashed_data,
|
||||
"supernode_sign": signed_data,
|
||||
"supernodePubKey": user_data.myLocalFLOPublicKey,
|
||||
"trader_flo_address": buyPipeObj.trader_flo_address,
|
||||
}
|
||||
callback(response_for_client);
|
||||
return true;
|
||||
localbitcoinplusplus.kademlia.determineClosestSupernode(buyPipeObj.trader_flo_address)
|
||||
.then(getPrimarySuObj=>{
|
||||
let response_for_client = {
|
||||
"trade_infos": trade_infos,
|
||||
"buyer_cash_data": buyerCashResponseObject,
|
||||
"seller_cash_data": sellerCashResponseObject,
|
||||
"buyer_btc_data": buyerBTCResponseObject,
|
||||
"seller_btc_data": sellerBTCResponseObject,
|
||||
"data_hash": hashed_data,
|
||||
"supernode_sign": signed_data,
|
||||
"supernodePubKey": user_data.myLocalFLOPublicKey,
|
||||
"trader_flo_address": getPrimarySuObj[0].data.id,
|
||||
}
|
||||
callback(response_for_client);
|
||||
return true;
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
});
|
||||
@ -14723,10 +14726,9 @@
|
||||
|
||||
},
|
||||
getAssetTradeAndWithdrawLimit(flo_id, crypto, fiat, backup_db="") {
|
||||
|
||||
let _readDB = readDB;
|
||||
let _readDBbyIndex = readDBbyIndex;
|
||||
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];
|
||||
_readDB = foreign_db.backup_readDB.bind(foreign_db);
|
||||
@ -17478,8 +17480,6 @@
|
||||
case "trade_balance_updates":
|
||||
if (typeof res_obj.params == "object" && typeof res_obj.params[0] == "object") {
|
||||
const trade_balance_res = res_obj.params[0];
|
||||
// Only the relevent user node should get response
|
||||
if(res_obj.params[0].trader_flo_address !== localbitcoinplusplus.wallets.my_local_flo_address) return;
|
||||
// Verify data
|
||||
let trade_info_str = JSON.stringify(trade_balance_res.trade_infos);
|
||||
let buyer_cash_data_str = JSON.stringify(trade_balance_res.buyer_cash_data);
|
||||
@ -17491,7 +17491,7 @@
|
||||
`${trade_info_str}${buyer_cash_data_str}${seller_cash_data_str}${buyer_btc_data_str}${seller_btc_data_str}`;
|
||||
let hashed_data = Crypto.SHA256(res_str);
|
||||
|
||||
RM_RPC.filter_legit_requests(trade_balance_res.trade_infos.buyer_flo_id,
|
||||
RM_RPC.filter_legit_backup_requests(trade_balance_res.trade_infos.buyer_flo_id,
|
||||
function (is_valid_request) {
|
||||
if (is_valid_request !== true) return false;
|
||||
|
||||
@ -18138,30 +18138,21 @@
|
||||
break;
|
||||
|
||||
case "link_My_Local_IP_To_My_Flo_Id":
|
||||
if (typeof res_obj.params == "object" && typeof res_obj.params[0] == "object") {
|
||||
const req_params = res_obj.params[0];
|
||||
if(typeof req_params.requesters_pub_key !== "string") return;
|
||||
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;
|
||||
|
||||
const backup_server_db_instance = localbitcoinplusplus.newBackupDatabase.db[res_obj.globalParams.senderFloId];
|
||||
|
||||
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);
|
||||
}).finally(()=>{
|
||||
linkBackOthersLocalIPToTheirFloId();
|
||||
});
|
||||
}
|
||||
if (typeof res_obj.params == "object" && typeof res_obj.params[0] == "object") {
|
||||
const req_params = res_obj.params[0];
|
||||
if(typeof req_params.requesters_pub_key !== "string") return;
|
||||
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;
|
||||
updateinDB('ipTable', {
|
||||
'flo_public_key': req_params.requesters_pub_key,
|
||||
'temporary_ip': incoming_msg_local_ip
|
||||
}).then((ipRes)=>{
|
||||
reactor.dispatchEvent('fireNodeWelcomeBackEvent', ipRes);
|
||||
}).finally(()=>{
|
||||
linkBackOthersLocalIPToTheirFloId();
|
||||
});
|
||||
}
|
||||
break;
|
||||
|
||||
case "link_Others_Local_IP_To_Their_Flo_Id":
|
||||
@ -20139,11 +20130,10 @@
|
||||
) return false;
|
||||
if (!localbitcoinplusplus.master_configurations.tradableAsset1
|
||||
.includes(trader_deposits.product)) return false;
|
||||
|
||||
let _readDB = readDB;
|
||||
let _readDBbyIndex = readDBbyIndex;
|
||||
let _updateinDB = updateinDB;
|
||||
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);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user