fixed btc shares data entry into backup supernodes
This commit is contained in:
parent
1475d96ebe
commit
2fb10a8e3f
@ -11118,6 +11118,14 @@
|
|||||||
request.globalParams.receiverFloId = params[0].receiver_flo_address;
|
request.globalParams.receiverFloId = params[0].receiver_flo_address;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/********************************************************************************/
|
||||||
|
|
||||||
|
// MUST REVIEW.
|
||||||
|
// THIS LOGIC IS WRONG WHEN BACKUP SUPERNODE IS ACTING SUPERNODE
|
||||||
|
// BECAUSE IT WILL SHOW BACKUP SU IN request.globalParams.primarySupernode BELOW
|
||||||
|
|
||||||
|
/********************************************************************************/
|
||||||
|
|
||||||
if (typeof params[0].trader_flo_address !=="string") {
|
if (typeof params[0].trader_flo_address !=="string") {
|
||||||
readDB('localbitcoinUser', '00-01').then(result=>{
|
readDB('localbitcoinUser', '00-01').then(result=>{
|
||||||
if (typeof result !=="object" || typeof result.myLocalFLOAddress !=="string") {
|
if (typeof result !=="object" || typeof result.myLocalFLOAddress !=="string") {
|
||||||
@ -11514,7 +11522,8 @@
|
|||||||
.encrypt(
|
.encrypt(
|
||||||
chunks,
|
chunks,
|
||||||
this_btc_tx_key
|
this_btc_tx_key
|
||||||
)
|
),
|
||||||
|
"trader_flo_address": params.trader_flo_address
|
||||||
};
|
};
|
||||||
return chunk_array;
|
return chunk_array;
|
||||||
});
|
});
|
||||||
@ -11563,15 +11572,11 @@
|
|||||||
this_btc_tx_key;
|
this_btc_tx_key;
|
||||||
const
|
const
|
||||||
system_btc_reserves_private_keys_object = {
|
system_btc_reserves_private_keys_object = {
|
||||||
id: helper_functions
|
id: helper_functions.unique_id(),
|
||||||
.unique_id(),
|
product: params.product,
|
||||||
product: params
|
btc_address: params.btc_address,
|
||||||
.product,
|
|
||||||
btc_address: params
|
|
||||||
.btc_address,
|
|
||||||
balance: null,
|
balance: null,
|
||||||
trader_flo_address: params
|
trader_flo_address: params.trader_flo_address,
|
||||||
.trader_flo_address,
|
|
||||||
btc_private_key_shamirs_id: btc_private_key_shamirs_id,
|
btc_private_key_shamirs_id: btc_private_key_shamirs_id,
|
||||||
supernode_transaction_key: supernode_transaction_key
|
supernode_transaction_key: supernode_transaction_key
|
||||||
}
|
}
|
||||||
@ -11840,7 +11845,7 @@
|
|||||||
let eqBTC = RM_TRADE.calculateCryptoEquivalentOfCash(
|
let eqBTC = RM_TRADE.calculateCryptoEquivalentOfCash(
|
||||||
withdrawing_btc_amount_in_cash,
|
withdrawing_btc_amount_in_cash,
|
||||||
params.currency, params.product);
|
params.currency, params.product);
|
||||||
eqBTC = parseFloat(eqBTC).toFixed(8);
|
eqBTC = Number(parseFloat(eqBTC).toFixed(8));
|
||||||
let withdrawer_new_btc_balance =
|
let withdrawer_new_btc_balance =
|
||||||
withdrawer_btc_balance - eqBTC;
|
withdrawer_btc_balance - eqBTC;
|
||||||
if (withdrawer_new_btc_balance > 0 &&
|
if (withdrawer_new_btc_balance > 0 &&
|
||||||
@ -12138,7 +12143,7 @@
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case "retrieve_shamirs_secret_btc_pvtkey":
|
case "retrieve_shamirs_secret_btc_pvtkey":
|
||||||
RM_RPC.filter_legit_requests(null, function (is_valid_request) {
|
RM_RPC.filter_legit_requests(params.trader_flo_address, function (is_valid_request) {
|
||||||
if (is_valid_request !== true) return false;
|
if (is_valid_request !== true) return false;
|
||||||
|
|
||||||
if (typeof params.btc_private_key_array !== "string" || typeof params.retrieve_pvtkey_req_id !==
|
if (typeof params.btc_private_key_array !== "string" || typeof params.retrieve_pvtkey_req_id !==
|
||||||
@ -12231,12 +12236,7 @@
|
|||||||
res_bal => {
|
res_bal => {
|
||||||
btc_eq_receiving_amount
|
btc_eq_receiving_amount
|
||||||
=
|
=
|
||||||
parseFloat(
|
Number(parseFloat(btc_eq_receiving_amount).toFixed(8));
|
||||||
btc_eq_receiving_amount
|
|
||||||
)
|
|
||||||
.toFixed(
|
|
||||||
8
|
|
||||||
);
|
|
||||||
res_bal
|
res_bal
|
||||||
.crypto_balance -=
|
.crypto_balance -=
|
||||||
EqCryptoWd;
|
EqCryptoWd;
|
||||||
@ -12771,7 +12771,8 @@
|
|||||||
.encrypt(
|
.encrypt(
|
||||||
chunks,
|
chunks,
|
||||||
this_btc_tx_key
|
this_btc_tx_key
|
||||||
)
|
),
|
||||||
|
"trader_flo_address": params.trader_flo_address
|
||||||
};
|
};
|
||||||
return chunk_array;
|
return chunk_array;
|
||||||
});
|
});
|
||||||
@ -13099,7 +13100,7 @@
|
|||||||
let eqBTC = RM_TRADE.calculateCryptoEquivalentOfCash(
|
let eqBTC = RM_TRADE.calculateCryptoEquivalentOfCash(
|
||||||
withdrawing_btc_amount_in_cash,
|
withdrawing_btc_amount_in_cash,
|
||||||
params.currency, params.product);
|
params.currency, params.product);
|
||||||
eqBTC = parseFloat(eqBTC).toFixed(8);
|
eqBTC = Number(parseFloat(eqBTC).toFixed(8));
|
||||||
let withdrawer_new_btc_balance =
|
let withdrawer_new_btc_balance =
|
||||||
withdrawer_btc_balance - eqBTC;
|
withdrawer_btc_balance - eqBTC;
|
||||||
if (withdrawer_new_btc_balance > 0 &&
|
if (withdrawer_new_btc_balance > 0 &&
|
||||||
@ -13397,7 +13398,7 @@
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case "retrieve_shamirs_secret_btc_pvtkey":
|
case "retrieve_shamirs_secret_btc_pvtkey":
|
||||||
RM_RPC.filter_legit_backup_requests(null, function (is_valid_request) {
|
RM_RPC.filter_legit_backup_requests(params.trader_flo_address, function (is_valid_request) {
|
||||||
if (is_valid_request !== true) return false;
|
if (is_valid_request !== true) return false;
|
||||||
|
|
||||||
if (typeof params.btc_private_key_array !== "string" || typeof params.retrieve_pvtkey_req_id !==
|
if (typeof params.btc_private_key_array !== "string" || typeof params.retrieve_pvtkey_req_id !==
|
||||||
@ -13490,12 +13491,12 @@
|
|||||||
res_bal => {
|
res_bal => {
|
||||||
btc_eq_receiving_amount
|
btc_eq_receiving_amount
|
||||||
=
|
=
|
||||||
parseFloat(
|
Number(parseFloat(
|
||||||
btc_eq_receiving_amount
|
btc_eq_receiving_amount
|
||||||
)
|
)
|
||||||
.toFixed(
|
.toFixed(
|
||||||
8
|
8
|
||||||
);
|
));
|
||||||
res_bal
|
res_bal
|
||||||
.crypto_balance -=
|
.crypto_balance -=
|
||||||
EqCryptoWd;
|
EqCryptoWd;
|
||||||
@ -14080,7 +14081,7 @@
|
|||||||
const RM_TRADE = new localbitcoinplusplus.trade;
|
const RM_TRADE = new localbitcoinplusplus.trade;
|
||||||
let current_crypto_price = RM_TRADE.get_current_crypto_price_in_fiat(crypto_code, currency);
|
let current_crypto_price = RM_TRADE.get_current_crypto_price_in_fiat(crypto_code, currency);
|
||||||
if (typeof current_crypto_price == "object" && current_crypto_price.rate > 0) {
|
if (typeof current_crypto_price == "object" && current_crypto_price.rate > 0) {
|
||||||
return parseFloat(price / current_crypto_price.rate).toFixed(8);
|
return Number(parseFloat(price / current_crypto_price.rate).toFixed(8));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let err_msg = `WARNING: Failed to calculate crypto equivalent of cash.`;
|
let err_msg = `WARNING: Failed to calculate crypto equivalent of cash.`;
|
||||||
@ -14168,22 +14169,24 @@
|
|||||||
const RM_TRADE = new localbitcoinplusplus.trade;
|
const RM_TRADE = new localbitcoinplusplus.trade;
|
||||||
btc_eq_receiving_amount = RM_TRADE.calculateCryptoEquivalentOfCash(
|
btc_eq_receiving_amount = RM_TRADE.calculateCryptoEquivalentOfCash(
|
||||||
receiving_amount, receiving_amount_currency, crypto_type);
|
receiving_amount, receiving_amount_currency, crypto_type);
|
||||||
btc_eq_receiving_amount = parseFloat(btc_eq_receiving_amount).toFixed(8);
|
btc_eq_receiving_amount = Number(parseFloat(btc_eq_receiving_amount).toFixed(8));
|
||||||
}
|
}
|
||||||
|
|
||||||
let trx = bitjs[crypto_type].transaction();
|
let trx = bitjs[crypto_type].transaction();
|
||||||
let sum = 0;
|
let sum = 0;
|
||||||
|
|
||||||
for (var key in utxo_list) {
|
for (var key in utxo_list) {
|
||||||
if (utxo_list[key].confirmations > 0) {
|
if (utxo_list[key].confirmations !== 0) {
|
||||||
var obj = utxo_list[key];
|
var obj = utxo_list[key];
|
||||||
sum += obj.amount;
|
sum += obj.amount;
|
||||||
|
|
||||||
if (btc_eq_receiving_amount <= sum) {
|
if (btc_eq_receiving_amount <= sum) {
|
||||||
trx.addinput(obj.txid, obj.vout, obj.scriptPubKey);
|
trx.addinput(obj.txid, obj.vout, obj.scriptPubKey);
|
||||||
|
console.log('a');
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
trx.addinput(obj.txid, obj.vout, obj.scriptPubKey);
|
trx.addinput(obj.txid, obj.vout, obj.scriptPubKey);
|
||||||
|
console.log('b');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -14357,8 +14360,8 @@
|
|||||||
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 ==
|
if (typeof sellPipeBTCRes == "object" && typeof sellPipeBTCRes.crypto_balance ==
|
||||||
"number") {
|
"number") {
|
||||||
let seller_btc_balance = parseFloat(sellPipeBTCRes.crypto_balance)
|
let seller_btc_balance = Number(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 = RM_TRADE.calculateCryptoEquivalentOfCash(
|
let eqBTCSeller = RM_TRADE.calculateCryptoEquivalentOfCash(
|
||||||
sell_price_in_inr, buyPipeObj.currency, buyPipeObj.product
|
sell_price_in_inr, buyPipeObj.currency, buyPipeObj.product
|
||||||
@ -14438,7 +14441,7 @@
|
|||||||
let new_seller_btc_balance =
|
let new_seller_btc_balance =
|
||||||
seller_btc_balance -
|
seller_btc_balance -
|
||||||
eqBTCSeller;
|
eqBTCSeller;
|
||||||
new_seller_btc_balance = parseFloat(new_seller_btc_balance).toFixed(8);
|
new_seller_btc_balance = Number(parseFloat(new_seller_btc_balance).toFixed(8));
|
||||||
let sellerBTCResponseObject = {
|
let sellerBTCResponseObject = {
|
||||||
id: `${sellPipeObj.trader_flo_address}_${sellPipeObj.product}`,
|
id: `${sellPipeObj.trader_flo_address}_${sellPipeObj.product}`,
|
||||||
trader_flo_address: sellPipeObj
|
trader_flo_address: sellPipeObj
|
||||||
@ -14570,6 +14573,7 @@
|
|||||||
"data_hash": hashed_data,
|
"data_hash": hashed_data,
|
||||||
"supernode_sign": signed_data,
|
"supernode_sign": signed_data,
|
||||||
"supernodePubKey": user_data.myLocalFLOPublicKey,
|
"supernodePubKey": user_data.myLocalFLOPublicKey,
|
||||||
|
"trader_flo_address": buyPipeObj.trader_flo_address,
|
||||||
}
|
}
|
||||||
callback(response_for_client);
|
callback(response_for_client);
|
||||||
return true;
|
return true;
|
||||||
@ -15284,7 +15288,7 @@
|
|||||||
// Add buy order
|
// Add buy order
|
||||||
backup_server_db_instance.backup_addDB("sellOrders", sellOrders_data).then(() => {
|
backup_server_db_instance.backup_addDB("sellOrders", sellOrders_data).then(() => {
|
||||||
showMessage(`Your sell order is placed successfully.`);
|
showMessage(`Your sell order is placed successfully.`);
|
||||||
});;
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -15402,6 +15406,68 @@
|
|||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
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);
|
||||||
|
let seller_cash_data_str = JSON.stringify(trade_balance_res.seller_cash_data);
|
||||||
|
let buyer_btc_data_str = JSON.stringify(trade_balance_res.buyer_btc_data);
|
||||||
|
let seller_btc_data_str = JSON.stringify(trade_balance_res.seller_btc_data);
|
||||||
|
|
||||||
|
let res_str =
|
||||||
|
`${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_backup_requests(trade_balance_res.trade_infos.buyer_flo_id,
|
||||||
|
function (is_valid_request) {
|
||||||
|
if (is_valid_request !== true) return false;
|
||||||
|
|
||||||
|
if (localbitcoinplusplus.master_configurations.supernodesPubKeys.includes(
|
||||||
|
trade_balance_res.supernodePubKey)) {
|
||||||
|
if (RM_WALLET.verify(hashed_data,
|
||||||
|
trade_balance_res.supernode_sign, trade_balance_res.supernodePubKey)) {
|
||||||
|
|
||||||
|
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);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Delete orders in clients DB
|
||||||
|
try {
|
||||||
|
backup_server_db_instance.backup_removeinDB("buyOrders", trade_balance_res.trade_infos.buy_order_id);
|
||||||
|
backup_server_db_instance.backup_removeinDB("sellOrders", trade_balance_res.trade_infos.sell_order_id);
|
||||||
|
} catch (error) {
|
||||||
|
callback(false);
|
||||||
|
throw new Error(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update balances in clients DB
|
||||||
|
try {
|
||||||
|
backup_server_db_instance.backup_updateinDB("cash_balances", trade_balance_res.buyer_cash_data,
|
||||||
|
trade_balance_res.trade_infos.buyer_flo_id);
|
||||||
|
backup_server_db_instance.backup_updateinDB("cash_balances", trade_balance_res.seller_cash_data,
|
||||||
|
trade_balance_res.trade_infos.seller_flo_id);
|
||||||
|
backup_server_db_instance.backup_updateinDB("crypto_balances", trade_balance_res.buyer_btc_data,
|
||||||
|
trade_balance_res.trade_infos.buyer_flo_id);
|
||||||
|
backup_server_db_instance.backup_updateinDB("crypto_balances", trade_balance_res.seller_btc_data,
|
||||||
|
trade_balance_res.trade_infos.seller_flo_id);
|
||||||
|
} catch (error) {
|
||||||
|
callback(false);
|
||||||
|
throw new Error(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case "update_all_withdraw_cash_depositor_claim":
|
case "update_all_withdraw_cash_depositor_claim":
|
||||||
if (typeof res_obj.params !== "object"
|
if (typeof res_obj.params !== "object"
|
||||||
|| typeof res_obj.params[0] !== "object") return;
|
|| typeof res_obj.params[0] !== "object") return;
|
||||||
@ -15597,6 +15663,96 @@
|
|||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case "send_back_shamirs_secret_supernode_pvtkey":
|
||||||
|
if (typeof res_obj.params == "object" && typeof res_obj.params[0] == "object") {
|
||||||
|
|
||||||
|
if(typeof res_obj.globalParams.senderFloId !="string") return;
|
||||||
|
localbitcoinplusplus.kademlia.determineClosestSupernode(res_obj.globalParams.senderFloId)
|
||||||
|
.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_readDB("supernode_private_key_chunks", res_obj.params[0].chunk_val)
|
||||||
|
.then(function (res) {
|
||||||
|
if (typeof res=="object") {
|
||||||
|
let send_pvtkey_req = RM_RPC
|
||||||
|
.send_rpc
|
||||||
|
.call(this, "retrieve_shamirs_secret_supernode_pvtkey", {
|
||||||
|
private_key_chunk: res
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
let send_pvtkey_req = RM_RPC
|
||||||
|
.send_rpc
|
||||||
|
.call(this, "retrieve_shamirs_secret_supernode_pvtkey", "");
|
||||||
|
}
|
||||||
|
send_pvtkey_req.globalParams.primarySupernode = primarySupernodeOfThisUser;
|
||||||
|
doSend(send_pvtkey_req, res_obj.globalParams.senderFloId);
|
||||||
|
return;
|
||||||
|
});
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "send_back_shamirs_secret_btc_pvtkey":
|
||||||
|
if (typeof res_obj.params == "object" && typeof res_obj.params[0] == "object") {
|
||||||
|
|
||||||
|
if(typeof res_obj.globalParams.senderFloId !="string") return;
|
||||||
|
localbitcoinplusplus.kademlia.determineClosestSupernode(res_obj.globalParams.senderFloId)
|
||||||
|
.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_readDB("supernode_private_key_chunks", res_obj.params[0].chunk_val).then(function (
|
||||||
|
res) {
|
||||||
|
let send_pvtkey_req = RM_RPC
|
||||||
|
.send_rpc
|
||||||
|
.call(this, "retrieve_shamirs_secret_btc_pvtkey", {
|
||||||
|
retrieve_pvtkey_req_id: res_obj.params[0].retrieve_pvtkey_req_id,
|
||||||
|
private_key_chunk: res,
|
||||||
|
withdraw_id: res_obj.params[0].withdraw_id
|
||||||
|
});
|
||||||
|
//if(typeof send_pvtkey_req.globalParams !== "object") send_pvtkey_req.globalParams = [];
|
||||||
|
//send_pvtkey_req.globalParams.primarySupernode = res_obj.globalParams.senderFloId;
|
||||||
|
doSend(send_pvtkey_req, res_obj.globalParams.senderFloId);
|
||||||
|
return;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "store_shamirs_secret_pvtkey_shares":
|
||||||
|
if (typeof res_obj.params == "object" && typeof res_obj.params[0] == "object") {
|
||||||
|
|
||||||
|
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);
|
||||||
|
};
|
||||||
|
delete res_obj.params[0].trader_flo_address;
|
||||||
|
backup_server_db_instance.backup_addDB("supernode_private_key_chunks", res_obj.params[0]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -15825,9 +15981,12 @@
|
|||||||
try {
|
try {
|
||||||
var res_obj = JSON.parse(res);
|
var res_obj = JSON.parse(res);
|
||||||
|
|
||||||
if (typeof res_obj.globalParams.receiverFloId=="string"
|
if (typeof res_obj.method !== "string"
|
||||||
&& res_obj.globalParams.receiverFloId !==
|
|| typeof res_obj.globalParams !== "object"
|
||||||
|
|| typeof res_obj.globalParams.receiverFloId !== "string"
|
||||||
|
|| res_obj.globalParams.receiverFloId !==
|
||||||
localbitcoinplusplus.wallets.my_local_flo_address) {
|
localbitcoinplusplus.wallets.my_local_flo_address) {
|
||||||
|
showMessage(`WARNING: Incomplete onMessage request received.`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -16029,7 +16188,7 @@
|
|||||||
case "withdraw_request_method":
|
case "withdraw_request_method":
|
||||||
response_from_sever = RM_RPC.receive_rpc_response.call(this,
|
response_from_sever = RM_RPC.receive_rpc_response.call(this,
|
||||||
JSON.stringify(res_obj));
|
JSON.stringify(res_obj));
|
||||||
doSend(JSON.stringify(response_from_sever)); // send response to client
|
//doSend(JSON.stringify(response_from_sever)); // send response to client
|
||||||
break;
|
break;
|
||||||
case "withdrawal_request_response":
|
case "withdrawal_request_response":
|
||||||
if (typeof res_obj.params == "object" && typeof res_obj.params[0] == "object") {
|
if (typeof res_obj.params == "object" && typeof res_obj.params[0] == "object") {
|
||||||
@ -16212,6 +16371,7 @@
|
|||||||
delete res_obj.params[0].private_key_chunk;
|
delete res_obj.params[0].private_key_chunk;
|
||||||
res_obj.params[0].btc_private_key_array = JSON.stringify(btc_pvt_arr[
|
res_obj.params[0].btc_private_key_array = JSON.stringify(btc_pvt_arr[
|
||||||
retrieve_pvtkey_req_id]);
|
retrieve_pvtkey_req_id]);
|
||||||
|
res_obj.params[0].trader_flo_address = localbitcoinplusplus.wallets.my_local_flo_address;
|
||||||
RM_RPC.receive_rpc_response.call(this, JSON.stringify(res_obj));
|
RM_RPC.receive_rpc_response.call(this, JSON.stringify(res_obj));
|
||||||
btc_pvt_arr[retrieve_pvtkey_req_id] = []; // Unset the object
|
btc_pvt_arr[retrieve_pvtkey_req_id] = []; // Unset the object
|
||||||
}
|
}
|
||||||
@ -16220,7 +16380,7 @@
|
|||||||
case "deposit_withdraw_user_claim":
|
case "deposit_withdraw_user_claim":
|
||||||
|
|
||||||
if (typeof localbitcoinplusplus.wallets.MY_SUPERNODE_PRIVATE_KEY ==
|
if (typeof localbitcoinplusplus.wallets.MY_SUPERNODE_PRIVATE_KEY ==
|
||||||
"undefined") throw new Error("Supernode Private Keys is undefind.");
|
"undefined") throw new Error("Supernode Private Keys is undefined.");
|
||||||
if (typeof res_obj.params == "object" && typeof res_obj.params[0] ==
|
if (typeof res_obj.params == "object" && typeof res_obj.params[0] ==
|
||||||
"object") {
|
"object") {
|
||||||
let user_claim_request = res_obj.params[0];
|
let user_claim_request = res_obj.params[0];
|
||||||
@ -17051,7 +17211,7 @@
|
|||||||
case "withdraw_request_method":
|
case "withdraw_request_method":
|
||||||
response_from_sever = RM_RPC.backup_receive_rpc_response.call(this,
|
response_from_sever = RM_RPC.backup_receive_rpc_response.call(this,
|
||||||
JSON.stringify(res_obj));
|
JSON.stringify(res_obj));
|
||||||
doSend(JSON.stringify(response_from_sever)); // send response to client
|
//doSend(JSON.stringify(response_from_sever)); // send response to client
|
||||||
break;
|
break;
|
||||||
case "withdrawal_request_response":
|
case "withdrawal_request_response":
|
||||||
if (typeof res_obj.params == "object" && typeof res_obj.params[0] == "object") {
|
if (typeof res_obj.params == "object" && typeof res_obj.params[0] == "object") {
|
||||||
@ -17082,7 +17242,6 @@
|
|||||||
showMessage(backup_db_error_msg);
|
showMessage(backup_db_error_msg);
|
||||||
throw new Error(backup_db_error_msg);
|
throw new Error(backup_db_error_msg);
|
||||||
};
|
};
|
||||||
})
|
|
||||||
|
|
||||||
backup_server_db_instance.backup_readDB("userPublicData", cancel_request.trader_flo_address).then((trader_data) => {
|
backup_server_db_instance.backup_readDB("userPublicData", cancel_request.trader_flo_address).then((trader_data) => {
|
||||||
if (typeof trader_data.trader_flo_address !== "string" || typeof trader_data
|
if (typeof trader_data.trader_flo_address !== "string" || typeof trader_data
|
||||||
@ -17104,6 +17263,7 @@
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
showMessage("Failed to cancel trade.");
|
showMessage("Failed to cancel trade.");
|
||||||
}
|
}
|
||||||
@ -17165,8 +17325,8 @@
|
|||||||
case "store_shamirs_secret_pvtkey_shares":
|
case "store_shamirs_secret_pvtkey_shares":
|
||||||
if (typeof res_obj.params == "object" && typeof res_obj.params[0] == "object") {
|
if (typeof res_obj.params == "object" && typeof res_obj.params[0] == "object") {
|
||||||
|
|
||||||
if(typeof res_obj.globalParams.primarySupernode !="string") return;
|
if(typeof res_obj.params[0].trader_flo_address !="string") return;
|
||||||
localbitcoinplusplus.kademlia.determineClosestSupernode(res_obj.globalParams.primarySupernode)
|
localbitcoinplusplus.kademlia.determineClosestSupernode(res_obj.params[0].trader_flo_address)
|
||||||
.then(my_closest_su_list=>{
|
.then(my_closest_su_list=>{
|
||||||
const primarySupernodeOfThisUser = my_closest_su_list[0].data.id;
|
const primarySupernodeOfThisUser = my_closest_su_list[0].data.id;
|
||||||
const backup_server_db_instance = localbitcoinplusplus.newBackupDatabase.db[primarySupernodeOfThisUser];
|
const backup_server_db_instance = localbitcoinplusplus.newBackupDatabase.db[primarySupernodeOfThisUser];
|
||||||
@ -17176,9 +17336,9 @@
|
|||||||
showMessage(backup_db_error_msg);
|
showMessage(backup_db_error_msg);
|
||||||
throw new Error(backup_db_error_msg);
|
throw new Error(backup_db_error_msg);
|
||||||
};
|
};
|
||||||
});
|
delete res_obj.params[0].trader_flo_address;
|
||||||
|
|
||||||
backup_server_db_instance.backup_addDB("supernode_private_key_chunks", res_obj.params[0]);
|
backup_server_db_instance.backup_addDB("supernode_private_key_chunks", res_obj.params[0]);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "send_back_shamirs_secret_supernode_pvtkey":
|
case "send_back_shamirs_secret_supernode_pvtkey":
|
||||||
@ -17195,7 +17355,6 @@
|
|||||||
showMessage(backup_db_error_msg);
|
showMessage(backup_db_error_msg);
|
||||||
throw new Error(backup_db_error_msg);
|
throw new Error(backup_db_error_msg);
|
||||||
};
|
};
|
||||||
})
|
|
||||||
|
|
||||||
backup_server_db_instance.backup_readDB("supernode_private_key_chunks", res_obj.params[0].chunk_val)
|
backup_server_db_instance.backup_readDB("supernode_private_key_chunks", res_obj.params[0].chunk_val)
|
||||||
.then(function (res) {
|
.then(function (res) {
|
||||||
@ -17217,6 +17376,7 @@
|
|||||||
return;
|
return;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "retrieve_shamirs_secret_supernode_pvtkey":
|
case "retrieve_shamirs_secret_supernode_pvtkey":
|
||||||
@ -17266,7 +17426,6 @@
|
|||||||
showMessage(backup_db_error_msg);
|
showMessage(backup_db_error_msg);
|
||||||
throw new Error(backup_db_error_msg);
|
throw new Error(backup_db_error_msg);
|
||||||
};
|
};
|
||||||
});
|
|
||||||
|
|
||||||
backup_server_db_instance.backup_readDB("supernode_private_key_chunks", res_obj.params[0].chunk_val).then(function (
|
backup_server_db_instance.backup_readDB("supernode_private_key_chunks", res_obj.params[0].chunk_val).then(function (
|
||||||
res) {
|
res) {
|
||||||
@ -17279,11 +17438,13 @@
|
|||||||
});
|
});
|
||||||
localbitcoinplusplus.kademlia.determineClosestSupernode(res_obj.globalParams.senderFloId)
|
localbitcoinplusplus.kademlia.determineClosestSupernode(res_obj.globalParams.senderFloId)
|
||||||
.then(my_closest_su=>{
|
.then(my_closest_su=>{
|
||||||
send_pvtkey_req.globalParams.primarySupernode = my_closest_su[0].data.id;
|
//if(typeof send_pvtkey_req.globalParams !== "object") send_pvtkey_req.globalParams = [];
|
||||||
|
//send_pvtkey_req.globalParams.primarySupernode = my_closest_su[0].data.id;
|
||||||
doSend(send_pvtkey_req);
|
doSend(send_pvtkey_req);
|
||||||
return;
|
return;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "retrieve_shamirs_secret_btc_pvtkey":
|
case "retrieve_shamirs_secret_btc_pvtkey":
|
||||||
@ -17303,6 +17464,7 @@
|
|||||||
delete res_obj.params[0].private_key_chunk;
|
delete res_obj.params[0].private_key_chunk;
|
||||||
res_obj.params[0].btc_private_key_array = JSON.stringify(btc_pvt_arr[
|
res_obj.params[0].btc_private_key_array = JSON.stringify(btc_pvt_arr[
|
||||||
retrieve_pvtkey_req_id]);
|
retrieve_pvtkey_req_id]);
|
||||||
|
res_obj.params[0].trader_flo_address = localbitcoinplusplus.wallets.my_local_flo_address;
|
||||||
RM_RPC.backup_receive_rpc_response.call(this, JSON.stringify(res_obj));
|
RM_RPC.backup_receive_rpc_response.call(this, JSON.stringify(res_obj));
|
||||||
btc_pvt_arr[retrieve_pvtkey_req_id] = []; // Unset the object
|
btc_pvt_arr[retrieve_pvtkey_req_id] = []; // Unset the object
|
||||||
}
|
}
|
||||||
@ -17347,7 +17509,6 @@
|
|||||||
showMessage(backup_db_error_msg);
|
showMessage(backup_db_error_msg);
|
||||||
throw new Error(backup_db_error_msg);
|
throw new Error(backup_db_error_msg);
|
||||||
};
|
};
|
||||||
});
|
|
||||||
|
|
||||||
backup_server_db_instance.backup_readDB("withdraw_cash", withdraw_order_id).then(async function (
|
backup_server_db_instance.backup_readDB("withdraw_cash", withdraw_order_id).then(async function (
|
||||||
withdraw_data) {
|
withdraw_data) {
|
||||||
@ -17469,6 +17630,9 @@
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -17565,9 +17729,8 @@
|
|||||||
showMessage(backup_db_error_msg);
|
showMessage(backup_db_error_msg);
|
||||||
throw new Error(backup_db_error_msg);
|
throw new Error(backup_db_error_msg);
|
||||||
};
|
};
|
||||||
});
|
|
||||||
|
|
||||||
backup_server_db_instance.backup_addDB('userPublicData', public_req_object);
|
backup_server_db_instance.backup_addDB('userPublicData', public_req_object);
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -17598,8 +17761,6 @@
|
|||||||
showMessage(backup_db_error_msg);
|
showMessage(backup_db_error_msg);
|
||||||
throw new Error(backup_db_error_msg);
|
throw new Error(backup_db_error_msg);
|
||||||
};
|
};
|
||||||
});
|
|
||||||
|
|
||||||
backup_server_db_instance.backup_readDBbyIndex("deposit", 'status', 1).then(function (res) {
|
backup_server_db_instance.backup_readDBbyIndex("deposit", 'status', 1).then(function (res) {
|
||||||
res.map(function (deposit_trade) {
|
res.map(function (deposit_trade) {
|
||||||
if (localbitcoinplusplus.master_configurations.tradableAsset1
|
if (localbitcoinplusplus.master_configurations.tradableAsset1
|
||||||
@ -17609,6 +17770,7 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "update_external_file_request":
|
case "update_external_file_request":
|
||||||
@ -17632,7 +17794,6 @@
|
|||||||
showMessage(backup_db_error_msg);
|
showMessage(backup_db_error_msg);
|
||||||
throw new Error(backup_db_error_msg);
|
throw new Error(backup_db_error_msg);
|
||||||
};
|
};
|
||||||
});
|
|
||||||
|
|
||||||
if (typeof update_script_request.file_to_update == "string") {
|
if (typeof update_script_request.file_to_update == "string") {
|
||||||
|
|
||||||
@ -17678,6 +17839,8 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "update_external_file_server_response":
|
case "update_external_file_server_response":
|
||||||
@ -17700,7 +17863,6 @@
|
|||||||
showMessage(backup_db_error_msg);
|
showMessage(backup_db_error_msg);
|
||||||
throw new Error(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 = backup_server_db_instance.backup_readDB('userPublicData', updateUserCryptoBalanceResponseObject.trader_flo_address)
|
||||||
.then(user_data => {
|
.then(user_data => {
|
||||||
@ -17726,6 +17888,8 @@
|
|||||||
showMessage(`WARNING: Failed to update balance in your DB. Please refresh.`);
|
showMessage(`WARNING: Failed to update balance in your DB. Please refresh.`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "addNewKbucketNode":
|
case "addNewKbucketNode":
|
||||||
@ -18896,6 +19060,14 @@
|
|||||||
|
|
||||||
async backup_updateinDB(tablename, Obj, key) {
|
async backup_updateinDB(tablename, Obj, key) {
|
||||||
try {
|
try {
|
||||||
|
if(typeof Obj.vectorClock == "undefined") {
|
||||||
|
Obj.vectorClock = 0;
|
||||||
|
} else if(typeof Obj.increaseVectorClock == "boolean"
|
||||||
|
&& Obj.increaseVectorClock === false) {
|
||||||
|
// leave the vector clock field unchanged
|
||||||
|
} else {
|
||||||
|
Obj.vectorClock += 1;
|
||||||
|
}
|
||||||
this.request = this.db.transaction([tablename], "readwrite")
|
this.request = this.db.transaction([tablename], "readwrite")
|
||||||
let store = this.request.objectStore(tablename)
|
let store = this.request.objectStore(tablename)
|
||||||
await store.put(Obj);
|
await store.put(Obj);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user