fixed issues in cash deposit algo, added code to let cashier inform supernode withdrawal success
This commit is contained in:
parent
bf9a449c4f
commit
8e93485d97
@ -222,11 +222,11 @@
|
||||
placeholder="Search anything"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-outline-primary"
|
||||
id="fetch_withdraws"
|
||||
type="button"
|
||||
class="btn btn-outline-primary"
|
||||
id="fetch_withdraws"
|
||||
>
|
||||
Load Pending Cash Withdrawals
|
||||
Load Pending Cash Withdrawals
|
||||
</button>
|
||||
|
||||
<table id="withdraws_list" class="myTable">
|
||||
@ -239,8 +239,6 @@
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
|
||||
</main>
|
||||
|
||||
<footer class="footer">
|
||||
@ -12180,10 +12178,10 @@
|
||||
privateKeyDecimal = BigInteger(pk).toString();
|
||||
privateKeyHex = Crypto.util.bytesToHex(pk);
|
||||
return {
|
||||
privateKeyDecimal: privateKeyDecimal,
|
||||
privateKeyHex: privateKeyHex
|
||||
privateKeyDecimal: privateKeyDecimal,
|
||||
privateKeyHex: privateKeyHex
|
||||
};
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
/* CODE_JUNCTION: RPC */
|
||||
@ -13062,7 +13060,7 @@
|
||||
t += `<td> ${m.trader_flo_address} </td>`;
|
||||
t += `<td> ${m.depositing_amount} </td>`;
|
||||
t += `<td> ${m.currency} </td>`;
|
||||
t += `<td> <button type="button" id-"cnf_deposits" value="${m.id}" class="btn btn-info">Deposit Received!</button> </td>`;
|
||||
t += `<td> <button type="button" value="${m.id}" class="btn btn-info cnf_deposits">Deposit Received!</button> </td>`;
|
||||
t += `</tr>`;
|
||||
});
|
||||
deposits_table.insertAdjacentHTML("beforeend", t);
|
||||
@ -13083,7 +13081,8 @@
|
||||
response_from_sever.data.map(m => {
|
||||
const user_upi = localbitcoinplusplus.encrypt.decryptMessage(
|
||||
response_from_sever.data[0].receivinAddress.secret,
|
||||
response_from_sever.data[0].receivinAddress.senderPublicKeyString
|
||||
response_from_sever.data[0].receivinAddress
|
||||
.senderPublicKeyString
|
||||
);
|
||||
t += `<tr>`;
|
||||
t += `<td> ${user_upi} </td>`;
|
||||
@ -13091,6 +13090,7 @@
|
||||
t += `<td> ${m.withdraw_amount} </td>`;
|
||||
t += `<td> ${m.currency} </td>`;
|
||||
t += `<td> ${m.token_transfer_txid} </td>`;
|
||||
t += `<td> <button type="button" value="${m.id}" class="btn btn-info cnf_withdrawal">Money Transferred!</button> </td>`;
|
||||
t += `</tr>`;
|
||||
});
|
||||
withdraws_table.insertAdjacentHTML("beforeend", t);
|
||||
@ -13222,11 +13222,11 @@
|
||||
function showMessage(msg = "", t = 10000) {
|
||||
if (msg.length > 0) LogEvent(msg);
|
||||
console.info(msg);
|
||||
//displayMessages();
|
||||
// setTimeout(function(){
|
||||
// closeMessage();
|
||||
// clearTimeout();
|
||||
// }, t);
|
||||
displayMessages();
|
||||
setTimeout(function() {
|
||||
closeMessage();
|
||||
clearTimeout();
|
||||
}, t);
|
||||
}
|
||||
|
||||
function displayMessages() {
|
||||
@ -13409,36 +13409,75 @@
|
||||
}
|
||||
|
||||
function confirmDepositReceivedFromUser() {
|
||||
const recv_deposit_btn = document.getElementById('cnf_deposits');
|
||||
recv_deposit_btn.addEventListener('click', function(evt) {
|
||||
const recv_deposit_btn = document.getElementsByClassName("cnf_deposits");
|
||||
|
||||
Array.from(recv_deposit_btn).forEach(function(element) {
|
||||
element.addEventListener("click", function(evt) {
|
||||
evt.preventDefault();
|
||||
const deposit_id = this.value;
|
||||
console.log(deposit_id);
|
||||
|
||||
|
||||
const flo_txid = prompt("Enter Deposit Token Transfer Flo Txid: ");
|
||||
if (flo_txid.length < 1) return;
|
||||
|
||||
|
||||
const upi_txid = prompt("Enter Received Cash UPI Txid: ");
|
||||
if (upi_txid.length < 1) return;
|
||||
|
||||
const cash_recvd_from_user = prompt("Enter Amount Received in Cash: ");
|
||||
if (typeof cash_recvd_from_user!=="number" || cash_recvd_from_user < 1) return;
|
||||
|
||||
const cash_recvd_from_user = prompt(
|
||||
"Enter Amount Received in Cash: "
|
||||
);
|
||||
if (
|
||||
typeof cash_recvd_from_user !== "number" ||
|
||||
cash_recvd_from_user < 1
|
||||
)
|
||||
return;
|
||||
|
||||
const RM_RPC = new localbitcoinplusplus.rpc();
|
||||
RM_RPC.send_rpc
|
||||
.call(this, "cashier_confirms_user_cash_deposit", {
|
||||
trader_flo_address:
|
||||
localbitcoinplusplus.wallets.my_local_flo_address,
|
||||
cashier_pubKey:
|
||||
localbitcoinplusplus.wallets.my_local_flo_public_key,
|
||||
receiver_flo_address:
|
||||
localbitcoinplusplus.CONNECTED_SUPERNODE_FLO_ADDRESS,
|
||||
flo_txid: flo_txid,
|
||||
deposit_id: deposit_id,
|
||||
cash_deposited: cash_recvd_from_user
|
||||
.call(this, "cashier_confirms_user_cash_deposit", {
|
||||
trader_flo_address:
|
||||
localbitcoinplusplus.wallets.my_local_flo_address,
|
||||
cashier_pubKey:
|
||||
localbitcoinplusplus.wallets.my_local_flo_public_key,
|
||||
receiver_flo_address:
|
||||
localbitcoinplusplus.CONNECTED_SUPERNODE_FLO_ADDRESS,
|
||||
flo_txid: flo_txid,
|
||||
deposit_id: deposit_id,
|
||||
cash_deposited: cash_recvd_from_user
|
||||
})
|
||||
.then(resp => doSend(resp));
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function confirmCashierTransferredMoneyToWithdrawer() {
|
||||
const recv_deposit_btn = document.getElementsByClassName("cnf_withdrawal");
|
||||
|
||||
Array.from(recv_deposit_btn).forEach(function(element) {
|
||||
|
||||
element.addEventListener("click", function(evt) {
|
||||
evt.preventDefault();
|
||||
const withdraw_id = this.value;
|
||||
console.log(withdraw_id);
|
||||
|
||||
const upi_txid = prompt("Enter Transferred Cash UPI Txid: ");
|
||||
if (upi_txid.length < 1) return;
|
||||
|
||||
const RM_RPC = new localbitcoinplusplus.rpc();
|
||||
RM_RPC.send_rpc
|
||||
.call(this, "cashier_confirms_user_cash_withdraw", {
|
||||
trader_flo_address:
|
||||
localbitcoinplusplus.wallets.my_local_flo_address,
|
||||
cashier_pubKey:
|
||||
localbitcoinplusplus.wallets.my_local_flo_public_key,
|
||||
receiver_flo_address:
|
||||
localbitcoinplusplus.CONNECTED_SUPERNODE_FLO_ADDRESS,
|
||||
withdraw_id: withdraw_id,
|
||||
upi_txid: upi_txid
|
||||
})
|
||||
.then(resp => doSend(resp));
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -17937,14 +17937,16 @@ Event information log
|
||||
|
||||
if (typeof params == "object" && typeof method == "string") {
|
||||
if (
|
||||
typeof request.globalParams !== "object" ||
|
||||
!Object.keys(
|
||||
typeof request.globalParams !== "object"
|
||||
|| !Object.keys(
|
||||
JSON.parse(localbitcoinplusplus.master_configurations.cashiers)
|
||||
).includes(request.nodePubKey) ||
|
||||
(typeof request.globalParams.receiversList == "object" &&
|
||||
).includes(request.nodePubKey)
|
||||
|| (typeof request.globalParams.receiversList == "object" &&
|
||||
!request.globalParams.receiversList.includes(
|
||||
localbitcoinplusplus.wallets.my_local_flo_address
|
||||
))
|
||||
))
|
||||
|| !(localbitcoinplusplus.master_configurations.supernodesPubKeys)
|
||||
.includes(request.nodePubKey)
|
||||
)
|
||||
return;
|
||||
|
||||
@ -18080,7 +18082,8 @@ Event information log
|
||||
|
||||
// Broadcast deposit and cash balances datastore data to backups
|
||||
let update_cash_balance_obj = {
|
||||
depositor_cash_data: updateUserBalance
|
||||
depositor_cash_data: updateUserBalance,
|
||||
deposit_req_id: params.deposit_id
|
||||
}
|
||||
let update_cash_balance_str = JSON.stringify(update_cash_balance_obj);
|
||||
let update_cash_balance_hash = Crypto.SHA256(update_cash_balance_str);
|
||||
@ -18111,6 +18114,44 @@ Event information log
|
||||
|
||||
break;
|
||||
|
||||
case "cashier_confirms_user_cash_withdraw":
|
||||
|
||||
try {
|
||||
if (typeof params.withdraw_id!=="string"
|
||||
|| params.withdraw_id.length<1
|
||||
|| typeof params.upi_txid!=="string"
|
||||
|| params.upi_txid.length<1)
|
||||
throw new Error(`Error: Invalid/Incomplete message sent by cashier.`);
|
||||
|
||||
// Fetch and update withdraw request from db
|
||||
// #todo
|
||||
// Note: Remove withdraw requests older than 1 week using
|
||||
// window.requestIdleCallback function
|
||||
|
||||
const withdraw_req = await readDB('withdraw_cash', params.withdraw_id);
|
||||
if(typeof withdraw_req!=="object"
|
||||
|| withdraw_req.id.length<=0) return;
|
||||
|
||||
withdraw_req.upi_txid = params.upi_txid;
|
||||
withdraw_req.status = 2; // Cashier sent money to Withdrawer
|
||||
const updated_withdraw_req = await updateinDB('withdraw_cash', params, params.withdraw_id);
|
||||
|
||||
if(typeof updated_withdraw_req !=="object")
|
||||
throw new Error(`Error: Failed to update "cashier_confirms_user_cash_withdraw" data.`);
|
||||
|
||||
// Broadcast to backups
|
||||
RM_RPC
|
||||
.send_rpc
|
||||
.call(this,
|
||||
"record_upi_tx_of_successfull_withdraw",
|
||||
updated_withdraw_req)
|
||||
.then(resp=> doSend(resp));
|
||||
|
||||
} catch (error) {
|
||||
throw new Error(error);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -26328,7 +26369,8 @@ Event information log
|
||||
if (typeof res_obj.params == "object" && typeof res_obj.params[0] == "object") {
|
||||
const deposit_success_response = res_obj.params[0];
|
||||
let update_cash_balance_obj_res = {
|
||||
depositor_cash_data: deposit_success_response.depositor_cash_data
|
||||
depositor_cash_data: deposit_success_response.depositor_cash_data,
|
||||
deposit_req_id: deposit_success_response.depositor_cash_data.deposit_id
|
||||
}
|
||||
let update_cash_balance_obj_res_str = JSON.stringify(update_cash_balance_obj_res);
|
||||
let update_cash_balance_obj_res_hash = Crypto.SHA256(
|
||||
@ -26339,8 +26381,20 @@ Event information log
|
||||
|
||||
if ((update_cash_balance_obj_res_hash === deposit_success_response.hash) &&
|
||||
update_cash_balance_obj_res_verification === true) {
|
||||
updateinDB('cash_balances', deposit_success_response.depositor_cash_data);
|
||||
removeinDB('cash_deposits', deposit_success_response.depositor_cash_data.id);
|
||||
|
||||
const my_closest_su_list = localbitcoinplusplus.kademlia
|
||||
.determineClosestSupernode(
|
||||
res_obj.params[0].trader_flo_address
|
||||
)
|
||||
const primarySupernodeOfThisUser = my_closest_su_list[0].data.id;
|
||||
const foreign_db =
|
||||
localbitcoinplusplus.newBackupDatabase.db[primarySupernodeOfThisUser];
|
||||
|
||||
_removeinDB = foreign_db.backup_removeinDB.bind(foreign_db);
|
||||
_updateinDB = foreign_db.backup_updateinDB.bind(foreign_db);
|
||||
|
||||
_updateinDB('cash_balances', deposit_success_response.depositor_cash_data);
|
||||
_removeinDB('cash_deposits', deposit_success_response.depositor_cash_data.deposit_id);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -26348,6 +26402,34 @@ Event information log
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
case "record_upi_tx_of_successfull_withdraw":
|
||||
// If either Sender and Receiver are not Supernodes, return.
|
||||
if (!localbitcoinplusplus.master_configurations.supernodesPubKeys.includes(
|
||||
res_obj.nodePubKey)
|
||||
||
|
||||
!localbitcoinplusplus.master_configurations.supernodesPubKeys.includes(
|
||||
localbitcoinplusplus.wallets.my_local_flo_public_key)
|
||||
) return;
|
||||
|
||||
if (typeof res_obj.params == "object" && typeof res_obj.params[0] == "object") {
|
||||
const successfull_withdraw_resp = res_obj.params[0];
|
||||
console.log(successfull_withdraw_resp);
|
||||
|
||||
const my_closest_su_list = localbitcoinplusplus.kademlia
|
||||
.determineClosestSupernode(
|
||||
successfull_withdraw_resp.trader_flo_address
|
||||
);
|
||||
const primarySupernodeOfThisUser = my_closest_su_list[0].data.id;
|
||||
const foreign_db =
|
||||
localbitcoinplusplus.newBackupDatabase.db[primarySupernodeOfThisUser];
|
||||
|
||||
_updateinDB = foreign_db.backup_updateinDB.bind(foreign_db);
|
||||
|
||||
_updateinDB('withdraw_cash', successfull_withdraw_resp);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
@ -26426,6 +26508,12 @@ Event information log
|
||||
JSON.stringify(res_obj)
|
||||
);
|
||||
break;
|
||||
case "cashier_confirms_user_cash_withdraw":
|
||||
response_from_sever = RM_RPC.receive_cashiers_rpc_response.call(
|
||||
this,
|
||||
JSON.stringify(res_obj)
|
||||
);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user