From 22f3b74d063d97d0e3d96bb57141ca9508ce161a Mon Sep 17 00:00:00 2001 From: Abhishek Sinha Date: Sat, 26 Sep 2020 14:22:18 +0530 Subject: [PATCH] updated code for improved cashier functions --- cash_payments_handler.html | 18 +- cash_payments_handler_v2.html | 225 +- index.html | 64509 +++++++++++++++++--------------- system_status.html | 12100 ++++++ 4 files changed, 47151 insertions(+), 29701 deletions(-) create mode 100644 system_status.html diff --git a/cash_payments_handler.html b/cash_payments_handler.html index 494c713..a0909cd 100644 --- a/cash_payments_handler.html +++ b/cash_payments_handler.html @@ -11409,8 +11409,8 @@ enumerable: false }); - const ENVR = 'LIVE'; // LIVE, TEST - const WS = 'wss'; + const ENVR = 'TEST'; // LIVE, TEST + const WS = 'ws'; const DBName = "paymentsHandlerDBRemote"; if(ENVR === 'LIVE') { @@ -13792,7 +13792,19 @@ let supernodeSeedsArray = Object.values(supernodeSeedsObj); supernodeSeedsArray.map(async wsUri => { localbitcoinplusplus.supernode_conns[wsUri.kbucketId] = await initializeWebSocket (`${WS}://${wsUri.ip}`); - startWebSocket(localbitcoinplusplus.supernode_conns[wsUri.kbucketId]); + + await startWebSocket(localbitcoinplusplus.supernode_conns[wsUri.kbucketId]); + + let req_body = { + trader_flo_address: + localbitcoinplusplus.wallets.my_local_flo_address, + is_live: true, + receiver_flo_address: wsUri.kbucketId + } + const server_con = localbitcoinplusplus.supernode_conns[wsUri.kbucketId]; + RM_RPC.send_rpc + .call(this, 'cashier_is_live', req_body) + .then(resp => doSend(server_con, resp)); }); } diff --git a/cash_payments_handler_v2.html b/cash_payments_handler_v2.html index 827d047..5e4a43f 100644 --- a/cash_payments_handler_v2.html +++ b/cash_payments_handler_v2.html @@ -13459,90 +13459,137 @@ } function onMessageDisplay(responseName, responseData) { - switch (responseName) { - case "list_of_cashier_latest_pending_cash_deposits": - (async function() { - let failed_confirms_in_deposits = await readAllDB('failed_deposit_confirms'); - let failed_confirms_in_deposits_ids = failed_confirms_in_deposits.map(m=>m.deposit_id); - // console.log(failed_confirms_in_deposits_ids); - // if(failed_confirms_in_deposits_ids.length>0) { - // alert("There are some failed deposit requests in DB. Please contact the admin."); - // } - let deposit_promises = []; - let t = ``; - let deposits_table = document.getElementById("deposits_list"); - //deposits_table.innerHTML = ''; - for (const m of responseData.responseData.data) { - - let su_res = await localbitcoinplusplus.kademlia.determineClosestSupernode(m.trader_flo_address); - let closestSupernode = su_res[0].data.id; - t += ``; - t += ` ${m.user_upi} `; - t += ` ${m.trader_flo_address} `; - t += ` ${m.depositing_amount} `; - t += ` ${m.currency} `; - t += ` ${m.timestamp} `; - if(m.status===1) { - // This deposit, token transfer was done but supernode was not informed - if(failed_confirms_in_deposits_ids.includes(m.id)) { - t += ` - `; - } else { - t += ` - - `; + try { + switch (responseName) { + case "list_of_cashier_latest_pending_cash_deposits": + (async function() { + let failed_confirms_in_deposits = await readAllDB('failed_deposit_confirms'); + let failed_confirms_in_deposits_ids = failed_confirms_in_deposits.map(m=>m.deposit_id); + // console.log(failed_confirms_in_deposits_ids); + // if(failed_confirms_in_deposits_ids.length>0) { + // alert("There are some failed deposit requests in DB. Please contact the admin."); + // } + + let all_cloud_registred_deposits = await floCloudAPI.requestApplicationData( + {receiverID: myFloID, type:"exchange_cash_deposits"}); + + if(typeof all_cloud_registred_deposits=="string") { + all_cloud_registred_deposits = JSON.parse(all_cloud_registred_deposits); + } + console.log(all_cloud_registred_deposits); + + let registered_deposit_ids = []; + for (const registered_deposit_data in all_cloud_registred_deposits) { + if (all_cloud_registred_deposits.hasOwnProperty(registered_deposit_data)) { + const registered_deposit = all_cloud_registred_deposits[registered_deposit_data].message; + registered_deposit_ids.push(registered_deposit.id); + } + } + + let deposit_promises = []; + let t = ``; + let deposits_table = document.getElementById("deposits_list"); + //deposits_table.innerHTML = ''; + for (const m of responseData.responseData.data) { + + if(!registered_deposit_ids.includes(m.id)) + floCloudAPI.sendApplicationData(m, type="exchange_cash_deposits", {receiverID: myFloID}); + + let su_res = await localbitcoinplusplus.kademlia.determineClosestSupernode(m.trader_flo_address); + let closestSupernode = su_res[0].data.id; + t += ``; + t += ` ${m.user_upi} `; + t += ` ${m.trader_flo_address} `; + t += ` ${m.depositing_amount} `; + t += ` ${m.currency} `; + t += ` ${m.timestamp} `; + if(m.status===1) { + // This deposit, token transfer was done but supernode was not informed + if(failed_confirms_in_deposits_ids.includes(m.id)) { + t += ` + `; + } else { + t += ` + + `; + } + + } else if(m.status===2) { + t += ` + `; + } + t += ``; + deposit_promises.push(addDB('deposits', m)); + } + deposits_table.insertAdjacentHTML("beforeend", t); + confirmDepositReceivedFromUser(); + })(); + break; + + case "list_of_cashier_latest_pending_cash_withdrawals": + (async function() { + let withdraw_promises = []; + let v = ``; + let withdraws_table = document.getElementById("withdraws_list"); + + let all_cloud_registred_withdrawals = await floCloudAPI.requestApplicationData( + {receiverID: myFloID, type:"exchange_cash_withdrawals"}); + + if(typeof all_cloud_registred_withdrawals=="string") { + all_cloud_registred_withdrawals = JSON.parse(all_cloud_registred_withdrawals); + } + + console.log(all_cloud_registred_withdrawals); + + let registered_withdraws_ids = []; + for (const registered_withdraw_data in all_cloud_registred_withdraws) { + if (all_cloud_registred_withdraws.hasOwnProperty(registered_withdraw_data)) { + const registered_withdraw = all_cloud_registred_withdraws[registered_withdraw_data].message; + registered_withdraws_ids.push(registered_withdraw.id); + } + } + + //withdraws_table.innerHTML = ''; + for (const m of responseData.responseData.data) { + + if(!registered_withdraws_ids.includes(m.id)) { + floCloudAPI.sendApplicationData(m, type="exchange_cash_withdrawals", {receiverID: myFloID}); } - } else if(m.status===2) { - t += ` - `; - } - t += ``; - deposit_promises.push(addDB('deposits', m)); - } - deposits_table.insertAdjacentHTML("beforeend", t); - confirmDepositReceivedFromUser(); - })(); - break; + const user_upi = localbitcoinplusplus.encrypt.decryptMessage( + m.receivinAddress.secret, + m.receivinAddress.senderPublicKeyString + ); + let su_res = await localbitcoinplusplus.kademlia.determineClosestSupernode(m.trader_flo_address); + let closestSupernode = su_res[0].data.id; - case "list_of_cashier_latest_pending_cash_withdrawals": - (async function() { - let withdraw_promises = []; - let v = ``; - let withdraws_table = document.getElementById("withdraws_list"); - //withdraws_table.innerHTML = ''; - for (const m of responseData.responseData.data) { - const user_upi = localbitcoinplusplus.encrypt.decryptMessage( - m.receivinAddress.secret, - m.receivinAddress.senderPublicKeyString - ); - let su_res = await localbitcoinplusplus.kademlia.determineClosestSupernode(m.trader_flo_address); - let closestSupernode = su_res[0].data.id; - - v += ``; - v += ` ${user_upi} `; - v += ` ${m.trader_flo_address} `; - v += ` ${m.withdraw_amount} `; - v += ` ${m.currency} `; - v += ` ${m.token_transfer_txid} `; - if(m.status===1) { - v += ` - - `; - } else if(m.status===2) { - v += ` - `; + v += ``; + v += ` ${user_upi} `; + v += ` ${m.trader_flo_address} `; + v += ` ${m.withdraw_amount} `; + v += ` ${m.currency} `; + v += ` ${m.token_transfer_txid} `; + if(m.status===1) { + v += ` + + `; + } else if(m.status===2) { + v += ` + `; + } + v += ``; + withdraw_promises.push(addDB('withdraws', m)); } - v += ``; - withdraw_promises.push(addDB('withdraws', m)); - } - withdraws_table.insertAdjacentHTML("beforeend", v); - confirmCashierTransferredMoneyToWithdrawer(); - })(); - break; - - default: + withdraws_table.insertAdjacentHTML("beforeend", v); + confirmCashierTransferredMoneyToWithdrawer(); + })(); break; + + default: + break; + } + } catch(e) { + console.error(e); } } @@ -13827,7 +13874,19 @@ let supernodeSeedsArray = Object.values(supernodeSeedsObj); supernodeSeedsArray.map(async wsUri => { localbitcoinplusplus.supernode_conns[wsUri.kbucketId] = await initializeWebSocket (`${WS}://${wsUri.ip}`); - startWebSocket(localbitcoinplusplus.supernode_conns[wsUri.kbucketId]); + + await startWebSocket(localbitcoinplusplus.supernode_conns[wsUri.kbucketId]); + + let req_body = { + trader_flo_address: + localbitcoinplusplus.wallets.my_local_flo_address, + is_live: true, + receiver_flo_address: wsUri.kbucketId + } + const server_con = localbitcoinplusplus.supernode_conns[wsUri.kbucketId]; + RM_RPC.send_rpc + .call(this, 'cashier_is_live', req_body) + .then(resp => doSend(server_con, resp)); }); } @@ -14016,10 +14075,10 @@ let n=1; (async function validateTxidInBlockchain() { // Validate Flo txid - //await delay(60000); + await delay(60000); const validate_flo_txid = await helper_functions.ajaxGet(txidUrlDeposit); console.log(validate_flo_txid); - if(0 && typeof validate_flo_txid == "object" + if(typeof validate_flo_txid == "object" && typeof validate_flo_txid.transactionDetails == "object" && typeof validate_flo_txid.transactionDetails.floData == "string" && validate_flo_txid.transactionDetails.floData.length > 5 // without ':text' @@ -14038,7 +14097,7 @@ return true; - } else if(0 && n<=20) { + } else if(n<=20) { validateTxidInBlockchain(); n++; } else { diff --git a/index.html b/index.html index aea925d..16d3e7d 100644 --- a/index.html +++ b/index.html @@ -1,11595 +1,16770 @@ + Local Bitcoin++ - + + -
-
-

Event Log

- - Close - - - -
-
-
- +
+
+

Event Log

+ + Close + + + +
+
+
+ -
- Copied -
+
+ Copied +
-