improved tx cnf issue in cash deposits

This commit is contained in:
Abhishek Sinha 2019-12-23 14:30:14 +05:30
parent 10f8270b43
commit 829da15201
2 changed files with 57 additions and 37 deletions

View File

@ -13637,6 +13637,12 @@
};
}
function delay(t, v) {
return new Promise(function(resolve) {
setTimeout(resolve.bind(null, v), t);
});
}
function duplicatesInArray(arr) {
arr.reduce(function(acc, el, i, arr) {
if (arr.indexOf(el) !== i && acc.indexOf(el) < 0) acc.push(el);
@ -13771,6 +13777,9 @@
const confirmTx = confirm(token_transfer_statement);
if(!confirmTx) return;
const websocket_conn = localbitcoinplusplus.supernode_conns[requesting_supernode];
if(typeof websocket_conn!=="object") return;
let flo_txid = '';
const flo_tx = await RM_WALLET.sendTransaction(
@ -13801,12 +13810,28 @@
parent_supernode: websocket_name,
}
const websocket_conn = localbitcoinplusplus.supernode_conns[requesting_supernode];
if(typeof websocket_conn!=="object") return;
const txidUrlDeposit = `${localbitcoinplusplus.server
.flo_api_testnet}/api/v1.0/getTransactionDetails/${flo_txid}`;
let n=1;
(async function validateTxidInBlockchain() {
// Validate Flo txid
await delay(120000);
const validate_flo_txid = await helper_functions.ajaxGet(txidUrlDeposit);
console.log(validate_flo_txid);
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'
) {
RM_RPC.send_rpc
.call(this, "cashier_confirms_user_cash_deposit", req_body)
.then(resp => doSend(websocket_conn, resp));
} else if(n<=10) {
validateTxidInBlockchain();
n++;
} else throw new Error(`Failed to inform Supernode of cash deposit: ${flo_txid}`);
})()
RM_RPC.send_rpc
.call(this, "cashier_confirms_user_cash_deposit", req_body)
.then(resp => doSend(websocket_conn, resp));
});
});
@ -13851,27 +13876,26 @@
async function transferTokensManually() {
try {
const token_sender = localbitcoinplusplus.wallets.my_local_flo_address;
const token_balance_url = `${localbitcoinplusplus.server.flo_api_testnet}/api/v1.0/getFloAddressBalance?token=${token_name}&floAddress=${token_sender}`;
const sender_token_balance = await helper_functions.ajaxGet(token_balance_url);
const token_receiver = document.getElementById('token_receiver').value;
const send_tokens_btn = document.getElementById('send_tokens_btn');
const token_amount = Number(document.getElementById('token_amount').value);
const token_name = document.querySelector('input[name="transfer_token_name"]:checked').value;
const flo_comment = `transfer ${token_amount} ${token_name}# to ${token_receiver}`;
let err_msg = '';
if(typeof sender_token_balance!=="object"
|| typeof sender_token_balance.balance!=="number"
|| sender_token_balance.balance<token_amount) {
err_msg = `INFO: Sender has insufficient ${token_name} balance.`;
showMessage(err_msg);
return false;
}
send_tokens_btn.onclick = function() {
return new Promise(async (resolve, reject)=>{
const token_sender = localbitcoinplusplus.wallets.my_local_flo_address;
const token_receiver = document.getElementById('token_receiver').value;
const send_tokens_btn = document.getElementById('send_tokens_btn');
const token_amount = Number(document.getElementById('token_amount').value);
const token_name_radio = document.querySelector('input[name="transfer_token_name"]:checked').value;
const flo_comment = `transfer ${token_amount} ${token_name}# to ${token_receiver}`;
const token_balance_url = `${localbitcoinplusplus.server.flo_api_testnet}/api/v1.0/getFloAddressBalance?token=${token_name}&floAddress=${token_sender}`;
const sender_token_balance = await helper_functions.ajaxGet(token_balance_url);
let err_msg = '';
if(typeof sender_token_balance!=="object"
|| typeof sender_token_balance.balance!=="number"
|| sender_token_balance.balance<token_amount) {
err_msg = `INFO: Sender has insufficient ${token_name} balance.`;
showMessage(err_msg);
return false;
}
let flo_txid = '';
const RM_WALLET = new localbitcoinplusplus.wallets;
const flo_tx = await RM_WALLET.sendTransaction(

View File

@ -8749,13 +8749,7 @@
// 52 characters base58
ECKey.isCompressedWalletImportFormat = function(key) {
key = key.toString();
// return ECKey.privateKeyPrefix == 0x80
// ? /^[LK][123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{51}$/.test(
// key
// )
// : /^c[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{51}$/.test(
// key
// );
switch (ECKey.currentBlockchain) {
case "BTC":
return /^[LK][123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{51}$/.test(
@ -18516,19 +18510,21 @@
// Validate deposit_id
const user_deposit_req = await _readDB("cash_deposits", params.deposit_id);
if (typeof user_deposit_req!=="object"
|| user_deposit_req===null) return;
|| user_deposit_req===null) return;
const txidUrlDeposit = `${localbitcoinplusplus.server
.flo_api_testnet}/api/v1.0/getTransactionDetails/${params.flo_txid}`;
// Validate Flo txid
const validate_flo_txid = await helper_functions
.ajaxGet(`${localbitcoinplusplus.server
.flo_api_testnet}/api/v1.0/getTransactionDetails/${params.flo_txid}`);
const validate_flo_txid = await helper_functions.ajaxGet(txidUrlDeposit);
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'
) throw new Error(`Error: Txid ${params.flo_txid} not found in Blockchain.`);
)
throw new Error(`Error: Txid ${params.flo_txid} not found in Blockchain.`);
/** IMP: CHECK WHETHER VIN IS A VALID SUPERNODE FLO ID HERE **/
const cashiers_pub_keys = Object.keys(JSON.parse(localbitcoinplusplus.master_configurations.cashiers));
const cashiers_flo_keys = Object.values(cashiers_pub_keys).map(m=>bitjs["FLO_TEST"].pubkey2address(m));