fixed live status error and can_server_FLO_ADDR property error

This commit is contained in:
Abhishek Sinha 2019-07-07 20:38:58 +05:30
parent 804abe0a6f
commit 42fb7a6830

View File

@ -12714,11 +12714,10 @@
su_db_data.trader_flo_address = params.trader_flo_address;
su_db_data.receiver_flo_address = params.trader_flo_address;
RM_RPC
.send_rpc
.call(this, "server_sync_response",
su_db_data)
.then(server_sync_response=>
doSend(server_sync_response));
.send_rpc
.call(this, "server_sync_response", su_db_data)
.then(server_sync_response=>
doSend(server_sync_response));
}
});
}
@ -14442,38 +14441,23 @@
fiat_to_crypto_exchange_rate(crypto_code="", fiat="") {
return new Promise((resolve, reject)=>{
if (crypto_code=="BTC") {
helper_functions.ajaxGet('https://api.coinmarketcap.com/v1/ticker/?limit=5')
.then(async res=>{
if(typeof res== 'object') {
let btc_obj = res.filter(f=>f.id=='bitcoin');
console.log(btc_obj[0].price_usd);
let new_price = btc_obj[0].price_usd;
if (typeof btc_obj[0].price_usd=="number") {
if (fiat=="INR") {
let usd_to_fiat_price = await this.usd_to_fiat_exchange_rate(fiat);
new_price = Number(new_price*usd_to_fiat_price);
}
resolve(new_price);
return;
}
}
throw new Error(`No data`);
}).catch(e=>{
helper_functions.ajaxGet(`https://api.coindesk.com/v1/bpi/currentprice.json`)
.then(async res=>{
if (typeof res=="object" && typeof res.bpi.USD.rate_float=="number") {
let new_price = res.bpi.USD.rate_float;
if (fiat=="INR") {
let usd_to_fiat_price = await this.usd_to_fiat_exchange_rate(fiat);
new_price = Number(new_price*usd_to_fiat_price);
}
resolve(new_price);
return;
} else {
reject(false);
helper_functions.ajaxGet(`https://api.coindesk.com/v1/bpi/currentprice.json`)
.then(async res=>{
if (typeof res=="object" && typeof res.bpi.USD.rate_float=="number") {
let new_price = res.bpi.USD.rate_float;
if (fiat=="INR") {
let usd_to_fiat_price = await this.usd_to_fiat_exchange_rate(fiat);
new_price = Number(new_price*usd_to_fiat_price);
}
});
resolve(new_price);
return;
} else {
reject(false);
}
}).catch(e=>{
console.error(e);
reject(false);
});
} else if(crypto_code=="FLO") {
helper_functions.ajaxGet('https://min-api.cryptocompare.com/data/histoday?fsym=FLO&tsym=USD&limit=1&aggregate=3&e=CCCAGG')
@ -15899,9 +15883,8 @@
return;
} else if(typeof res_obj.globalParams.primarySupernode=="string"
&& res_obj.globalParams.primarySupernode !== localbitcoinplusplus.MY_SUPERNODE_FLO_ADDRESS) {
if (typeof res_obj.globalParams.receiverFloId !== 'string' ||
res_obj.globalParams.receiverFloId == localbitcoinplusplus.MY_SUPERNODE_FLO_ADDRESS) {
if (typeof res_obj.globalParams.receiverFloId !== 'string'
|| res_obj.globalParams.receiverFloId == localbitcoinplusplus.MY_SUPERNODE_FLO_ADDRESS) {
// ** Changed it for "retrieve_shamirs_secret_btc_pvtkey" when backup su is requeter
//res_obj.globalParams.receiverFloId !== localbitcoinplusplus.MY_SUPERNODE_FLO_ADDRESS) {
processBackupUserOnMesssageRequest(response);
@ -16987,6 +16970,13 @@
let _removeAllinDB = removeAllinDB;
let _updateinDB = updateinDB;
let backup_db;
if(typeof localbitcoinplusplus.wallets.my_local_flo_address !=="string"
|| localbitcoinplusplus.wallets.my_local_flo_address.length<1) {
console.warn(`WARNING: Local FLO Address is not set.`);
return;
}
if (su_db_data.trader_flo_address !==localbitcoinplusplus.wallets.my_local_flo_address) {
backup_db = su_db_data.trader_flo_address;
}
@ -17063,7 +17053,8 @@
) {
(async function() {
let su_db_data = res_obj.params[0];
const MCS = await localbitcoinplusplus.kademlia.determineClosestSupernode(su_db_data.trader_flo_address, 10);
const MCS = await localbitcoinplusplus.kademlia
.determineClosestSupernode(localbitcoinplusplus.wallets.my_local_flo_address, 10);
// If user is already connected to primary return back
if (localbitcoinplusplus.MY_SUPERNODE_FLO_ADDRESS == MCS[0].data.id) return;
@ -17205,9 +17196,9 @@
console.log("ifAllPrevSuAreDead: ", ifAllPrevSuAreDead);
if (ifAllPrevSuAreDead !== true || res_obj.method=='sync_backup_supernode_from_backup_supernode_response') {
console.log(res_obj);
showMessage(`INFO: "checkIfAllPreviousSupernodesAreDeadForAUserNode" check failed.`);
let allowed_methods = ['sync_backup_supernode_from_backup_supernode_response', 'yup_i_am_awake'];
if (ifAllPrevSuAreDead !== true || allowed_methods.includes(res_obj.method)) {
handle_backup_server_messages(response);
return;
}
@ -17250,7 +17241,7 @@
try {
if (received_resp.trader_flo_address.length > 0 && received_resp.server_msg.length > 0) {
readDB("localbitcoinUser", "00-01").then(function (res) {
readDB("localbitcoinUser", "00-01").then(async function (res) {
if (typeof res == "object" && res.myLocalFLOAddress.length > 0) {
if (res.myLocalFLOAddress === received_resp.trader_flo_address) {
showMessage(received_resp.server_msg);
@ -18543,7 +18534,8 @@
) {
(async function() {
let su_db_data = res_obj.params[0];
const MCS = await localbitcoinplusplus.kademlia.determineClosestSupernode(su_db_data.trader_flo_address, 10);
const MCS = await localbitcoinplusplus.kademlia
.determineClosestSupernode(localbitcoinplusplus.wallets.my_local_flo_address, 10);
// If user is already connected to primary return back
if (localbitcoinplusplus.MY_SUPERNODE_FLO_ADDRESS == MCS[0].data.id) return;
@ -19439,6 +19431,13 @@
let _removeAllinDB = removeAllinDB;
let _updateinDB = updateinDB;
let backup_db;
if(typeof localbitcoinplusplus.wallets.my_local_flo_address !=="string"
|| localbitcoinplusplus.wallets.my_local_flo_address.length<1) {
console.warn(`WARNING: Local FLO Address is not set.`);
return;
}
if (su_db_data.trader_flo_address !==localbitcoinplusplus.wallets.my_local_flo_address) {
backup_db = su_db_data.trader_flo_address;
}
@ -21717,6 +21716,9 @@
const switchMyWS = new backupSupernodesWebSocketObject();
switchMyWS.updateSupernodeAvailabilityStatus(getFLOId, true);
if (getFLOId !== localbitcoinplusplus.wallets.my_local_flo_address) {
localbitcoinplusplus.services[`can_serve_${getFLOId}`] = false;
}
} else {
msg = `INFO: User node ${getFLOId} joined.`;
@ -21914,6 +21916,10 @@
if (params.receiver_flo_address !== localbitcoinplusplus.wallets.my_local_flo_address) return;
const switchMyWS = new backupSupernodesWebSocketObject();
switchMyWS.updateSupernodeAvailabilityStatus(params.trader_flo_address, true);
if (params.trader_flo_address !== localbitcoinplusplus.wallets.my_local_flo_address) {
localbitcoinplusplus.services[`can_serve_${params.trader_flo_address}`] = false;
}
} catch(e) {
console.warn(e);
}