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"
|
placeholder="Search anything"
|
||||||
/>
|
/>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
class="btn btn-outline-primary"
|
class="btn btn-outline-primary"
|
||||||
id="fetch_withdraws"
|
id="fetch_withdraws"
|
||||||
>
|
>
|
||||||
Load Pending Cash Withdrawals
|
Load Pending Cash Withdrawals
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<table id="withdraws_list" class="myTable">
|
<table id="withdraws_list" class="myTable">
|
||||||
@ -239,8 +239,6 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
<footer class="footer">
|
<footer class="footer">
|
||||||
@ -12180,10 +12178,10 @@
|
|||||||
privateKeyDecimal = BigInteger(pk).toString();
|
privateKeyDecimal = BigInteger(pk).toString();
|
||||||
privateKeyHex = Crypto.util.bytesToHex(pk);
|
privateKeyHex = Crypto.util.bytesToHex(pk);
|
||||||
return {
|
return {
|
||||||
privateKeyDecimal: privateKeyDecimal,
|
privateKeyDecimal: privateKeyDecimal,
|
||||||
privateKeyHex: privateKeyHex
|
privateKeyHex: privateKeyHex
|
||||||
};
|
};
|
||||||
},
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/* CODE_JUNCTION: RPC */
|
/* CODE_JUNCTION: RPC */
|
||||||
@ -13062,7 +13060,7 @@
|
|||||||
t += `<td> ${m.trader_flo_address} </td>`;
|
t += `<td> ${m.trader_flo_address} </td>`;
|
||||||
t += `<td> ${m.depositing_amount} </td>`;
|
t += `<td> ${m.depositing_amount} </td>`;
|
||||||
t += `<td> ${m.currency} </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>`;
|
t += `</tr>`;
|
||||||
});
|
});
|
||||||
deposits_table.insertAdjacentHTML("beforeend", t);
|
deposits_table.insertAdjacentHTML("beforeend", t);
|
||||||
@ -13083,7 +13081,8 @@
|
|||||||
response_from_sever.data.map(m => {
|
response_from_sever.data.map(m => {
|
||||||
const user_upi = localbitcoinplusplus.encrypt.decryptMessage(
|
const user_upi = localbitcoinplusplus.encrypt.decryptMessage(
|
||||||
response_from_sever.data[0].receivinAddress.secret,
|
response_from_sever.data[0].receivinAddress.secret,
|
||||||
response_from_sever.data[0].receivinAddress.senderPublicKeyString
|
response_from_sever.data[0].receivinAddress
|
||||||
|
.senderPublicKeyString
|
||||||
);
|
);
|
||||||
t += `<tr>`;
|
t += `<tr>`;
|
||||||
t += `<td> ${user_upi} </td>`;
|
t += `<td> ${user_upi} </td>`;
|
||||||
@ -13091,6 +13090,7 @@
|
|||||||
t += `<td> ${m.withdraw_amount} </td>`;
|
t += `<td> ${m.withdraw_amount} </td>`;
|
||||||
t += `<td> ${m.currency} </td>`;
|
t += `<td> ${m.currency} </td>`;
|
||||||
t += `<td> ${m.token_transfer_txid} </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>`;
|
t += `</tr>`;
|
||||||
});
|
});
|
||||||
withdraws_table.insertAdjacentHTML("beforeend", t);
|
withdraws_table.insertAdjacentHTML("beforeend", t);
|
||||||
@ -13222,11 +13222,11 @@
|
|||||||
function showMessage(msg = "", t = 10000) {
|
function showMessage(msg = "", t = 10000) {
|
||||||
if (msg.length > 0) LogEvent(msg);
|
if (msg.length > 0) LogEvent(msg);
|
||||||
console.info(msg);
|
console.info(msg);
|
||||||
//displayMessages();
|
displayMessages();
|
||||||
// setTimeout(function(){
|
setTimeout(function() {
|
||||||
// closeMessage();
|
closeMessage();
|
||||||
// clearTimeout();
|
clearTimeout();
|
||||||
// }, t);
|
}, t);
|
||||||
}
|
}
|
||||||
|
|
||||||
function displayMessages() {
|
function displayMessages() {
|
||||||
@ -13409,8 +13409,10 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function confirmDepositReceivedFromUser() {
|
function confirmDepositReceivedFromUser() {
|
||||||
const recv_deposit_btn = document.getElementById('cnf_deposits');
|
const recv_deposit_btn = document.getElementsByClassName("cnf_deposits");
|
||||||
recv_deposit_btn.addEventListener('click', function(evt) {
|
|
||||||
|
Array.from(recv_deposit_btn).forEach(function(element) {
|
||||||
|
element.addEventListener("click", function(evt) {
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
const deposit_id = this.value;
|
const deposit_id = this.value;
|
||||||
console.log(deposit_id);
|
console.log(deposit_id);
|
||||||
@ -13421,24 +13423,61 @@
|
|||||||
const upi_txid = prompt("Enter Received Cash UPI Txid: ");
|
const upi_txid = prompt("Enter Received Cash UPI Txid: ");
|
||||||
if (upi_txid.length < 1) return;
|
if (upi_txid.length < 1) return;
|
||||||
|
|
||||||
const cash_recvd_from_user = prompt("Enter Amount Received in Cash: ");
|
const cash_recvd_from_user = prompt(
|
||||||
if (typeof cash_recvd_from_user!=="number" || cash_recvd_from_user < 1) return;
|
"Enter Amount Received in Cash: "
|
||||||
|
);
|
||||||
|
if (
|
||||||
|
typeof cash_recvd_from_user !== "number" ||
|
||||||
|
cash_recvd_from_user < 1
|
||||||
|
)
|
||||||
|
return;
|
||||||
|
|
||||||
const RM_RPC = new localbitcoinplusplus.rpc();
|
const RM_RPC = new localbitcoinplusplus.rpc();
|
||||||
RM_RPC.send_rpc
|
RM_RPC.send_rpc
|
||||||
.call(this, "cashier_confirms_user_cash_deposit", {
|
.call(this, "cashier_confirms_user_cash_deposit", {
|
||||||
trader_flo_address:
|
trader_flo_address:
|
||||||
localbitcoinplusplus.wallets.my_local_flo_address,
|
localbitcoinplusplus.wallets.my_local_flo_address,
|
||||||
cashier_pubKey:
|
cashier_pubKey:
|
||||||
localbitcoinplusplus.wallets.my_local_flo_public_key,
|
localbitcoinplusplus.wallets.my_local_flo_public_key,
|
||||||
receiver_flo_address:
|
receiver_flo_address:
|
||||||
localbitcoinplusplus.CONNECTED_SUPERNODE_FLO_ADDRESS,
|
localbitcoinplusplus.CONNECTED_SUPERNODE_FLO_ADDRESS,
|
||||||
flo_txid: flo_txid,
|
flo_txid: flo_txid,
|
||||||
deposit_id: deposit_id,
|
deposit_id: deposit_id,
|
||||||
cash_deposited: cash_recvd_from_user
|
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));
|
.then(resp => doSend(resp));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -17937,14 +17937,16 @@ Event information log
|
|||||||
|
|
||||||
if (typeof params == "object" && typeof method == "string") {
|
if (typeof params == "object" && typeof method == "string") {
|
||||||
if (
|
if (
|
||||||
typeof request.globalParams !== "object" ||
|
typeof request.globalParams !== "object"
|
||||||
!Object.keys(
|
|| !Object.keys(
|
||||||
JSON.parse(localbitcoinplusplus.master_configurations.cashiers)
|
JSON.parse(localbitcoinplusplus.master_configurations.cashiers)
|
||||||
).includes(request.nodePubKey) ||
|
).includes(request.nodePubKey)
|
||||||
(typeof request.globalParams.receiversList == "object" &&
|
|| (typeof request.globalParams.receiversList == "object" &&
|
||||||
!request.globalParams.receiversList.includes(
|
!request.globalParams.receiversList.includes(
|
||||||
localbitcoinplusplus.wallets.my_local_flo_address
|
localbitcoinplusplus.wallets.my_local_flo_address
|
||||||
))
|
))
|
||||||
|
|| !(localbitcoinplusplus.master_configurations.supernodesPubKeys)
|
||||||
|
.includes(request.nodePubKey)
|
||||||
)
|
)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -18080,7 +18082,8 @@ Event information log
|
|||||||
|
|
||||||
// Broadcast deposit and cash balances datastore data to backups
|
// Broadcast deposit and cash balances datastore data to backups
|
||||||
let update_cash_balance_obj = {
|
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_str = JSON.stringify(update_cash_balance_obj);
|
||||||
let update_cash_balance_hash = Crypto.SHA256(update_cash_balance_str);
|
let update_cash_balance_hash = Crypto.SHA256(update_cash_balance_str);
|
||||||
@ -18111,6 +18114,44 @@ Event information log
|
|||||||
|
|
||||||
break;
|
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:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -26328,7 +26369,8 @@ Event information log
|
|||||||
if (typeof res_obj.params == "object" && typeof res_obj.params[0] == "object") {
|
if (typeof res_obj.params == "object" && typeof res_obj.params[0] == "object") {
|
||||||
const deposit_success_response = res_obj.params[0];
|
const deposit_success_response = res_obj.params[0];
|
||||||
let update_cash_balance_obj_res = {
|
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_str = JSON.stringify(update_cash_balance_obj_res);
|
||||||
let update_cash_balance_obj_res_hash = Crypto.SHA256(
|
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) &&
|
if ((update_cash_balance_obj_res_hash === deposit_success_response.hash) &&
|
||||||
update_cash_balance_obj_res_verification === true) {
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
@ -26349,6 +26403,34 @@ Event information log
|
|||||||
}
|
}
|
||||||
break;
|
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:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -26426,6 +26508,12 @@ Event information log
|
|||||||
JSON.stringify(res_obj)
|
JSON.stringify(res_obj)
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
|
case "cashier_confirms_user_cash_withdraw":
|
||||||
|
response_from_sever = RM_RPC.receive_cashiers_rpc_response.call(
|
||||||
|
this,
|
||||||
|
JSON.stringify(res_obj)
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user