added sendMultipleInputsTransaction, modified retrieve_shamirs_secret_btc_pvtkey
This commit is contained in:
parent
7e19267321
commit
8b16b8cbd9
474
index.html
474
index.html
@ -16686,7 +16686,7 @@
|
|||||||
// Check how much cryptos the user can withdraw
|
// Check how much cryptos the user can withdraw
|
||||||
let withdrawer_btc_id = `${params.trader_flo_address}_${params.product}`;
|
let withdrawer_btc_id = `${params.trader_flo_address}_${params.product}`;
|
||||||
readDB("crypto_balances", withdrawer_btc_id).then(
|
readDB("crypto_balances", withdrawer_btc_id).then(
|
||||||
function(btc_balance_res) {
|
async function(btc_balance_res) {
|
||||||
if (
|
if (
|
||||||
typeof btc_balance_res == "object" &&
|
typeof btc_balance_res == "object" &&
|
||||||
typeof btc_balance_res.trader_flo_address ==
|
typeof btc_balance_res.trader_flo_address ==
|
||||||
@ -16707,17 +16707,11 @@
|
|||||||
) {
|
) {
|
||||||
// Now details of Bitcoins can be sent to withdrawer
|
// Now details of Bitcoins can be sent to withdrawer
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
***********IMPORTANT: CHANGE RECEIVING ADDRESS TO BTC THAN FLO HERE**********
|
|
||||||
***********AND DO SOMETHING ABOUT PRIVATE KEY BELOW**************************
|
|
||||||
****************************************************************************/
|
|
||||||
let sum_total_btc = 0;
|
let sum_total_btc = 0;
|
||||||
let valid_utxo_list = [];
|
let valid_utxo_list = [];
|
||||||
let receiverBTCAddress = params.receivinAddress.trim();
|
let receiverBTCAddress = params.receivinAddress.trim();
|
||||||
|
|
||||||
readAllDB("deposit").then(function(
|
const deposit_list = await readAllDB("deposit");
|
||||||
deposit_list
|
|
||||||
) {
|
|
||||||
if (
|
if (
|
||||||
typeof deposit_list == "object" &&
|
typeof deposit_list == "object" &&
|
||||||
deposit_list.length > 0
|
deposit_list.length > 0
|
||||||
@ -16733,6 +16727,13 @@
|
|||||||
) &&
|
) &&
|
||||||
params.product == deposit_dl.product
|
params.product == deposit_dl.product
|
||||||
)) {
|
)) {
|
||||||
|
// Deposited Bitcoin is under process
|
||||||
|
deposit_dl.status = 3;
|
||||||
|
await updateinDB(
|
||||||
|
"deposit",
|
||||||
|
deposit_dl,
|
||||||
|
deposit_dl.id
|
||||||
|
);
|
||||||
sum_total_btc += helper_functions.truncateDecimals(
|
sum_total_btc += helper_functions.truncateDecimals(
|
||||||
deposit_dl.bitcoinToBePaid
|
deposit_dl.bitcoinToBePaid
|
||||||
);
|
);
|
||||||
@ -16749,13 +16750,6 @@
|
|||||||
let deposited_utxo_addr_list = {};
|
let deposited_utxo_addr_list = {};
|
||||||
let idx = 0;
|
let idx = 0;
|
||||||
for (const deposit_arr of valid_utxo_list) {
|
for (const deposit_arr of valid_utxo_list) {
|
||||||
// Deposited Bitcoin is under process
|
|
||||||
deposit_arr.status = 3;
|
|
||||||
updateinDB(
|
|
||||||
"deposit",
|
|
||||||
deposit_arr,
|
|
||||||
deposit_arr.id
|
|
||||||
);
|
|
||||||
|
|
||||||
if(idx==valid_utxo_list.length-1) {
|
if(idx==valid_utxo_list.length-1) {
|
||||||
deposited_utxo_addr_list[idx]=deposit_arr.btc_address;
|
deposited_utxo_addr_list[idx]=deposit_arr.btc_address;
|
||||||
@ -16776,7 +16770,7 @@
|
|||||||
timestamp: +new Date()
|
timestamp: +new Date()
|
||||||
};
|
};
|
||||||
|
|
||||||
addDB("withdraw_btc", withdraw_btc_order_object);
|
await addDB("withdraw_btc", withdraw_btc_order_object);
|
||||||
|
|
||||||
// Delete the withdraw crypto order after 30 mins anyway
|
// Delete the withdraw crypto order after 30 mins anyway
|
||||||
let withdraw_order_life = JSON.parse(localbitcoinplusplus.master_configurations.ordersLife);
|
let withdraw_order_life = JSON.parse(localbitcoinplusplus.master_configurations.ordersLife);
|
||||||
@ -16798,7 +16792,9 @@
|
|||||||
await updateinDB(
|
await updateinDB(
|
||||||
"deposit",
|
"deposit",
|
||||||
deposit_arr,
|
deposit_arr,
|
||||||
deposit_arr.id
|
deposit_arr.id,
|
||||||
|
false,
|
||||||
|
false
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -16830,7 +16826,7 @@
|
|||||||
idx++;
|
idx++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
err_msg = `Withdrawal request failed: You are trying to withdraw more ${params.product} than you have.`;
|
err_msg = `Withdrawal request failed: You are trying to withdraw more ${params.product} than you have.`;
|
||||||
err_response = {
|
err_response = {
|
||||||
@ -17187,11 +17183,11 @@
|
|||||||
RM_RPC.filter_legit_requests(
|
RM_RPC.filter_legit_requests(
|
||||||
params.trader_flo_address,
|
params.trader_flo_address,
|
||||||
async function (is_valid_request) {
|
async function (is_valid_request) {
|
||||||
|
try {
|
||||||
if (is_valid_request !== true) return false;
|
if (is_valid_request !== true) return false;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
typeof params.btc_private_key_array !== "object" ||
|
typeof params.btc_private_key_array !== "object"
|
||||||
typeof params.retrieve_pvtkey_req_id !== "object"
|
|
||||||
)
|
)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -17212,23 +17208,13 @@
|
|||||||
localbitcoinplusplus.wallets.my_local_flo_address
|
localbitcoinplusplus.wallets.my_local_flo_address
|
||||||
) return;
|
) return;
|
||||||
|
|
||||||
let retrieve_pvtkey_req_id = params.retrieve_pvtkey_req_id;
|
const withdraw_id = params.withdraw_id;
|
||||||
let withdraw_id = params.withdraw_id;
|
|
||||||
|
|
||||||
try {
|
|
||||||
// let btc_private_key_object = params.btc_private_key_array;
|
|
||||||
// let btc_pk_shares_array = btc_private_key_object
|
|
||||||
// .map(pkChunks => {
|
|
||||||
// if (typeof pkChunks.private_key_chunk !== "undefined")
|
|
||||||
// return pkChunks.private_key_chunk.privateKeyChunks;
|
|
||||||
// })
|
|
||||||
// .filter(val => val !== undefined);
|
|
||||||
// console.log(btc_pk_shares_array);
|
|
||||||
|
|
||||||
const withdraw_res = await readDB("withdraw_btc", withdraw_id);
|
const withdraw_res = await readDB("withdraw_btc", withdraw_id);
|
||||||
if (typeof withdraw_res == "object") {
|
if (typeof withdraw_res == "object") {
|
||||||
const withdrawer_crypto_bal_id = `${withdraw_res.trader_flo_address}_${withdraw_res.product}`;
|
const withdrawer_crypto_bal_id = `${withdraw_res.trader_flo_address}_${withdraw_res.product}`;
|
||||||
const withdrawer_crypto_bal_response = await readDB("crypto_balances", withdrawer_crypto_bal_id);
|
const withdrawer_crypto_bal_response = await readDB("crypto_balances", withdrawer_crypto_bal_id);
|
||||||
|
const withdrawer_crypto_bal_response_before_update = JSON.parse(JSON.stringify(withdrawer_crypto_bal_response));
|
||||||
|
|
||||||
if (typeof withdrawer_crypto_bal_response !== "object"
|
if (typeof withdrawer_crypto_bal_response !== "object"
|
||||||
|| typeof withdrawer_crypto_bal_response.crypto_balance !== "number") {
|
|| typeof withdrawer_crypto_bal_response.crypto_balance !== "number") {
|
||||||
@ -17276,36 +17262,30 @@
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const bal_url = `${explorer}/api/addr/${withdraw_res.utxo_addr}/balance`;
|
|
||||||
console.log(bal_url);
|
|
||||||
|
|
||||||
// Get the balance before sending the tx. It is important to get balance before
|
// Get the balance before sending the tx. It is important to get balance before
|
||||||
// tx than to after because fetching balance after can return older or newer balance
|
// tx than to after because fetching balance after can return older or newer balance
|
||||||
// on random events
|
// on random events
|
||||||
let current_balance = await helper_functions.ajaxGet(bal_url);
|
let current_utxos_balance = 0;
|
||||||
|
const RM_WALLET = new localbitcoinplusplus.wallets;
|
||||||
|
let total_balance_promises = [];
|
||||||
|
for (const utxo_pk of params.btc_private_key_array) {
|
||||||
|
let utxo_addr = RM_WALLET.generateFloKeys(utxo_pk, withdraw_res.product).address;
|
||||||
|
const bal_url = `${explorer}/api/addr/${utxo_addr}/balance`;
|
||||||
|
total_balance_promises.push(helper_functions.ajaxGet(bal_url));
|
||||||
|
}
|
||||||
|
let total_balance_promises_resp = await Promise.all(total_balance_promises);
|
||||||
|
current_utxos_balance = total_balance_promises_resp.reduce((acc, c) => acc + c, 0);
|
||||||
|
console.log(current_utxos_balance);
|
||||||
|
|
||||||
if(typeof current_balance !== "number" || current_balance<=0) {
|
if (typeof current_utxos_balance !== "number" || current_utxos_balance <= 0) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"Failed to determine utxo balance of address "+withdraw_res.utxo_addr
|
"Failed to determine utxo balance of deposits in withdraw_id " + withdraw_res.id
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const btc_reserves = await readDB("system_btc_reserves_private_keys", retrieve_pvtkey_req_id);
|
const totalWithdrawingAmount = helper_functions.truncateDecimals(withdraw_res.receivingBTC);
|
||||||
if (typeof btc_reserves == "object") {
|
|
||||||
// Ideally this line should never run.
|
|
||||||
if (btc_reserves.product !== withdraw_res.product)
|
|
||||||
throw new Error(
|
|
||||||
"Mismatch of assets in withdrawal request."
|
|
||||||
);
|
|
||||||
|
|
||||||
await RM_TRADE.resolve_current_crypto_price_in_fiat(
|
if (totalWithdrawingAmount > withdrawer_crypto_bal_response.crypto_balance) {
|
||||||
withdraw_res.product,
|
|
||||||
withdraw_res.currency
|
|
||||||
);
|
|
||||||
const EqCryptoWd = helper_functions.truncateDecimals(withdraw_res.receivingBTC);
|
|
||||||
//const EqCryptoWd = helper_functions.truncateDecimals(current_balance);
|
|
||||||
|
|
||||||
if (withdraw_res.receivingBTC > withdrawer_crypto_bal_response.crypto_balance) {
|
|
||||||
err_response = {
|
err_response = {
|
||||||
user_flo_addr: params.trader_flo_address,
|
user_flo_addr: params.trader_flo_address,
|
||||||
msg: `You are withdrawing ${withdraw_res.product} more than your balance.`
|
msg: `You are withdrawing ${withdraw_res.product} more than your balance.`
|
||||||
@ -17314,34 +17294,36 @@
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
let transaction_key = localbitcoinplusplus.actions
|
if (totalWithdrawingAmount > current_utxos_balance) {
|
||||||
.master_decrypt(btc_reserves.supernode_transaction_key);
|
err_response = {
|
||||||
if(typeof transaction_key=="string") {
|
user_flo_addr: params.trader_flo_address,
|
||||||
transaction_key = JSON.parse(transaction_key);
|
msg: `${withdraw_res.product} Withdrawal request failed: System does not have sufficient balance.
|
||||||
|
Please try later.`
|
||||||
}
|
}
|
||||||
if (transaction_key.length > 0) {
|
reactor.dispatchEvent('message_for_user', err_response);
|
||||||
let btc_private_key = RM_WALLET.rebuild_private_key(
|
return false;
|
||||||
btc_pk_shares_array,
|
}
|
||||||
transaction_key
|
|
||||||
|
// Deduct balance before sending crypto
|
||||||
|
withdrawer_crypto_bal_response.crypto_balance -= totalWithdrawingAmount;
|
||||||
|
withdrawer_crypto_bal_response.crypto_balance =
|
||||||
|
helper_functions.truncateDecimals(withdrawer_crypto_bal_response.crypto_balance);
|
||||||
|
const updated_crypto_balance = await updateinDB(
|
||||||
|
"crypto_balances",
|
||||||
|
withdrawer_crypto_bal_response,
|
||||||
|
withdrawer_crypto_bal_id
|
||||||
);
|
);
|
||||||
console.log(btc_private_key);
|
|
||||||
|
|
||||||
let withdrawingAmountInThisTx = helper_functions.truncateDecimals(withdraw_res.receivingBTC);
|
RM_TRADE.sendMultipleInputsTransaction(
|
||||||
if(withdraw_res.receivingBTC>current_balance) {
|
|
||||||
withdrawingAmountInThisTx = current_balance;
|
|
||||||
}
|
|
||||||
|
|
||||||
RM_TRADE.sendTransaction(
|
|
||||||
withdraw_res.product,
|
withdraw_res.product,
|
||||||
withdraw_res.utxo_addr,
|
params.btc_private_key_array,
|
||||||
btc_private_key,
|
|
||||||
withdraw_res.receiverBTCAddress,
|
withdraw_res.receiverBTCAddress,
|
||||||
withdrawingAmountInThisTx,
|
totalWithdrawingAmount,
|
||||||
withdraw_res.change_adress,
|
withdraw_res.change_adress,
|
||||||
async function (res) {
|
async function (res) {
|
||||||
console.log(res);
|
console.log(res);
|
||||||
if (typeof res == "object") {
|
|
||||||
try {
|
try {
|
||||||
|
if (typeof res == "object") {
|
||||||
let msg = "";
|
let msg = "";
|
||||||
if (
|
if (
|
||||||
typeof res.txid == "string" &&
|
typeof res.txid == "string" &&
|
||||||
@ -17364,14 +17346,6 @@
|
|||||||
doSend(server_response)
|
doSend(server_response)
|
||||||
);
|
);
|
||||||
|
|
||||||
withdrawer_crypto_bal_response.crypto_balance -= EqCryptoWd;
|
|
||||||
withdrawer_crypto_bal_response.crypto_balance =
|
|
||||||
helper_functions.truncateDecimals(withdrawer_crypto_bal_response.crypto_balance);
|
|
||||||
const updated_crypto_balance = await updateinDB(
|
|
||||||
"crypto_balances",
|
|
||||||
withdrawer_crypto_bal_response,
|
|
||||||
withdrawer_crypto_bal_id
|
|
||||||
);
|
|
||||||
const res_obj_str = JSON.stringify(updated_crypto_balance);
|
const res_obj_str = JSON.stringify(updated_crypto_balance);
|
||||||
const res_obj_hash = Crypto.SHA256(res_obj_str);
|
const res_obj_hash = Crypto.SHA256(res_obj_str);
|
||||||
const res_obj_sign = RM_WALLET.sign(
|
const res_obj_sign = RM_WALLET.sign(
|
||||||
@ -17400,38 +17374,34 @@
|
|||||||
*******************CHECK ACTUAL BTC BALANCE HERE THROUGH AN API AND UPDATE DEPOSIT TABLE****************************************************
|
*******************CHECK ACTUAL BTC BALANCE HERE THROUGH AN API AND UPDATE DEPOSIT TABLE****************************************************
|
||||||
************************************************************************************************************************************/
|
************************************************************************************************************************************/
|
||||||
|
|
||||||
|
for (const deposited_utxo_idx in withdraw_res.utxo_addr) {
|
||||||
|
let deposited_utxo_addr = withdraw_res.utxo_addr[deposited_utxo_idx];
|
||||||
|
|
||||||
const deposit_arr_resp = await readDBbyIndex(
|
const deposit_arr_resp = await readDBbyIndex(
|
||||||
"deposit",
|
"deposit",
|
||||||
"btc_address",
|
"btc_address",
|
||||||
withdraw_res.utxo_addr
|
deposited_utxo_addr
|
||||||
);
|
);
|
||||||
if (typeof deposit_arr_resp[0] == "object") {
|
if (typeof deposit_arr_resp[0] == "object") {
|
||||||
const deposit_arr = deposit_arr_resp[0];
|
const deposit_arr = deposit_arr_resp[0];
|
||||||
if (
|
if (
|
||||||
!isNaN(current_balance) &&
|
!isNaN(current_utxos_balance) &&
|
||||||
parseFloat(current_balance) > 0
|
parseFloat(current_utxos_balance) > 0
|
||||||
) {
|
) {
|
||||||
current_balance = helper_functions.truncateDecimals(
|
current_utxos_balance = helper_functions.truncateDecimals(
|
||||||
current_balance / decimal
|
current_utxos_balance / decimal
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
typeof current_balance == "number"
|
typeof current_utxos_balance == "number"
|
||||||
) {
|
) {
|
||||||
deposit_arr.bitcoinToBePaid = current_balance-EqCryptoWd;
|
deposit_arr.bitcoinToBePaid = current_utxos_balance - totalWithdrawingAmount;
|
||||||
btc_reserves.balance = current_balance-EqCryptoWd;
|
|
||||||
} else {
|
} else {
|
||||||
deposit_arr.bitcoinToBePaid -= EqCryptoWd;
|
throw new Error('current_utxos_balance is not a number');
|
||||||
btc_reserves.balance -= EqCryptoWd;
|
|
||||||
// Tx is not registered in Blocckhain yet. Refresh balance after 30 minutes
|
|
||||||
localbitcoinplusplus.actions.delay(1800000).then(() =>
|
|
||||||
reactor.dispatchEvent("refresh_reserved_crypto_balances", params.trader_flo_address)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
deposit_arr.bitcoinToBePaid = helper_functions.truncateDecimals(deposit_arr.bitcoinToBePaid);
|
deposit_arr.bitcoinToBePaid = helper_functions.truncateDecimals(deposit_arr.bitcoinToBePaid);
|
||||||
btc_reserves.balance = helper_functions.truncateDecimals(btc_reserves.balance);
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
deposit_arr.bitcoinToBePaid > 0
|
deposit_arr.bitcoinToBePaid > 0
|
||||||
@ -17443,19 +17413,12 @@
|
|||||||
deposit_arr,
|
deposit_arr,
|
||||||
deposit_arr.id
|
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
|
// Send the resp to backups
|
||||||
RM_RPC.send_rpc(
|
RM_RPC.send_rpc(
|
||||||
"update_deposited_crypto_instance",
|
"update_deposited_crypto_instance",
|
||||||
{
|
{
|
||||||
deposit_data: deposit_resp,
|
deposit_data: deposit_resp,
|
||||||
btc_reserve_data: reserves_resp,
|
|
||||||
db_inst: params.db_inst,
|
db_inst: params.db_inst,
|
||||||
trader_flo_address:
|
trader_flo_address:
|
||||||
deposit_arr.trader_flo_address
|
deposit_arr.trader_flo_address
|
||||||
@ -17464,9 +17427,6 @@
|
|||||||
doSend(delRequestObject)
|
doSend(delRequestObject)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Do not delete these data instantly as the data
|
|
||||||
// may be required by a follow-up withdraw request
|
|
||||||
await localbitcoinplusplus.actions.delay(180000)
|
|
||||||
await removeinDB("withdraw_btc", withdraw_id);
|
await removeinDB("withdraw_btc", withdraw_id);
|
||||||
|
|
||||||
RM_RPC.send_rpc(
|
RM_RPC.send_rpc(
|
||||||
@ -17483,22 +17443,16 @@
|
|||||||
|
|
||||||
// AND DO THE SAME ABOVE 2 IN BACKUP RECEIVE RPC
|
// AND DO THE SAME ABOVE 2 IN BACKUP RECEIVE RPC
|
||||||
} else {
|
} else {
|
||||||
// Do not delete these data instantly as the data
|
|
||||||
// may be required by a follow-up withdraw request
|
|
||||||
await localbitcoinplusplus.actions.delay(180000);
|
|
||||||
|
|
||||||
let p1 = removeinDB("deposit", deposit_arr.id);
|
let p1 = removeinDB("deposit", deposit_arr.id);
|
||||||
let p2 = removeinDB("system_btc_reserves_private_keys", retrieve_pvtkey_req_id);
|
let p2 = removeinDB("withdraw_btc", withdraw_id);
|
||||||
let p3 = removeinDB("withdraw_btc", withdraw_id);
|
|
||||||
|
|
||||||
await Promise.all([p1, p2, p3]);
|
await Promise.all([p1, p2]);
|
||||||
|
|
||||||
RM_RPC.send_rpc(
|
RM_RPC.send_rpc(
|
||||||
"delete_deposited_crypto_instance",
|
"delete_deposited_crypto_instance",
|
||||||
{
|
{
|
||||||
deposit_id:
|
deposit_id: deposit_arr.id,
|
||||||
deposit_arr.id,
|
|
||||||
btc_reserve_id: retrieve_pvtkey_req_id,
|
|
||||||
withdraw_btc_id: withdraw_id,
|
withdraw_btc_id: withdraw_id,
|
||||||
db_inst: params.db_inst,
|
db_inst: params.db_inst,
|
||||||
trader_flo_address:
|
trader_flo_address:
|
||||||
@ -17512,11 +17466,15 @@
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
console.log(res);
|
console.log(res);
|
||||||
throw new Errror(`ERROR: Failed to make transaction.`);
|
throw new Errror(`ERROR: Failed to make transaction.`);
|
||||||
return false;
|
}
|
||||||
|
} else {
|
||||||
|
console.error("Waithdraw transaction is not an object");
|
||||||
|
//throw new Errror(`ERROR: Failed to make transaction.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -17526,15 +17484,14 @@
|
|||||||
msg: `Withdraw of crypto failed. Network issue:- Please try again after 30 minutes.`
|
msg: `Withdraw of crypto failed. Network issue:- Please try again after 30 minutes.`
|
||||||
}
|
}
|
||||||
reactor.dispatchEvent('message_for_user', err_response);
|
reactor.dispatchEvent('message_for_user', err_response);
|
||||||
// Do not delete these data instantly as the data
|
|
||||||
// may be required by a follow-up withdraw request
|
|
||||||
await localbitcoinplusplus.actions.delay(180000);
|
|
||||||
|
|
||||||
// update deposits status back to 2 in db
|
// update deposits status back to 2 in db
|
||||||
|
for (const deposited_utxo_idx in withdraw_res.utxo_addr) {
|
||||||
|
let deposited_utxo_addr = withdraw_res.utxo_addr[deposited_utxo_idx];
|
||||||
const deposit_arr_resp = await readDBbyIndex(
|
const deposit_arr_resp = await readDBbyIndex(
|
||||||
"deposit",
|
"deposit",
|
||||||
"btc_address",
|
"btc_address",
|
||||||
withdraw_res.utxo_addr
|
deposited_utxo_addr
|
||||||
)
|
)
|
||||||
if (typeof deposit_arr_resp[0] == "object") {
|
if (typeof deposit_arr_resp[0] == "object") {
|
||||||
deposit_arr_resp[0].status = 2; // UTXO ready to be used again
|
deposit_arr_resp[0].status = 2; // UTXO ready to be used again
|
||||||
@ -17544,35 +17501,43 @@
|
|||||||
deposit_arr_resp[0].id
|
deposit_arr_resp[0].id
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
await removeinDB("withdraw_btc", withdraw_id);
|
await removeinDB("withdraw_btc", withdraw_id);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
||||||
const withdraw_res = await readDB("withdraw_btc", withdraw_id);
|
const withdraw_res = await readDB("withdraw_btc", params.withdraw_id);
|
||||||
|
for (const deposited_utxo_idx in withdraw_res.utxo_addr) {
|
||||||
|
let deposited_utxo_addr = withdraw_res.utxo_addr[deposited_utxo_idx];
|
||||||
// update deposits status back to 2 in db
|
// update deposits status back to 2 in db
|
||||||
const deposit_arr_resp = await readDBbyIndex(
|
const deposit_arr_resp = await readDBbyIndex(
|
||||||
"deposit",
|
"deposit",
|
||||||
"btc_address",
|
"btc_address",
|
||||||
withdraw_res.utxo_addr
|
deposited_utxo_addr
|
||||||
)
|
)
|
||||||
if (typeof deposit_arr_resp[0] == "object") {
|
if (typeof deposit_arr_resp[0] == "object") {
|
||||||
deposit_arr_resp[0].status = 2; // UTXO ready to be used again
|
deposit_arr_resp[0].status = 2; // UTXO ready to be used again
|
||||||
await updateinDB(
|
updateinDB(
|
||||||
"deposit",
|
"deposit",
|
||||||
deposit_arr_resp[0],
|
deposit_arr_resp[0],
|
||||||
deposit_arr_resp[0].id
|
deposit_arr_resp[0].id
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
await removeinDB("withdraw_btc", withdraw_id);
|
}
|
||||||
|
removeinDB("withdraw_btc", params.withdraw_id);
|
||||||
|
// Revert user balance
|
||||||
|
updateinDB("crypto_balances",
|
||||||
|
withdrawer_crypto_bal_response_before_update,
|
||||||
|
withdrawer_crypto_bal_response_before_update.id,
|
||||||
|
false,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
throw new Error(error);
|
throw new Error(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -18501,7 +18466,7 @@
|
|||||||
const withdrawer_btc_id = `${params.trader_flo_address}_${params.product}`;
|
const withdrawer_btc_id = `${params.trader_flo_address}_${params.product}`;
|
||||||
backup_server_db_instance
|
backup_server_db_instance
|
||||||
.backup_readDB("crypto_balances", withdrawer_btc_id)
|
.backup_readDB("crypto_balances", withdrawer_btc_id)
|
||||||
.then(function(btc_balance_res) {
|
.then(async function(btc_balance_res) {
|
||||||
if (
|
if (
|
||||||
typeof btc_balance_res == "object" &&
|
typeof btc_balance_res == "object" &&
|
||||||
typeof btc_balance_res.trader_flo_address ==
|
typeof btc_balance_res.trader_flo_address ==
|
||||||
@ -18522,11 +18487,6 @@
|
|||||||
eqBTC <= withdrawer_btc_balance
|
eqBTC <= withdrawer_btc_balance
|
||||||
) {
|
) {
|
||||||
// Now details of Bitcoins can be sent to withdrawer
|
// Now details of Bitcoins can be sent to withdrawer
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
***********IMPORTANT: CHANGE RECEIVING ADDRESS TO BTC THAN FLO HERE**********
|
|
||||||
***********AND DO SOMETHING ABOUT PRIVATE KEY BELOW**************************
|
|
||||||
****************************************************************************/
|
|
||||||
let sum_total_btc = 0;
|
let sum_total_btc = 0;
|
||||||
let valid_utxo_list = [];
|
let valid_utxo_list = [];
|
||||||
let receiverBTCAddress = params.receivinAddress.trim();
|
let receiverBTCAddress = params.receivinAddress.trim();
|
||||||
@ -20862,6 +20822,170 @@
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Send transaction for multiple inputs and outputs
|
||||||
|
sendMultipleInputsTransaction(
|
||||||
|
crypto_type,
|
||||||
|
utxo_addr_wif,
|
||||||
|
receiver_address,
|
||||||
|
receiving_amount,
|
||||||
|
change_adress,
|
||||||
|
callback,
|
||||||
|
custom_floData = ""
|
||||||
|
) {
|
||||||
|
let blockchain_explorer;
|
||||||
|
let miners_fee = 0.0003;
|
||||||
|
const miner_fee_obj = JSON.parse(
|
||||||
|
localbitcoinplusplus.master_configurations.miners_fee
|
||||||
|
);
|
||||||
|
if (crypto_type == "BTC") {
|
||||||
|
blockchain_explorer = localbitcoinplusplus.server.btc_mainnet;
|
||||||
|
miners_fee = miner_fee_obj.btc;
|
||||||
|
} else if (crypto_type == "BTC_TEST") {
|
||||||
|
blockchain_explorer = localbitcoinplusplus.server.btc_testnet;
|
||||||
|
miners_fee = miner_fee_obj.btc;
|
||||||
|
} else if (crypto_type == "FLO") {
|
||||||
|
blockchain_explorer = localbitcoinplusplus.server.flo_mainnet;
|
||||||
|
miners_fee = miner_fee_obj.flo;
|
||||||
|
} else if (crypto_type == "FLO_TEST") {
|
||||||
|
blockchain_explorer = localbitcoinplusplus.server.flo_testnet;
|
||||||
|
miners_fee = miner_fee_obj.flo;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof blockchain_explorer !== "string") {
|
||||||
|
showMessage(
|
||||||
|
`WARNING: Please select cryptocurrency/fiat value from select bar.`
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
let err_msg;
|
||||||
|
let utxo_list_req = [];
|
||||||
|
const RM_WALLET = new localbitcoinplusplus.wallets;
|
||||||
|
|
||||||
|
for (const pk of utxo_addr_wif) {
|
||||||
|
let keygen = RM_WALLET.generateFloKeys(pk);
|
||||||
|
let utxo_addr = keygen.address;
|
||||||
|
let url = `${blockchain_explorer}/api/addr/${utxo_addr}/utxo`;
|
||||||
|
utxo_list_req.push(helper_functions.ajaxGet(url));
|
||||||
|
}
|
||||||
|
|
||||||
|
Promise.all(utxo_list_req).then(all_utxos => {
|
||||||
|
if (all_utxos.length > 0) {
|
||||||
|
try {
|
||||||
|
const utxo_list = [].concat(...all_utxos);
|
||||||
|
utxo_list.sort((a, b) => b.confirmations - a.confirmations);
|
||||||
|
let btc_eq_receiving_amount = helper_functions.truncateDecimals(receiving_amount);
|
||||||
|
|
||||||
|
let trx = bitjs[crypto_type].transaction();
|
||||||
|
let sum = 0;
|
||||||
|
|
||||||
|
for (var key in utxo_list) {
|
||||||
|
if (utxo_list[key].confirmations > 0) {
|
||||||
|
var obj = utxo_list[key];
|
||||||
|
sum += helper_functions.truncateDecimals(obj.amount);
|
||||||
|
// let signing_private_keys_array = [];
|
||||||
|
// Find the private key of this utxo (signingPk)
|
||||||
|
// Then signing_private_keys_array.push(signingPk)
|
||||||
|
// trx.sign(signing_private_keys_array, 1)
|
||||||
|
|
||||||
|
if (btc_eq_receiving_amount <= sum) {
|
||||||
|
trx.addinput(obj.txid, obj.vout, obj.scriptPubKey);
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
trx.addinput(obj.txid, obj.vout, obj.scriptPubKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sum <= 0) {
|
||||||
|
console.log(utxo_list);
|
||||||
|
throw new Error("ERROR: No amount found in UTXO.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Output cannot be greater than input
|
||||||
|
if (sum < btc_eq_receiving_amount) {
|
||||||
|
btc_eq_receiving_amount = sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (btc_eq_receiving_amount - miners_fee <= 0)
|
||||||
|
throw new Error(
|
||||||
|
`Error: btc_eq_receiving_amount cannot be less than miners_fee.`
|
||||||
|
);
|
||||||
|
|
||||||
|
btc_eq_receiving_amount =
|
||||||
|
btc_eq_receiving_amount - miners_fee;
|
||||||
|
btc_eq_receiving_amount = helper_functions.truncateDecimals(
|
||||||
|
btc_eq_receiving_amount
|
||||||
|
);
|
||||||
|
trx.addoutput(receiver_address, btc_eq_receiving_amount);
|
||||||
|
|
||||||
|
let change_amount = 0;
|
||||||
|
if (sum - btc_eq_receiving_amount - miners_fee > 0) {
|
||||||
|
change_amount = sum - btc_eq_receiving_amount - miners_fee;
|
||||||
|
change_amount = helper_functions.truncateDecimals(change_amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (change_amount > 0) {
|
||||||
|
trx.addoutput(change_adress, change_amount);
|
||||||
|
}
|
||||||
|
var sendFloData = `localbitcoinpluslus tx: Send ${btc_eq_receiving_amount} ${crypto_type} to ${receiver_address}.`; //flochange adding place for flodata -- need a validation of 1024 chars
|
||||||
|
if (custom_floData.length > 0) {
|
||||||
|
sendFloData = custom_floData;
|
||||||
|
}
|
||||||
|
if (crypto_type == "FLO" || crypto_type == "FLO_TEST") {
|
||||||
|
trx.addflodata(sendFloData); // flochange .. create this function
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
console.log(trx);
|
||||||
|
|
||||||
|
let signedTxHash = trx.sign(utxo_addr_wif, 1); //SIGHASH_ALL DEFAULT 1
|
||||||
|
console.log(signedTxHash);
|
||||||
|
|
||||||
|
var http = new XMLHttpRequest();
|
||||||
|
var tx_send_url = `${blockchain_explorer}/api/tx/send`;
|
||||||
|
var params = `{"rawtx":"${signedTxHash}"}`;
|
||||||
|
http.open("POST", tx_send_url, true);
|
||||||
|
http.setRequestHeader("Content-type", "application/json");
|
||||||
|
http.onreadystatechange = function () {
|
||||||
|
//Call a function when the state changes.
|
||||||
|
if (http.readyState == 4) {
|
||||||
|
if (http.status == 200) {
|
||||||
|
console.log(http.responseText);
|
||||||
|
let response_obj = {
|
||||||
|
signedTxHash: signedTxHash,
|
||||||
|
txid: http.responseText
|
||||||
|
};
|
||||||
|
//callback(http.responseText);
|
||||||
|
callback(response_obj);
|
||||||
|
} else {
|
||||||
|
let response_obj = {
|
||||||
|
signedTxHash: signedTxHash,
|
||||||
|
txid: ""
|
||||||
|
};
|
||||||
|
callback(response_obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
http.onerror = function () {
|
||||||
|
let response_obj = {
|
||||||
|
signedTxHash: signedTxHash,
|
||||||
|
txid: ""
|
||||||
|
};
|
||||||
|
callback(response_obj);
|
||||||
|
};
|
||||||
|
http.send(params);
|
||||||
|
} catch (error) {
|
||||||
|
showMessage(error);
|
||||||
|
throw new Error(error);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
throw new Error(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
/*Finds the best buy sell id match for a trade*/
|
/*Finds the best buy sell id match for a trade*/
|
||||||
createTradePipes(trading_currency = "USD", backup_db = "") {
|
createTradePipes(trading_currency = "USD", backup_db = "") {
|
||||||
let _readAllDB = readAllDB;
|
let _readAllDB = readAllDB;
|
||||||
@ -23080,7 +23204,15 @@
|
|||||||
if (
|
if (
|
||||||
typeof btc_pvt_arr[retrieve_pvtkey_req_id] == "undefined"
|
typeof btc_pvt_arr[retrieve_pvtkey_req_id] == "undefined"
|
||||||
)
|
)
|
||||||
|
{
|
||||||
btc_pvt_arr[retrieve_pvtkey_req_id] = [];
|
btc_pvt_arr[retrieve_pvtkey_req_id] = [];
|
||||||
|
localbitcoinplusplus.actions.delay(15*60*1000)
|
||||||
|
.then(()=>{
|
||||||
|
if(typeof btc_pvt_arr[retrieve_pvtkey_req_id]=="object") {
|
||||||
|
btc_pvt_arr[retrieve_pvtkey_req_id] = null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Filter function below logic source -
|
// Filter function below logic source -
|
||||||
// https://stackoverflow.com/a/9229821/5348972
|
// https://stackoverflow.com/a/9229821/5348972
|
||||||
@ -23163,31 +23295,23 @@
|
|||||||
if(typeof localbitcoinplusplus.btc_private_key_array[withdraw_id] !== "object"
|
if(typeof localbitcoinplusplus.btc_private_key_array[withdraw_id] !== "object"
|
||||||
|| localbitcoinplusplus.btc_private_key_array[withdraw_id]==null) {
|
|| localbitcoinplusplus.btc_private_key_array[withdraw_id]==null) {
|
||||||
localbitcoinplusplus.btc_private_key_array[withdraw_id] = [];
|
localbitcoinplusplus.btc_private_key_array[withdraw_id] = [];
|
||||||
localbitcoinplusplus.retrieve_pvtkey_req_id[withdraw_id] = [];
|
|
||||||
}
|
}
|
||||||
localbitcoinplusplus.btc_private_key_array[withdraw_id].push(btc_private_key);
|
localbitcoinplusplus.btc_private_key_array[withdraw_id].push(btc_private_key);
|
||||||
localbitcoinplusplus.retrieve_pvtkey_req_id[withdraw_id].push(retrieve_pvtkey_req_id);
|
|
||||||
|
|
||||||
if(localbitcoinplusplus.btc_private_key_array[withdraw_id].length
|
if(localbitcoinplusplus.btc_private_key_array[withdraw_id].length
|
||||||
===Object.values(withdraw_res.utxo_addr).length) {
|
===Object.values(withdraw_res.utxo_addr).length) {
|
||||||
// When all the private keys are built successfully proceed further
|
// When all the private keys are built successfully proceed further
|
||||||
res_obj.params[0].btc_private_key_array =
|
res_obj.params[0].btc_private_key_array =
|
||||||
localbitcoinplusplus.btc_private_key_array[withdraw_id];
|
localbitcoinplusplus.btc_private_key_array[withdraw_id];
|
||||||
res_obj.params[0].retrieve_pvtkey_req_id =
|
|
||||||
localbitcoinplusplus.retrieve_pvtkey_req_id[withdraw_id];
|
|
||||||
|
|
||||||
res_obj.params[0].trader_flo_address = localbitcoinplusplus.wallets.my_local_flo_address;
|
res_obj.params[0].trader_flo_address = localbitcoinplusplus.wallets.my_local_flo_address;
|
||||||
// RM_RPC.receive_rpc_response.call(
|
RM_RPC.receive_rpc_response.call(
|
||||||
// this,
|
this,
|
||||||
// JSON.stringify(res_obj)
|
JSON.stringify(res_obj)
|
||||||
// );
|
);
|
||||||
console.log("*********************");
|
|
||||||
console.log(res_obj);
|
|
||||||
if(!delete localbitcoinplusplus.btc_private_key_array[withdraw_id]) {
|
if(!delete localbitcoinplusplus.btc_private_key_array[withdraw_id]) {
|
||||||
localbitcoinplusplus.btc_private_key_array[withdraw_id] = null;
|
localbitcoinplusplus.btc_private_key_array[withdraw_id] = null;
|
||||||
delete localbitcoinplusplus.retrieve_pvtkey_req_id[withdraw_id];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -24802,8 +24926,15 @@
|
|||||||
if (typeof btc_pvt_arr !== "object") btc_pvt_arr = [];
|
if (typeof btc_pvt_arr !== "object") btc_pvt_arr = [];
|
||||||
if (
|
if (
|
||||||
typeof btc_pvt_arr[retrieve_pvtkey_req_id] == "undefined"
|
typeof btc_pvt_arr[retrieve_pvtkey_req_id] == "undefined"
|
||||||
)
|
) {
|
||||||
btc_pvt_arr[retrieve_pvtkey_req_id] = [];
|
btc_pvt_arr[retrieve_pvtkey_req_id] = [];
|
||||||
|
localbitcoinplusplus.actions.delay(15*60*1000)
|
||||||
|
.then(()=>{
|
||||||
|
if(typeof btc_pvt_arr[retrieve_pvtkey_req_id]=="object") {
|
||||||
|
btc_pvt_arr[retrieve_pvtkey_req_id] = null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
// Filter function below logic source -
|
// Filter function below logic source -
|
||||||
// https://stackoverflow.com/a/9229821/5348972
|
// https://stackoverflow.com/a/9229821/5348972
|
||||||
let seen_chunk_id_list = [];
|
let seen_chunk_id_list = [];
|
||||||
@ -26632,8 +26763,15 @@
|
|||||||
if (typeof btc_pvt_arr !== "object") btc_pvt_arr = [];
|
if (typeof btc_pvt_arr !== "object") btc_pvt_arr = [];
|
||||||
if (
|
if (
|
||||||
typeof btc_pvt_arr[retrieve_pvtkey_req_id] == "undefined"
|
typeof btc_pvt_arr[retrieve_pvtkey_req_id] == "undefined"
|
||||||
)
|
) {
|
||||||
btc_pvt_arr[retrieve_pvtkey_req_id] = [];
|
btc_pvt_arr[retrieve_pvtkey_req_id] = [];
|
||||||
|
localbitcoinplusplus.actions.delay(15*60*1000)
|
||||||
|
.then(()=>{
|
||||||
|
if(typeof btc_pvt_arr[retrieve_pvtkey_req_id]=="object") {
|
||||||
|
btc_pvt_arr[retrieve_pvtkey_req_id] = null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Filter function below logic source -
|
// Filter function below logic source -
|
||||||
// https://stackoverflow.com/a/9229821/5348972
|
// https://stackoverflow.com/a/9229821/5348972
|
||||||
@ -26739,31 +26877,23 @@
|
|||||||
if(typeof localbitcoinplusplus.btc_private_key_array[withdraw_id] !== "object"
|
if(typeof localbitcoinplusplus.btc_private_key_array[withdraw_id] !== "object"
|
||||||
|| localbitcoinplusplus.btc_private_key_array[withdraw_id]==null) {
|
|| localbitcoinplusplus.btc_private_key_array[withdraw_id]==null) {
|
||||||
localbitcoinplusplus.btc_private_key_array[withdraw_id] = [];
|
localbitcoinplusplus.btc_private_key_array[withdraw_id] = [];
|
||||||
localbitcoinplusplus.retrieve_pvtkey_req_id[withdraw_id] = [];
|
|
||||||
}
|
}
|
||||||
localbitcoinplusplus.btc_private_key_array[withdraw_id].push(btc_private_key);
|
localbitcoinplusplus.btc_private_key_array[withdraw_id].push(btc_private_key);
|
||||||
localbitcoinplusplus.retrieve_pvtkey_req_id[withdraw_id].push(retrieve_pvtkey_req_id);
|
|
||||||
|
|
||||||
if(localbitcoinplusplus.btc_private_key_array[withdraw_id].length
|
if(localbitcoinplusplus.btc_private_key_array[withdraw_id].length
|
||||||
===Object.values(withdraw_res.utxo_addr).length) {
|
===Object.values(withdraw_res.utxo_addr).length) {
|
||||||
// When all the private keys are built successfully proceed further
|
// When all the private keys are built successfully proceed further
|
||||||
res_obj.params[0].btc_private_key_array =
|
res_obj.params[0].btc_private_key_array =
|
||||||
localbitcoinplusplus.btc_private_key_array[withdraw_id];
|
localbitcoinplusplus.btc_private_key_array[withdraw_id];
|
||||||
res_obj.params[0].retrieve_pvtkey_req_id =
|
|
||||||
localbitcoinplusplus.retrieve_pvtkey_req_id[withdraw_id];
|
|
||||||
|
|
||||||
res_obj.params[0].trader_flo_address = localbitcoinplusplus.wallets.my_local_flo_address;
|
res_obj.params[0].trader_flo_address = localbitcoinplusplus.wallets.my_local_flo_address;
|
||||||
// RM_RPC.receive_rpc_response.call(
|
RM_RPC.receive_rpc_response.call(
|
||||||
// this,
|
this,
|
||||||
// JSON.stringify(res_obj)
|
JSON.stringify(res_obj)
|
||||||
// );
|
);
|
||||||
console.log("*********************");
|
|
||||||
console.log(res_obj);
|
|
||||||
console.log(JSON.stringify(res_obj));
|
|
||||||
|
|
||||||
if(!delete localbitcoinplusplus.btc_private_key_array[withdraw_id]) {
|
if(!delete localbitcoinplusplus.btc_private_key_array[withdraw_id]) {
|
||||||
localbitcoinplusplus.btc_private_key_array[withdraw_id] = null;
|
localbitcoinplusplus.btc_private_key_array[withdraw_id] = null;
|
||||||
delete localbitcoinplusplus.retrieve_pvtkey_req_id[withdraw_id];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -28605,6 +28735,19 @@
|
|||||||
throw new Error('Failed verification at db update');
|
throw new Error('Failed verification at db update');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (myRecord.vectorClock == Obj.vectorClock) {
|
||||||
|
if(myRecord.timestamp < Obj.timestamp) {
|
||||||
|
if(!exception_datastores.includes(tablename)) {
|
||||||
|
if(verifyDBData(Obj)===true) {
|
||||||
|
Obj = signDBData(Obj);
|
||||||
|
request = db.transaction([tablename], "readwrite")
|
||||||
|
.objectStore(tablename).put(Obj);
|
||||||
|
} else {
|
||||||
|
console.trace(Obj);
|
||||||
|
throw new Error('Failed verification at db update');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
resolve(Obj);
|
resolve(Obj);
|
||||||
}
|
}
|
||||||
@ -29264,6 +29407,19 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} else if (myRecord.vectorClock == Obj.vectorClock) {
|
||||||
|
if(myRecord.timestamp < Obj.timestamp) {
|
||||||
|
if(!exception_datastores.includes(tablename)) {
|
||||||
|
if(verifyDBData(Obj)===true) {
|
||||||
|
Obj = signDBData(Obj);
|
||||||
|
this.request = this.db.transaction([tablename], "readwrite")
|
||||||
|
.objectStore(tablename).put(Obj);
|
||||||
|
} else {
|
||||||
|
console.trace(Obj);
|
||||||
|
throw new Error('Failed verification at db update');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
resolve(Obj);
|
resolve(Obj);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user