added code to update backups about deposit and btc_reserves when a withdraw btc is complete

This commit is contained in:
Abhishek Sinha 2019-07-27 16:20:04 +05:30
parent 489c784bb3
commit 9186c03d38

View File

@ -11736,20 +11736,16 @@
if (is_valid_request !== true) return false; if (is_valid_request !== true) return false;
// This code will only run for supernodes // This code will only run for supernodes
if (typeof params.product !== "undefined" && if (typeof params.product !== "undefined"
(localbitcoinplusplus.master_configurations.tradableAsset1.includes( && (localbitcoinplusplus.master_configurations.tradableAsset1.includes(params.product)
params.product) || || localbitcoinplusplus.master_configurations.tradableAsset2.includes(params.product))
localbitcoinplusplus.master_configurations.tradableAsset2.includes( && typeof params.depositing_amount !== "undefined"
params.product)) && && localbitcoinplusplus.master_configurations.tradableAsset2.includes(params.currency)
typeof params.depositing_amount !== "undefined" && && typeof localbitcoinplusplus.master_configurations.validTradingAmount !== 'undefined'
localbitcoinplusplus.master_configurations.tradableAsset2.includes( && localbitcoinplusplus.master_configurations.validTradingAmount
params.currency) && .includes(parseFloat(params.depositing_amount))
typeof localbitcoinplusplus.master_configurations.validTradingAmount !== && typeof params.trader_flo_address == "string"
'undefined' && && params.trader_flo_address.length > 0
localbitcoinplusplus.master_configurations.validTradingAmount.includes(
parseFloat(params.depositing_amount)) &&
typeof params.trader_flo_address == "string" &&
params.trader_flo_address.length > 0
) { ) {
RM_WALLET.getUserPublicKey(params.trader_flo_address, RM_WALLET.getUserPublicKey(params.trader_flo_address,
async function (requester_public_key) { async function (requester_public_key) {
@ -11790,7 +11786,7 @@
} }
readDB("localbitcoinUser", "00-01").then( readDB("localbitcoinUser", "00-01").then(
function (su_data) { async function (su_data) {
if (typeof su_data == "object" && if (typeof su_data == "object" &&
typeof su_data.myLocalFLOPublicKey == typeof su_data.myLocalFLOPublicKey ==
"string" && "string" &&
@ -11818,16 +11814,15 @@
if (typeof this_btc_pvt_key_shamirs_secret == "object" if (typeof this_btc_pvt_key_shamirs_secret == "object"
&& this_btc_pvt_key_shamirs_secret.length > 0) { && this_btc_pvt_key_shamirs_secret.length > 0) {
addDB("deposit", receivedTradeInfo); const deposit_res = await addDB("deposit", receivedTradeInfo);
// Send the address to the requester // Send the address to the requester
let let deposit_response_object = {
deposit_response_object = { error: false,
error: false, method: "deposit_asset_request_response",
method: "deposit_asset_request_response", msg: `Please send ${params.product} ${params.bitcoinToBePaid} to the following addres: ${generate_btc_keys_for_requester.address}.`,
msg: `Please send ${params.product} ${params.bitcoinToBePaid} to the following addres: ${generate_btc_keys_for_requester.address}.`, data: deposit_res
data: receivedTradeInfo };
};
deposit_response_object.receiver_flo_address = params.trader_flo_address; deposit_response_object.receiver_flo_address = params.trader_flo_address;
deposit_response_object.trader_flo_address = params.trader_flo_address; deposit_response_object.trader_flo_address = params.trader_flo_address;
RM_RPC RM_RPC
@ -11932,21 +11927,21 @@
} }
// Send the address to the requester // Send the address to the requester
let deposit_response_object = { // let deposit_response_object = {
error: false, // error: false,
method: "deposit_asset_request_response", // method: "deposit_asset_request_response",
msg: `Please send the ${params.product} to ${generate_btc_keys_for_requester.address}.`, // msg: `Please send the ${params.product} to ${generate_btc_keys_for_requester.address}.`,
data: receivedTradeInfo, // data: receivedTradeInfo,
receiver_flo_address: params.trader_flo_address, // receiver_flo_address: params.trader_flo_address,
trader_flo_address: params.trader_flo_address, // trader_flo_address: params.trader_flo_address,
}; // };
RM_RPC.send_rpc // RM_RPC.send_rpc
.call(this, // .call(this,
"deposit_asset_request_response", // "deposit_asset_request_response",
deposit_response_object // deposit_response_object
).then(deposit_request_response=> // ).then(deposit_request_response=>
doSend(deposit_request_response)); // doSend(deposit_request_response));
return true; return true;
} }
}); });
@ -11976,11 +11971,9 @@
Crypto.SHA256(JSON.stringify( Crypto.SHA256(JSON.stringify(
receivedTradeInfo)); receivedTradeInfo));
receivedTradeInfo[ receivedTradeInfo["depositDataHash"] =
"depositDataHash"] =
receivedTradeInfoHash; receivedTradeInfoHash;
receivedTradeInfo[ receivedTradeInfo["order_validator_sign"] =
"order_validator_sign"] =
RM_WALLET.sign( RM_WALLET.sign(
receivedTradeInfoHash, receivedTradeInfoHash,
localbitcoinplusplus.wallets localbitcoinplusplus.wallets
@ -11992,12 +11985,11 @@
// YOU NEED TO DETERMINE A BANK ACCOUNT HERE IF NO ONE IS WITHDRAWING // YOU NEED TO DETERMINE A BANK ACCOUNT HERE IF NO ONE IS WITHDRAWING
try { try {
addDB("deposit", addDB("deposit", receivedTradeInfo);
receivedTradeInfo);
readDBbyIndex( readDBbyIndex(
"withdraw_cash", "withdraw_cash",
"status", 1).then( "status", 1).then(
function ( async function (
withdrawers_list withdrawers_list
) { ) {
if (typeof withdrawers_list == if (typeof withdrawers_list ==
@ -12007,7 +11999,7 @@
withdrawers_list.filter( withdrawers_list.filter(
wd => wd.currency == wd => wd.currency ==
params.currency).map( params.currency).map(
function (withdrawer) { async function (withdrawer) {
if ( if (
withdrawer.withdraw_amount == withdrawer.withdraw_amount ==
params.depositing_amount && params.depositing_amount &&
@ -12017,10 +12009,10 @@
withdrawer.status = 2; // A depositor has been asked to deposit money withdrawer.status = 2; // A depositor has been asked to deposit money
withdrawer.depositor_found_at = + new Date(); withdrawer.depositor_found_at = + new Date();
withdrawer.depositor_flo_id = receivedTradeInfo.trader_flo_address; withdrawer.depositor_flo_id = receivedTradeInfo.trader_flo_address;
updateinDB ("withdraw_cash", withdrawer, withdrawer.trader_flo_address); const withdraw_resp = await updateinDB ("withdraw_cash", withdrawer, withdrawer.trader_flo_address);
receivedTradeInfo.status = 2; // withdrawer found. Now deposit money to his account receivedTradeInfo.status = 2; // withdrawer found. Now deposit money to his account
updateinDB( const receivedTradeInfo_resp = await updateinDB(
"deposit", "deposit",
receivedTradeInfo, receivedTradeInfo,
receivedTradeInfo.trader_flo_address receivedTradeInfo.trader_flo_address
@ -12031,9 +12023,9 @@
let deposit_response_object = { let deposit_response_object = {
error: false, error: false,
method: "deposit_asset_request_response", method: "deposit_asset_request_response",
msg: `Plese send the money to following bank address: "${withdrawer_bank_account}"`, msg: `Please send the money to following bank address: "${withdrawer_bank_account}"`,
data: receivedTradeInfo, data: receivedTradeInfo_resp,
withdrawer_data: withdrawer, withdrawer_data: withdraw_resp,
receiver_flo_address: receivedTradeInfo.trader_flo_address, receiver_flo_address: receivedTradeInfo.trader_flo_address,
trader_flo_address: receivedTradeInfo.trader_flo_address, trader_flo_address: receivedTradeInfo.trader_flo_address,
}; };
@ -12054,18 +12046,9 @@
); );
} else { } else {
//No one is withdrawing so provide your bank details //No one is withdrawing so provide your bank details
let
deposit_response_object = {
error: false,
method: "deposit_asset_request_response",
msg: `Plese send the money to following bank address: "System determined bank".`,
data: receivedTradeInfo,
receiver_flo_address: receivedTradeInfo.trader_flo_address,
trader_flo_address: receivedTradeInfo.trader_flo_address,
};
receivedTradeInfo.status = 2; // withdrawer found. Now deposit money to his account receivedTradeInfo.status = 2; // withdrawer found. Now deposit money to his account
updateinDB const receivedTradeInfo_resp = await updateinDB
( (
"deposit", "deposit",
receivedTradeInfo, receivedTradeInfo,
@ -12073,6 +12056,15 @@
.trader_flo_address .trader_flo_address
); );
let deposit_response_object = {
error: false,
method: "deposit_asset_request_response",
msg: `Please send the money to following bank address: "System determined bank".`,
data: receivedTradeInfo_resp,
receiver_flo_address: receivedTradeInfo.trader_flo_address,
trader_flo_address: receivedTradeInfo.trader_flo_address,
};
RM_RPC RM_RPC
.send_rpc .send_rpc
.call( .call(
@ -12130,8 +12122,7 @@
params.trader_flo_address, params.product, params.currency params.trader_flo_address, params.product, params.currency
); );
if (localbitcoinplusplus.master_configurations.tradableAsset1.includes( if (localbitcoinplusplus.master_configurations.tradableAsset1.includes(params.product)) {
params.product)) {
if (trade_margin.remaining_crypto_credit < 0 if (trade_margin.remaining_crypto_credit < 0
|| params.withdrawing_amount <= 0 || params.withdrawing_amount <= 0
|| trade_margin.remaining_crypto_credit < params.withdrawing_amount) { || trade_margin.remaining_crypto_credit < params.withdrawing_amount) {
@ -12421,17 +12412,20 @@
addDB( addDB(
"withdraw_cash", "withdraw_cash",
withdraw_request_db_object withdraw_request_db_object
); ).then(withdraw_request_db_object=>{
// return back the response to client // return back the response to client
withdraw_request_db_object.receiver_flo_address = withdraw_request_db_object.receiver_flo_address =
params.trader_flo_address; params.trader_flo_address;
withdraw_request_db_object.trader_flo_address = withdraw_request_db_object.trader_flo_address =
params.trader_flo_address; params.trader_flo_address;
RM_RPC.send_rpc RM_RPC.send_rpc
.call(this, .call(this,
"withdrawal_request_response", "withdrawal_request_response",
withdraw_request_db_object withdraw_request_db_object
).then(withdrawal_request_response=>doSend(withdrawal_request_response)); ).then(withdrawal_request_response=>
doSend(withdrawal_request_response));
});
return true; return true;
} catch (error) { } catch (error) {
console.log(error); console.log(error);
@ -12563,7 +12557,7 @@
); );
const updateUserCryptoBalanceObject = { const updateUserCryptoBalanceObject = {
updatedBTCBalanceObject: res_bal, updatedBTCBalanceObject: res_obj,
updatedBTCBalanceObjectSign: res_obj_sign, updatedBTCBalanceObjectSign: res_obj_sign,
trader_flo_address: withdraw_res.trader_flo_address, trader_flo_address: withdraw_res.trader_flo_address,
receiver_flo_address: withdraw_res.trader_flo_address, receiver_flo_address: withdraw_res.trader_flo_address,
@ -12632,14 +12626,32 @@
if (typeof current_balance=="number") { if (typeof current_balance=="number") {
deposit_arr.bitcoinToBePaid = current_balance; deposit_arr.bitcoinToBePaid = current_balance;
btc_reserves.balance = current_balance;
} else { } else {
deposit_arr.bitcoinToBePaid -= EqCryptoWd; deposit_arr.bitcoinToBePaid -= EqCryptoWd;
btc_reserves.balance -= EqCryptoWd;
} }
if (deposit_arr.bitcoinToBePaid > 0) { if (deposit_arr.bitcoinToBePaid > 0) {
// update deposits in db // update deposits in db
deposit_arr.status = 2; // UTXO ready to be used again deposit_arr.status = 2; // UTXO ready to be used again
updateinDB("deposit", deposit_arr, deposit_arr.id); const deposit_resp = await updateinDB("deposit", deposit_arr, deposit_arr.id)
// Update new balance in system_btc_reserves
const reserves_resp = await updateinDB("system_btc_reserves_private_keys",
btc_reserves, btc_reserves.id);
// Send the resp to backups
RM_RPC
.send_rpc(
"update_deposited_crypto_instance",
{
deposit_data: deposit_resp,
btc_reserve_data: reserves_resp,
db_inst: params.db_inst,
trader_flo_address: deposit_arr.trader_flo_address
}
).then(delRequestObject=>
doSend(delRequestObject));
// Do not delete these data instantly as the data // Do not delete these data instantly as the data
// may be required by a follow-up withdraw request // may be required by a follow-up withdraw request
@ -12658,6 +12670,10 @@
doSend(delRequestObject)); doSend(delRequestObject));
}); });
// AND DO THE SAME ABOVE 2 IN BACKUP RECEIVE RPC
} else { } else {
// Do not delete these data instantly as the data // Do not delete these data instantly as the data
// may be required by a follow-up withdraw request // may be required by a follow-up withdraw request
@ -13057,7 +13073,7 @@
} }
readDB("localbitcoinUser", "00-01").then( readDB("localbitcoinUser", "00-01").then(
function (su_data) { async function (su_data) {
if (typeof su_data == "object" && if (typeof su_data == "object" &&
typeof su_data.myLocalFLOPublicKey == typeof su_data.myLocalFLOPublicKey ==
"string" && "string" &&
@ -13090,16 +13106,16 @@
"object" && "object" &&
this_btc_pvt_key_shamirs_secret this_btc_pvt_key_shamirs_secret
.length > 0) { .length > 0) {
backup_server_db_instance.backup_addDB("deposit", receivedTradeInfo);
const deposit_res = await backup_server_db_instance.backup_addDB("deposit", receivedTradeInfo);
// Send the address to the requester // Send the address to the requester
let let deposit_response_object = {
deposit_response_object = { error: false,
error: false, method: "deposit_asset_request_response",
method: "deposit_asset_request_response", msg: `Please send ${params.product} ${params.bitcoinToBePaid} to the following addres: ${generate_btc_keys_for_requester.address}.`,
msg: `Please send ${params.product} ${params.bitcoinToBePaid} to the following addres: ${generate_btc_keys_for_requester.address}.`, data: deposit_res
data: receivedTradeInfo };
};
deposit_response_object.receiver_flo_address = params.trader_flo_address; deposit_response_object.receiver_flo_address = params.trader_flo_address;
deposit_response_object.trader_flo_address = params.trader_flo_address; deposit_response_object.trader_flo_address = params.trader_flo_address;
@ -13206,21 +13222,21 @@
} }
// Send the address to the requester // Send the address to the requester
let deposit_response_object = { // let deposit_response_object = {
error: false, // error: false,
method: "deposit_asset_request_response", // method: "deposit_asset_request_response",
msg: `Please send the ${params.product} to ${generate_btc_keys_for_requester.address}.`, // msg: `Please send the ${params.product} to ${generate_btc_keys_for_requester.address}.`,
data: receivedTradeInfo, // data: deposit_res,
receiver_flo_address: params.trader_flo_address, // receiver_flo_address: params.trader_flo_address,
trader_flo_address: params.trader_flo_address, // trader_flo_address: params.trader_flo_address,
}; // };
RM_RPC.send_rpc // RM_RPC.send_rpc
.call(this, // .call(this,
"deposit_asset_request_response", // "deposit_asset_request_response",
deposit_response_object // deposit_response_object
).then(deposit_request_response=> // ).then(deposit_request_response=>
doSend(deposit_request_response)); // doSend(deposit_request_response));
return true; return true;
} }
}); });
@ -13269,11 +13285,8 @@
backup_server_db_instance.backup_addDB("deposit", backup_server_db_instance.backup_addDB("deposit",
receivedTradeInfo); receivedTradeInfo);
backup_server_db_instance.backup_readDBbyIndex( backup_server_db_instance.backup_readDBbyIndex(
"withdraw_cash", "withdraw_cash", "status", 1)
"status", 1).then( .then(async function (withdrawers_list) {
function (
withdrawers_list
) {
if (typeof withdrawers_list == if (typeof withdrawers_list ==
"object") { "object") {
if ( if (
@ -13281,7 +13294,7 @@
withdrawers_list.filter( withdrawers_list.filter(
wd => wd.currency == wd => wd.currency ==
params.currency).map( params.currency).map(
function (withdrawer) { async function (withdrawer) {
if ( if (
withdrawer.withdraw_amount == withdrawer.withdraw_amount ==
params.depositing_amount && params.depositing_amount &&
@ -13291,10 +13304,11 @@
withdrawer.status = 2; // A depositor has been asked to deposit money withdrawer.status = 2; // A depositor has been asked to deposit money
withdrawer.depositor_found_at = + new Date(); withdrawer.depositor_found_at = + new Date();
withdrawer.depositor_flo_id = receivedTradeInfo.trader_flo_address; withdrawer.depositor_flo_id = receivedTradeInfo.trader_flo_address;
backup_server_db_instance.backup_updateinDB ("withdraw_cash", withdrawer, withdrawer.trader_flo_address); const withdraw_resp = await backup_server_db_instance
.backup_updateinDB ("withdraw_cash", withdrawer, withdrawer.trader_flo_address);
receivedTradeInfo.status = 2; // withdrawer found. Now deposit money to his account receivedTradeInfo.status = 2; // withdrawer found. Now deposit money to his account
backup_server_db_instance.backup_updateinDB( const receivedTradeInfo_resp = await backup_server_db_instance.backup_updateinDB(
"deposit", "deposit",
receivedTradeInfo, receivedTradeInfo,
receivedTradeInfo.trader_flo_address receivedTradeInfo.trader_flo_address
@ -13305,9 +13319,9 @@
let deposit_response_object = { let deposit_response_object = {
error: false, error: false,
method: "deposit_asset_request_response", method: "deposit_asset_request_response",
msg: `Plese send the money to following bank address: "${withdrawer_bank_account}"`, msg: `Please send the money to following bank address: "${withdrawer_bank_account}"`,
data: receivedTradeInfo, data: receivedTradeInfo_resp,
withdrawer_data: withdrawer, withdrawer_data: withdraw_resp,
receiver_flo_address: receivedTradeInfo.trader_flo_address, receiver_flo_address: receivedTradeInfo.trader_flo_address,
trader_flo_address: receivedTradeInfo.trader_flo_address, trader_flo_address: receivedTradeInfo.trader_flo_address,
}; };
@ -13328,18 +13342,9 @@
); );
} else { } else {
//No one is withdrawing so provide your bank details //No one is withdrawing so provide your bank details
let
deposit_response_object = {
error: false,
method: "deposit_asset_request_response",
msg: `Plese send the money to following bank address: "System determined bank".`,
data: receivedTradeInfo,
receiver_flo_address: receivedTradeInfo.trader_flo_address,
trader_flo_address: receivedTradeInfo.trader_flo_address,
};
receivedTradeInfo.status = 2; // withdrawer found. Now deposit money to his account receivedTradeInfo.status = 2; // withdrawer found. Now deposit money to his account
updateinDB const receivedTradeInfo_resp = await updateinDB
( (
"deposit", "deposit",
receivedTradeInfo, receivedTradeInfo,
@ -13347,6 +13352,15 @@
.trader_flo_address .trader_flo_address
); );
let deposit_response_object = {
error: false,
method: "deposit_asset_request_response",
msg: `Please send the money to following bank address: "System determined bank".`,
data: receivedTradeInfo_resp,
receiver_flo_address: receivedTradeInfo.trader_flo_address,
trader_flo_address: receivedTradeInfo.trader_flo_address,
};
RM_RPC RM_RPC
.send_rpc .send_rpc
.call( .call(
@ -13647,18 +13661,20 @@
backup_server_db_instance.backup_addDB( backup_server_db_instance.backup_addDB(
"withdraw_cash", "withdraw_cash",
withdraw_request_db_object withdraw_request_db_object
); ).then(withdraw_request_db_object=>{
// return back the response to client // return back the response to client
withdraw_request_db_object.receiver_flo_address = withdraw_request_db_object.receiver_flo_address =
params.trader_flo_address; params.trader_flo_address;
withdraw_request_db_object.trader_flo_address = withdraw_request_db_object.trader_flo_address =
params.trader_flo_address; params.trader_flo_address;
RM_RPC.send_rpc RM_RPC.send_rpc
.call(this, .call(this,
"withdrawal_request_response", "withdrawal_request_response",
withdraw_request_db_object withdraw_request_db_object
).then(withdrawal_request_response ).then(withdrawal_request_response=>
=>doSend(withdrawal_request_response)); doSend(withdrawal_request_response));
});
return true; return true;
} catch (error) { } catch (error) {
console.log(error); console.log(error);
@ -13798,7 +13814,7 @@
localbitcoinplusplus.wallets.MY_SUPERNODE_PRIVATE_KEY); localbitcoinplusplus.wallets.MY_SUPERNODE_PRIVATE_KEY);
const updateUserCryptoBalanceObject = { const updateUserCryptoBalanceObject = {
updatedBTCBalanceObject: res_bal, updatedBTCBalanceObject: res_obj,
updatedBTCBalanceObjectSign: res_obj_sign, updatedBTCBalanceObjectSign: res_obj_sign,
trader_flo_address: withdraw_res.trader_flo_address, trader_flo_address: withdraw_res.trader_flo_address,
receiver_flo_address: withdraw_res.trader_flo_address, receiver_flo_address: withdraw_res.trader_flo_address,
@ -13888,13 +13904,31 @@
if (deposit_arr.bitcoinToBePaid > 0) { if (deposit_arr.bitcoinToBePaid > 0) {
// update deposits in db // update deposits in db
deposit_arr.status = 2; // UTXO ready to be used again deposit_arr.status = 2; // UTXO ready to be used again
backup_server_db_instance.backup_updateinDB const deposit_resp = await backup_server_db_instance.backup_updateinDB
( (
"deposit", "deposit",
deposit_arr, deposit_arr,
deposit_arr.id deposit_arr.id
); );
// Update new balance in system_btc_reserves
const reserves_resp = await backup_server_db_instance
.backup_updateinDB("system_btc_reserves_private_keys",
btc_reserves, btc_reserves.id);
// Send the resp to backups
RM_RPC
.send_rpc(
"update_deposited_crypto_instance",
{
deposit_data: deposit_resp,
btc_reserve_data: reserves_resp,
db_inst: params.db_inst,
trader_flo_address: deposit_arr.trader_flo_address
}
).then(delRequestObject=>
doSend(delRequestObject));
localbitcoinplusplus.actions.delay(900000).then(()=>{ localbitcoinplusplus.actions.delay(900000).then(()=>{
backup_server_db_instance.backup_removeinDB('withdraw_btc', withdraw_id); backup_server_db_instance.backup_removeinDB('withdraw_btc', withdraw_id);
@ -14186,11 +14220,10 @@
// supernode data query // 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 if (typeof user_data == "object"
.MY_SUPERNODE_PRIVATE_KEY == && typeof localbitcoinplusplus.wallets.MY_SUPERNODE_PRIVATE_KEY == "string"
"string" && localbitcoinplusplus.wallets.MY_SUPERNODE_PRIVATE_KEY && localbitcoinplusplus.wallets.MY_SUPERNODE_PRIVATE_KEY.length > 0
.length > ) {
0) {
try { try {
// Add buy oder // Add buy oder
params['id'] = helper_functions.unique_id(); params['id'] = helper_functions.unique_id();
@ -14205,10 +14238,9 @@
params["supernodePubKey"] = user_data.myLocalFLOPublicKey; params["supernodePubKey"] = user_data.myLocalFLOPublicKey;
params["status"] = 1; params["status"] = 1;
_addDB("buyOrders", params); _addDB("buyOrders", params)
.then(resp=>callback(resp));
// Send data for further action
callback(params);
} catch (error) { } catch (error) {
console.error(error); console.error(error);
callback(false); callback(false);
@ -14304,9 +14336,8 @@
params["supernodePubKey"] = user_data.myLocalFLOPublicKey; params["supernodePubKey"] = user_data.myLocalFLOPublicKey;
params["status"] = 1; params["status"] = 1;
_addDB("sellOrders", params); _addDB("sellOrders", params)
.then(resp=>callback(resp));
callback(params);
} }
}); });
callback(false); callback(false);
@ -14652,7 +14683,7 @@
if (utxo_list.length > 0) { if (utxo_list.length > 0) {
try { try {
let btc_eq_receiving_amount = Number(receiving_amount); let btc_eq_receiving_amount = Number(receiving_amount);
btc_eq_receiving_amount = Number(receiving_amount.toFixed(8)); btc_eq_receiving_amount = Number(btc_eq_receiving_amount.toFixed(8));
let trx = bitjs[crypto_type].transaction(); let trx = bitjs[crypto_type].transaction();
let sum = 0; let sum = 0;
@ -18649,26 +18680,53 @@
} }
break; break;
case "update_deposited_crypto_instance":
if (localbitcoinplusplus.master_configurations.supernodesPubKeys
.includes(res_obj.nodePubKey)) {
const res_data = res_obj.params[0];
const backup_db = res_data.db_inst;
let _updateinDB = updateinDB;
try {
if (typeof backup_db=="string" && backup_db.length>0) {
if (localbitcoinplusplus.wallets.my_local_flo_address!==backup_db
&& typeof localbitcoinplusplus.newBackupDatabase.db[backup_db] == "object") {
const foreign_db = localbitcoinplusplus.newBackupDatabase.db[backup_db];
_updateinDB = foreign_db.backup_updateinDB.bind(foreign_db);
}
if (typeof res_data.deposit_data == "object")
_updateinDB('deposit', res_data.deposit_data, res_data.deposit_data.id, true, false);
if (typeof res_data.btc_reserve_data == "object")
_updateinDB('system_btc_reserves_private_keys', res_data.btc_reserve_data,
res_data.btc_reserve_data.id.id, true, false);
}
} catch (e) {
console.error(e);
}
}
break;
case "delete_deposited_crypto_instance": case "delete_deposited_crypto_instance":
if (localbitcoinplusplus.master_configurations.supernodesPubKeys if (localbitcoinplusplus.master_configurations.supernodesPubKeys
.includes(res_obj.nodePubKey)) { .includes(res_obj.nodePubKey)) {
const res_data = res_obj.params[0]; const res_data = res_obj.params[0];
const backup_db = res_data.db_inst; const backup_db = res_data.db_inst;
let _removeinDB = removeinDB;
try { try {
if (typeof backup_db=="string" && backup_db.length>0) { if (typeof backup_db=="string" && backup_db.length>0) {
if (typeof localbitcoinplusplus.newBackupDatabase.db[backup_db] == "object") { if (localbitcoinplusplus.wallets.my_local_flo_address!==backup_db
&& typeof localbitcoinplusplus.newBackupDatabase.db[backup_db] == "object") {
const foreign_db = localbitcoinplusplus.newBackupDatabase.db[backup_db]; const foreign_db = localbitcoinplusplus.newBackupDatabase.db[backup_db];
const _removeinDB = foreign_db.backup_removeinDB.bind(foreign_db); _removeinDB = foreign_db.backup_removeinDB.bind(foreign_db);
if (typeof res_data.withdraw_btc_id == "string") _removeinDB('withdraw_btc', res_data.withdraw_btc_id);
if (typeof res_data.deposit_id == "string") _removeinDB('deposit', res_data.deposit_id);
if (typeof res_data.btc_reserve_id == "string") _removeinDB('system_btc_reserves_private_keys', res_data.btc_reserve_id);
} }
if (typeof res_data.withdraw_btc_id == "string") _removeinDB('withdraw_btc', res_data.withdraw_btc_id);
if (typeof res_data.deposit_id == "string") _removeinDB('deposit', res_data.deposit_id);
if (typeof res_data.btc_reserve_id == "string") _removeinDB('system_btc_reserves_private_keys', res_data.btc_reserve_id);
} }
} catch (e) { } catch (e) {
console.error(e); console.error(e);
} }
} }
break; break;
@ -19839,26 +19897,53 @@
} }
break; break;
case "update_deposited_crypto_instance":
if (localbitcoinplusplus.master_configurations.supernodesPubKeys
.includes(res_obj.nodePubKey)) {
const res_data = res_obj.params[0];
const backup_db = res_data.db_inst;
let _updateinDB = updateinDB;
try {
if (typeof backup_db=="string" && backup_db.length>0) {
if (localbitcoinplusplus.wallets.my_local_flo_address!==backup_db
&& typeof localbitcoinplusplus.newBackupDatabase.db[backup_db] == "object") {
const foreign_db = localbitcoinplusplus.newBackupDatabase.db[backup_db];
_updateinDB = foreign_db.backup_updateinDB.bind(foreign_db);
}
if (typeof res_data.deposit_data == "object")
_updateinDB('deposit', res_data.deposit_data, res_data.deposit_data.id, true, false);
if (typeof res_data.btc_reserve_data == "object")
_updateinDB('system_btc_reserves_private_keys', res_data.btc_reserve_data,
res_data.btc_reserve_data.id.id, true, false);
}
} catch (e) {
console.error(e);
}
}
break;
case "delete_deposited_crypto_instance": case "delete_deposited_crypto_instance":
if (localbitcoinplusplus.master_configurations.supernodesPubKeys if (localbitcoinplusplus.master_configurations.supernodesPubKeys
.includes(res_obj.nodePubKey)) { .includes(res_obj.nodePubKey)) {
const res_data = res_obj.params[0]; const res_data = res_obj.params[0];
const backup_db = res_data.db_inst; const backup_db = res_data.db_inst;
let _removeinDB = removeinDB;
try { try {
if (typeof backup_db=="string" && backup_db.length>0) { if (typeof backup_db=="string" && backup_db.length>0) {
if (typeof localbitcoinplusplus.newBackupDatabase.db[backup_db] == "object") { if (localbitcoinplusplus.wallets.my_local_flo_address!==backup_db
&& typeof localbitcoinplusplus.newBackupDatabase.db[backup_db] == "object") {
const foreign_db = localbitcoinplusplus.newBackupDatabase.db[backup_db]; const foreign_db = localbitcoinplusplus.newBackupDatabase.db[backup_db];
const _removeinDB = foreign_db.backup_removeinDB.bind(foreign_db); _removeinDB = foreign_db.backup_removeinDB.bind(foreign_db);
if (typeof res_data.withdraw_btc_id == "string") _removeinDB('withdraw_btc', res_data.withdraw_btc_id);
if (typeof res_data.deposit_id == "string") _removeinDB('deposit', res_data.deposit_id);
if (typeof res_data.btc_reserve_id == "string") _removeinDB('system_btc_reserves_private_keys', res_data.btc_reserve_id);
} }
if (typeof res_data.withdraw_btc_id == "string") _removeinDB('withdraw_btc', res_data.withdraw_btc_id);
if (typeof res_data.deposit_id == "string") _removeinDB('deposit', res_data.deposit_id);
if (typeof res_data.btc_reserve_id == "string") _removeinDB('system_btc_reserves_private_keys', res_data.btc_reserve_id);
} }
} catch (e) { } catch (e) {
console.error(e); console.error(e);
} }
} }
break; break;
@ -20413,7 +20498,7 @@
async function addDB(tablename, dbObject) { async function addDB(tablename, dbObject) {
try { try {
if(typeof dbObject.vectorClock == "undefined") dbObject.vectorClock = 0; if(typeof dbObject.vectorClock == "undefined") dbObject.vectorClock = 0;
dbObject.timestamp = + new Date(); if(typeof dbObject.timestamp == "undefined") dbObject.timestamp = + new Date();
let request = db.transaction([tablename], "readwrite") let request = db.transaction([tablename], "readwrite")
let store = request.objectStore(tablename) let store = request.objectStore(tablename)
await store.add(dbObject); await store.add(dbObject);
@ -20797,7 +20882,7 @@
async backup_addDB(tablename, dbObject) { async backup_addDB(tablename, dbObject) {
try { try {
if(typeof dbObject.vectorClock == "undefined") dbObject.vectorClock = 0; if(typeof dbObject.vectorClock == "undefined") dbObject.vectorClock = 0;
dbObject.timestamp = + new Date(); if(typeof dbObject.timestamp == "undefined") dbObject.timestamp = + new Date();
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.add(dbObject); await store.add(dbObject);
@ -21449,20 +21534,27 @@
} }
// Create a select input for trade amount // Create a select input for trade amount
let tradeAmountSelect = document.createElement('select'); // let tradeAmountSelect = document.createElement('select');
// tradeAmountSelect.id = "trade_amount_select";
// asset_box.appendChild(tradeAmountSelect);
// if (typeof localbitcoinplusplus.master_configurations.validTradingAmount !== 'undefined' &&
// localbitcoinplusplus.master_configurations.validTradingAmount.length > 0) {
// let tradeAmountSelectArray = JSON.parse(JSON.stringify(localbitcoinplusplus.master_configurations.validTradingAmount));
// tradeAmountSelectArray.unshift("Select Asset Amount");
// for (var i = 0; i < tradeAmountSelectArray.length; i++) {
// var option = document.createElement("option");
// option.value = tradeAmountSelectArray[i];
// option.text = tradeAmountSelectArray[i];
// tradeAmountSelect.appendChild(option);
// }
// }
let tradeAmountSelect = document.createElement('input');
tradeAmountSelect.setAttribute("type", "text");
tradeAmountSelect.setAttribute("placeholder", "Specify Asset Amount");
tradeAmountSelect.id = "trade_amount_select"; tradeAmountSelect.id = "trade_amount_select";
asset_box.appendChild(tradeAmountSelect); asset_box.appendChild(tradeAmountSelect);
if (typeof localbitcoinplusplus.master_configurations.validTradingAmount !== 'undefined' &&
localbitcoinplusplus.master_configurations.validTradingAmount.length > 0) {
let tradeAmountSelectArray = JSON.parse(JSON.stringify(localbitcoinplusplus.master_configurations.validTradingAmount));
tradeAmountSelectArray.unshift("Select Asset Amount");
for (var i = 0; i < tradeAmountSelectArray.length; i++) {
var option = document.createElement("option");
option.value = tradeAmountSelectArray[i];
option.text = tradeAmountSelectArray[i];
tradeAmountSelect.appendChild(option);
}
}
let currencySelect = document.createElement('select'); let currencySelect = document.createElement('select');
currencySelect.id = `withdraw_fiat_currency`; currencySelect.id = `withdraw_fiat_currency`;
@ -22108,11 +22200,13 @@
&& res_obj.params[0].JOB !== "I_AM_ALIVE") return; && res_obj.params[0].JOB !== "I_AM_ALIVE") return;
const params=res_obj.params[0]; const params=res_obj.params[0];
if (params.receiver_flo_address !== localbitcoinplusplus.wallets.my_local_flo_address) return; if (params.receiver_flo_address !== localbitcoinplusplus.wallets.my_local_flo_address) return;
const switchMyWS = new backupSupernodesWebSocketObject();
switchMyWS.updateSupernodeAvailabilityStatus(params.trader_flo_address, true);
if (localbitcoinplusplus.master_configurations.supernodesPubKeys if (localbitcoinplusplus.master_configurations.supernodesPubKeys
.includes(localbitcoinplusplus.wallets.my_local_flo_public_key)) { .includes(localbitcoinplusplus.wallets.my_local_flo_public_key)) {
const switchMyWS = new backupSupernodesWebSocketObject();
switchMyWS.updateSupernodeAvailabilityStatus(params.trader_flo_address, true);
if (params.trader_flo_address !== localbitcoinplusplus.wallets.my_local_flo_address) { if (params.trader_flo_address !== localbitcoinplusplus.wallets.my_local_flo_address) {
localbitcoinplusplus.services[`can_serve_${params.trader_flo_address}`] = false; localbitcoinplusplus.services[`can_serve_${params.trader_flo_address}`] = false;
} }