promisified sendMultipleInputsTransaction
This commit is contained in:
parent
93046494f9
commit
c574160a44
462
index.html
462
index.html
@ -6,9 +6,8 @@
|
|||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>Local Bitcoin++</title>
|
<title>Local Bitcoin++</title>
|
||||||
<!-- <link rel="stylesheet" href="/home/aks/Documents/p2p/localbitcoinplusplus/supernode/server/web/playground/main.css"> -->
|
<!-- <link rel="stylesheet" href="/home/aks/Documents/p2p/localbitcoinplusplus/supernode/server/web/playground/main.css"> -->
|
||||||
<style>
|
<style type="text/css">
|
||||||
|
@import url("https://fonts.googleapis.com/css?family=Barlow:400,500,600,700&display=swap");
|
||||||
@import url("https://fonts.googleapis.com/css?family=Barlow:400,500,600,700&display=swap");
|
|
||||||
@import url("https://fonts.googleapis.com/css?family=Roboto:400,500&display=swap");
|
@import url("https://fonts.googleapis.com/css?family=Roboto:400,500&display=swap");
|
||||||
@import url("https://fonts.googleapis.com/css2?family=Source+Code+Pro&display=swap");
|
@import url("https://fonts.googleapis.com/css2?family=Source+Code+Pro&display=swap");
|
||||||
* {
|
* {
|
||||||
@ -18469,8 +18468,6 @@
|
|||||||
readDB("cash_balances", trader_cash_id).then(async function (
|
readDB("cash_balances", trader_cash_id).then(async function (
|
||||||
cash_balances_res
|
cash_balances_res
|
||||||
) {
|
) {
|
||||||
try {
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
typeof cash_balances_res == "object" &&
|
typeof cash_balances_res == "object" &&
|
||||||
typeof cash_balances_res.trader_flo_address ==
|
typeof cash_balances_res.trader_flo_address ==
|
||||||
@ -18478,7 +18475,8 @@
|
|||||||
typeof cash_balances_res.cash_balance == "number" &&
|
typeof cash_balances_res.cash_balance == "number" &&
|
||||||
cash_balances_res.cash_balance > 0
|
cash_balances_res.cash_balance > 0
|
||||||
) {
|
) {
|
||||||
let old_cash_balances_res = JSON.parse(JSON.stringify(cash_balances_res));
|
const old_cash_balances_res = JSON.parse(JSON.stringify(cash_balances_res));
|
||||||
|
try {
|
||||||
let withdrawer_cash_balance = helper_functions.truncateDecimals(
|
let withdrawer_cash_balance = helper_functions.truncateDecimals(
|
||||||
cash_balances_res.cash_balance, 2
|
cash_balances_res.cash_balance, 2
|
||||||
);
|
);
|
||||||
@ -18504,8 +18502,7 @@
|
|||||||
|
|
||||||
// Get a cashier
|
// Get a cashier
|
||||||
const cashiersList = JSON.parse(
|
const cashiersList = JSON.parse(
|
||||||
localbitcoinplusplus.master_configurations
|
localbitcoinplusplus.master_configurations.cashiers
|
||||||
.cashiers
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const cashiersPubKeysArray = Object.keys(cashiersList);
|
const cashiersPubKeysArray = Object.keys(cashiersList);
|
||||||
@ -18551,9 +18548,7 @@
|
|||||||
status: 1 // withdraw request called
|
status: 1 // withdraw request called
|
||||||
};
|
};
|
||||||
|
|
||||||
readDB("localbitcoinUser", "00-01").then(function (
|
const su_data = await readDB("localbitcoinUser", "00-01");
|
||||||
su_data
|
|
||||||
) {
|
|
||||||
if (
|
if (
|
||||||
typeof su_data == "object" &&
|
typeof su_data == "object" &&
|
||||||
typeof su_data.myLocalFLOPublicKey ==
|
typeof su_data.myLocalFLOPublicKey ==
|
||||||
@ -18580,38 +18575,35 @@
|
|||||||
"order_validator_public_key"
|
"order_validator_public_key"
|
||||||
] = su_data.myLocalFLOPublicKey;
|
] = su_data.myLocalFLOPublicKey;
|
||||||
|
|
||||||
try {
|
|
||||||
// Transfer Token
|
// Transfer Token
|
||||||
RM_TRADE.sendMultipleInputsTransaction(
|
const transfer_token_response = await RM_TRADE.sendMultipleInputsTransaction(
|
||||||
localbitcoinplusplus.BASE_BLOCKCHAIN,
|
localbitcoinplusplus.BASE_BLOCKCHAIN,
|
||||||
[localbitcoinplusplus.wallets
|
[localbitcoinplusplus.wallets.MY_SUPERNODE_PRIVATE_KEY],
|
||||||
.MY_SUPERNODE_PRIVATE_KEY],
|
|
||||||
cashierFloAddr,
|
cashierFloAddr,
|
||||||
0.01,
|
0.01,
|
||||||
localbitcoinplusplus.wallets
|
localbitcoinplusplus.wallets.my_local_flo_address,
|
||||||
.my_local_flo_address,
|
flo_withdraw_comment
|
||||||
async function (res) {
|
);
|
||||||
console.log(res);
|
|
||||||
if (typeof res == "object") {
|
if (typeof transfer_token_response == "object") {
|
||||||
try {
|
|
||||||
let msg = "";
|
let msg = "";
|
||||||
let resp_txid = "";
|
let resp_txid = "";
|
||||||
if (
|
if (
|
||||||
typeof res.txid == "string" &&
|
typeof transfer_token_response.txid == "string" &&
|
||||||
res.txid.length > 0
|
transfer_token_response.txid.length > 0
|
||||||
) {
|
) {
|
||||||
resp_obj = JSON.parse(res.txid);
|
resp_obj = transfer_token_response.txid;
|
||||||
resp_txid = resp_obj.txid.result || resp_obj.txid;
|
resp_txid = resp_obj.txid.result || resp_obj.txid;
|
||||||
msg = `Transaction Id for token transfer to ${params.trader_flo_address}: ${resp_txid}.`;
|
msg = `Transaction Id for token transfer to ${params.trader_flo_address}: ${resp_txid}.`;
|
||||||
} else {
|
} else {
|
||||||
console.log(res);
|
console.log(transfer_token_response);
|
||||||
err_response = {
|
err_response = {
|
||||||
user_flo_addr: cashierFloAddr,
|
user_flo_addr: cashierFloAddr,
|
||||||
msg: `Failed to transfer token for withdraw order ${withdraw_request_db_object.id}`
|
msg: `Failed to transfer token for withdraw order ${withdraw_request_db_object.id}`
|
||||||
}
|
}
|
||||||
reactor.dispatchEvent('message_for_user', err_response);
|
reactor.dispatchEvent('message_for_user', err_response);
|
||||||
throw new Errror(`ERROR: Failed to transfer token for withdraw order ${withdraw_request_db_object.id}.`);
|
throw new Errror(`ERROR: Failed to transfer token for withdraw order ${withdraw_request_db_object.id}.`);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msg.length > 0) {
|
if (msg.length > 0) {
|
||||||
@ -18674,34 +18666,10 @@
|
|||||||
withdrawal_request_response
|
withdrawal_request_response
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
} else {
|
|
||||||
throw new Errror(
|
|
||||||
`ERROR: Failed to make transaction. Message length is 0: ${msg}`
|
|
||||||
);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
updateinDB("cash_balances",
|
|
||||||
old_cash_balances_res,
|
|
||||||
old_cash_balances_res.id,
|
|
||||||
false, false
|
|
||||||
);
|
|
||||||
throw new Error(e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
|
||||||
flo_withdraw_comment
|
|
||||||
);
|
|
||||||
} catch (error) {
|
|
||||||
updateinDB("cash_balances",
|
|
||||||
old_cash_balances_res,
|
|
||||||
old_cash_balances_res.id,
|
|
||||||
false, false
|
|
||||||
);
|
|
||||||
throw new Error(error);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
// Return error to the requester
|
// Return error to the requester
|
||||||
err_msg =
|
err_msg =
|
||||||
@ -18713,8 +18681,6 @@
|
|||||||
reactor.dispatchEvent('message_for_user', err_response);
|
reactor.dispatchEvent('message_for_user', err_response);
|
||||||
throw new Error(err_msg);
|
throw new Error(err_msg);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
updateinDB("cash_balances",
|
updateinDB("cash_balances",
|
||||||
@ -18723,7 +18689,7 @@
|
|||||||
false, false
|
false, false
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
err_msg = "Unknown asset withdraw request error.";
|
err_msg = "Unknown asset withdraw request error.";
|
||||||
@ -18735,8 +18701,7 @@
|
|||||||
throw new Error(err_msg);
|
throw new Error(err_msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "cancel_trade":
|
case "cancel_trade":
|
||||||
@ -18929,25 +18894,27 @@
|
|||||||
withdrawer_crypto_bal_id
|
withdrawer_crypto_bal_id
|
||||||
);
|
);
|
||||||
|
|
||||||
RM_TRADE.sendMultipleInputsTransaction(
|
const withdraw_crypto_response =
|
||||||
|
await RM_TRADE.sendMultipleInputsTransaction(
|
||||||
withdraw_res.product,
|
withdraw_res.product,
|
||||||
params.btc_private_key_array,
|
params.btc_private_key_array,
|
||||||
withdraw_res.receiverBTCAddress,
|
withdraw_res.receiverBTCAddress,
|
||||||
totalWithdrawingAmount,
|
totalWithdrawingAmount,
|
||||||
withdraw_res.utxo_addr[0],
|
withdraw_res.utxo_addr[0]
|
||||||
async function (res) {
|
);
|
||||||
console.log(res);
|
|
||||||
try {
|
console.log(withdraw_crypto_response);
|
||||||
if (typeof res == "object") {
|
|
||||||
|
if (typeof withdraw_crypto_response == "object") {
|
||||||
let msg = "";
|
let msg = "";
|
||||||
let emsg = '';
|
let emsg = '';
|
||||||
let respo_obj = JSON.parse(res.txid);
|
let respo_obj = withdraw_crypto_response.txid;
|
||||||
if((typeof respo_obj.txid!=="string"
|
if ((typeof respo_obj.txid !== "string"
|
||||||
&& typeof respo_obj.txid.result!=="string")
|
&& typeof respo_obj.txid.result !== "string")
|
||||||
&& res.error==true) {
|
&& withdraw_crypto_response.error == true) {
|
||||||
emsg = 'Failed to send Transaction.';
|
emsg = 'Failed to send Transaction.';
|
||||||
if(typeof res.msg == "string") {
|
if (typeof withdraw_crypto_response.msg == "string") {
|
||||||
emsg = res.msg;
|
emsg = withdraw_crypto_response.msg;
|
||||||
}
|
}
|
||||||
console.error(emsg);
|
console.error(emsg);
|
||||||
RM_RPC.send_rpc
|
RM_RPC.send_rpc
|
||||||
@ -18965,10 +18932,10 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
typeof res.txid == "string" &&
|
typeof withdraw_crypto_response.txid == "string" &&
|
||||||
res.txid.length > 0
|
withdraw_crypto_response.txid.length > 0
|
||||||
) {
|
) {
|
||||||
resp_obj = JSON.parse(res.txid);
|
resp_obj = JSON.parse(withdraw_crypto_response.txid);
|
||||||
resp_txid = resp_obj.txid.result || resp_obj.txid;
|
resp_txid = resp_obj.txid.result || resp_obj.txid;
|
||||||
msg = `Transaction Id for your withdrawn crypto asset: ${resp_txid}.`;
|
msg = `Transaction Id for your withdrawn crypto asset: ${resp_txid}.`;
|
||||||
|
|
||||||
@ -19051,7 +19018,7 @@
|
|||||||
doSend(delRequestObject)
|
doSend(delRequestObject)
|
||||||
);
|
);
|
||||||
|
|
||||||
} else if (n <= 20) {
|
} else if (withdrawTxCounter <= 20) {
|
||||||
validateWithdrawTxidInBlockchain();
|
validateWithdrawTxidInBlockchain();
|
||||||
withdrawTxCounter++;
|
withdrawTxCounter++;
|
||||||
} else {
|
} else {
|
||||||
@ -19060,44 +19027,12 @@
|
|||||||
})();
|
})();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
console.log(res);
|
console.log(withdraw_crypto_response);
|
||||||
throw new Errror(`ERROR: Failed to make transaction.`);
|
throw new Errror(`ERROR: Failed to make transaction.`);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.error("Waithdraw transaction is not an object");
|
throw new Errror("Waithdraw transaction is not an object");
|
||||||
//throw new Errror(`ERROR: Failed to make transaction.`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
console.warn(error);
|
|
||||||
err_response = {
|
|
||||||
user_flo_addr: params.trader_flo_address,
|
|
||||||
msg: `Withdraw of crypto failed. Network issue:- Please try again after 30 minutes.`
|
|
||||||
}
|
|
||||||
reactor.dispatchEvent('message_for_user', err_response);
|
|
||||||
|
|
||||||
// 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(
|
|
||||||
"deposit",
|
|
||||||
"btc_address",
|
|
||||||
deposited_utxo_addr
|
|
||||||
)
|
|
||||||
if (typeof deposit_arr_resp[0] == "object") {
|
|
||||||
deposit_arr_resp[0].status = 2; // UTXO ready to be used again
|
|
||||||
await updateinDB(
|
|
||||||
"deposit",
|
|
||||||
deposit_arr_resp[0],
|
|
||||||
deposit_arr_resp[0].id
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await removeinDB("withdraw_btc", withdraw_id);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -19129,7 +19064,12 @@
|
|||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
throw new Error(error);
|
err_response = {
|
||||||
|
user_flo_addr: params.trader_flo_address,
|
||||||
|
msg: `Withdraw of crypto failed. Please try again later. ${error}`
|
||||||
|
}
|
||||||
|
reactor.dispatchEvent('message_for_user', err_response);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -20308,8 +20248,7 @@
|
|||||||
);
|
);
|
||||||
// Get a cashier
|
// Get a cashier
|
||||||
const cashiersList = JSON.parse(
|
const cashiersList = JSON.parse(
|
||||||
localbitcoinplusplus.master_configurations
|
localbitcoinplusplus.master_configurations.cashiers
|
||||||
.cashiers
|
|
||||||
);
|
);
|
||||||
const cashiersPubKeysArray = Object.keys(cashiersList);
|
const cashiersPubKeysArray = Object.keys(cashiersList);
|
||||||
const getAPaymentHandler = randomNoRepeats(cashiersPubKeysArray)();
|
const getAPaymentHandler = randomNoRepeats(cashiersPubKeysArray)();
|
||||||
@ -20317,10 +20256,7 @@
|
|||||||
getAPaymentHandler
|
getAPaymentHandler
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!cashiersPubKeysArray.includes(
|
if (!cashiersPubKeysArray.includes(getAPaymentHandler)) {
|
||||||
getAPaymentHandler
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`ERROR: ${getAPaymentHandler} is not recognized as any Cashier's Public Key.`
|
`ERROR: ${getAPaymentHandler} is not recognized as any Cashier's Public Key.`
|
||||||
);
|
);
|
||||||
@ -20349,8 +20285,7 @@
|
|||||||
status: 1 // withdraw request called
|
status: 1 // withdraw request called
|
||||||
};
|
};
|
||||||
|
|
||||||
readDB("localbitcoinUser", "00-01").then(
|
const su_data = await readDB("localbitcoinUser", "00-01");
|
||||||
function (su_data) {
|
|
||||||
if (
|
if (
|
||||||
typeof su_data == "object" &&
|
typeof su_data == "object" &&
|
||||||
typeof su_data.myLocalFLOPublicKey ==
|
typeof su_data.myLocalFLOPublicKey ==
|
||||||
@ -20379,9 +20314,9 @@
|
|||||||
"order_validator_public_key"
|
"order_validator_public_key"
|
||||||
] = su_data.myLocalFLOPublicKey;
|
] = su_data.myLocalFLOPublicKey;
|
||||||
|
|
||||||
try {
|
|
||||||
// Transfer Token
|
// Transfer Token
|
||||||
RM_TRADE.sendMultipleInputsTransaction(
|
const flo_withdraw_tx_res =
|
||||||
|
await RM_TRADE.sendMultipleInputsTransaction(
|
||||||
localbitcoinplusplus.BASE_BLOCKCHAIN,
|
localbitcoinplusplus.BASE_BLOCKCHAIN,
|
||||||
[localbitcoinplusplus.wallets
|
[localbitcoinplusplus.wallets
|
||||||
.MY_SUPERNODE_PRIVATE_KEY],
|
.MY_SUPERNODE_PRIVATE_KEY],
|
||||||
@ -20389,19 +20324,19 @@
|
|||||||
0.01,
|
0.01,
|
||||||
localbitcoinplusplus.wallets
|
localbitcoinplusplus.wallets
|
||||||
.my_local_flo_address,
|
.my_local_flo_address,
|
||||||
async function (res) {
|
flo_withdraw_comment
|
||||||
console.log(res);
|
);
|
||||||
if (typeof res == "object") {
|
|
||||||
|
console.log(flo_withdraw_tx_res);
|
||||||
|
if (typeof flo_withdraw_tx_res == "object") {
|
||||||
try {
|
try {
|
||||||
let msg = "";
|
let msg = "";
|
||||||
let resp_txid = "";
|
let resp_txid = "";
|
||||||
if (
|
if (
|
||||||
typeof res.txid == "string" &&
|
typeof flo_withdraw_tx_res.txid == "string" &&
|
||||||
res.txid.length > 0
|
flo_withdraw_tx_res.txid.length > 0
|
||||||
) {
|
) {
|
||||||
resp_obj = JSON.parse(
|
resp_obj = flo_withdraw_tx_res.txid
|
||||||
res.txid
|
|
||||||
);
|
|
||||||
resp_txid =
|
resp_txid =
|
||||||
resp_obj.txid.result ||
|
resp_obj.txid.result ||
|
||||||
resp_obj.txid;
|
resp_obj.txid;
|
||||||
@ -20412,10 +20347,7 @@
|
|||||||
msg: `Failed to transfer token for withdraw id ${withdraw_request_db_object.id}`
|
msg: `Failed to transfer token for withdraw id ${withdraw_request_db_object.id}`
|
||||||
}
|
}
|
||||||
reactor.dispatchEvent('message_for_user', err_response);
|
reactor.dispatchEvent('message_for_user', err_response);
|
||||||
throw new Errror(
|
throw new Errror(`ERROR: Failed to make transaction.`);
|
||||||
`ERROR: Failed to make transaction.`
|
|
||||||
);
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msg.length > 0) {
|
if (msg.length > 0) {
|
||||||
@ -20457,7 +20389,7 @@
|
|||||||
//add the request to supernode db
|
//add the request to supernode db
|
||||||
withdraw_request_db_object.token_transfer_txid =
|
withdraw_request_db_object.token_transfer_txid =
|
||||||
resp_txid ||
|
resp_txid ||
|
||||||
res.signedTxHash;
|
flo_withdraw_tx_res.signedTxHash;
|
||||||
|
|
||||||
// Add record in Db
|
// Add record in Db
|
||||||
const withdraw_request_db_object_res = await backup_server_db_instance.backup_addDB(
|
const withdraw_request_db_object_res = await backup_server_db_instance.backup_addDB(
|
||||||
@ -20486,7 +20418,6 @@
|
|||||||
throw new Errror(
|
throw new Errror(
|
||||||
`ERROR: Failed to make transaction. Message length is 0: ${msg}`
|
`ERROR: Failed to make transaction. Message length is 0: ${msg}`
|
||||||
);
|
);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
@ -20497,20 +20428,9 @@
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
|
||||||
flo_withdraw_comment
|
|
||||||
);
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error);
|
|
||||||
backup_server_db_instance.backup_updateinDB("cash_balances",
|
|
||||||
old_cash_balances_res,
|
|
||||||
old_cash_balances_res.id,
|
|
||||||
false, false
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
// Return error to the requester
|
// Return error to the requester
|
||||||
err_msg =
|
err_msg =
|
||||||
@ -20523,7 +20443,7 @@
|
|||||||
throw new Error(err_msg);
|
throw new Error(err_msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch(e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
backup_server_db_instance.backup_updateinDB("cash_balances",
|
backup_server_db_instance.backup_updateinDB("cash_balances",
|
||||||
old_cash_balances_res,
|
old_cash_balances_res,
|
||||||
@ -20532,7 +20452,7 @@
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
})
|
||||||
} else {
|
} else {
|
||||||
err_msg = "withdraw request error";
|
err_msg = "withdraw request error";
|
||||||
showMessage(err_msg);
|
showMessage(err_msg);
|
||||||
@ -20774,27 +20694,27 @@
|
|||||||
withdrawer_crypto_bal_id
|
withdrawer_crypto_bal_id
|
||||||
);
|
);
|
||||||
|
|
||||||
RM_TRADE.sendMultipleInputsTransaction(
|
const withdraw_tx_response =
|
||||||
|
await RM_TRADE.sendMultipleInputsTransaction(
|
||||||
withdraw_res.product,
|
withdraw_res.product,
|
||||||
params.btc_private_key_array,
|
params.btc_private_key_array,
|
||||||
withdraw_res.receiverBTCAddress,
|
withdraw_res.receiverBTCAddress,
|
||||||
totalWithdrawingAmount,
|
totalWithdrawingAmount,
|
||||||
withdraw_res.utxo_addr[0],
|
withdraw_res.utxo_addr[0]
|
||||||
async function (res) {
|
);
|
||||||
console.log(res);
|
|
||||||
try {
|
console.log(withdraw_tx_response);
|
||||||
if (typeof res == "object") {
|
if (typeof withdraw_tx_response == "object" && withdraw_tx_response !== null) {
|
||||||
let msg = "";
|
let msg = "";
|
||||||
let emsg = '';
|
let emsg = '';
|
||||||
let respo_obj = JSON.parse(res.txid);
|
let respo_obj = withdraw_tx_response.txid;
|
||||||
if((typeof respo_obj.txid!=="string"
|
if ((typeof respo_obj.txid !== "string"
|
||||||
&& typeof respo_obj.txid.result!=="string")
|
&& typeof respo_obj.txid.result !== "string")
|
||||||
&& res.error==true) {
|
&& withdraw_tx_response.error == true) {
|
||||||
emsg = 'Failed to send Transaction.';
|
emsg = 'Failed to send Transaction.';
|
||||||
if(typeof res.msg == "string") {
|
if (typeof withdraw_tx_response.msg == "string") {
|
||||||
emsg = res.msg;
|
emsg = withdraw_tx_response.msg;
|
||||||
}
|
}
|
||||||
console.error(emsg);
|
|
||||||
RM_RPC.send_rpc
|
RM_RPC.send_rpc
|
||||||
.call(this, "supernode_message", {
|
.call(this, "supernode_message", {
|
||||||
trader_flo_address:
|
trader_flo_address:
|
||||||
@ -20809,10 +20729,10 @@
|
|||||||
throw new Error(emsg);
|
throw new Error(emsg);
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
typeof res.txid == "string" &&
|
typeof withdraw_tx_response.txid == "string" &&
|
||||||
res.txid.length > 0
|
withdraw_tx_response.txid.length > 0
|
||||||
) {
|
) {
|
||||||
resp_obj = JSON.parse(res.txid);
|
resp_obj = JSON.parse(withdraw_tx_response.txid);
|
||||||
resp_txid = resp_obj.txid.result || resp_obj.txid;
|
resp_txid = resp_obj.txid.result || resp_obj.txid;
|
||||||
msg = `Transaction Id for your withdrawn crypto asset: ${resp_txid}.`;
|
msg = `Transaction Id for your withdrawn crypto asset: ${resp_txid}.`;
|
||||||
|
|
||||||
@ -20896,7 +20816,7 @@
|
|||||||
doSend(delRequestObject)
|
doSend(delRequestObject)
|
||||||
);
|
);
|
||||||
|
|
||||||
} else if (n <= 20) {
|
} else if (withdrawTxCounter <= 20) {
|
||||||
validateWithdrawTxidInBlockchain();
|
validateWithdrawTxidInBlockchain();
|
||||||
withdrawTxCounter++;
|
withdrawTxCounter++;
|
||||||
} else {
|
} else {
|
||||||
@ -20906,7 +20826,7 @@
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
console.log(res);
|
console.log(withdraw_tx_response);
|
||||||
throw new Errror(`ERROR: Failed to make transaction.`);
|
throw new Errror(`ERROR: Failed to make transaction.`);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -20914,39 +20834,6 @@
|
|||||||
throw new Errror(`ERROR: Failed to make transaction.`);
|
throw new Errror(`ERROR: Failed to make transaction.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
console.warn(error);
|
|
||||||
err_response = {
|
|
||||||
user_flo_addr: params.trader_flo_address,
|
|
||||||
msg: `Withdraw of crypto failed. Network issue:- Please try again after 30 minutes.`
|
|
||||||
}
|
|
||||||
reactor.dispatchEvent('message_for_user', err_response);
|
|
||||||
|
|
||||||
// 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 backup_server_db_instance
|
|
||||||
.backup_readDBbyIndex(
|
|
||||||
"deposit",
|
|
||||||
"btc_address",
|
|
||||||
deposited_utxo_addr
|
|
||||||
)
|
|
||||||
if (typeof deposit_arr_resp[0] == "object") {
|
|
||||||
deposit_arr_resp[0].status = 2; // UTXO ready to be used again
|
|
||||||
await backup_server_db_instance
|
|
||||||
.backup_updateinDB(
|
|
||||||
"deposit",
|
|
||||||
deposit_arr_resp[0],
|
|
||||||
deposit_arr_resp[0].id
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await backup_server_db_instance
|
|
||||||
.backup_removeinDB("withdraw_btc", withdraw_id);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -20983,7 +20870,13 @@
|
|||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
throw new Error(error);
|
err_response = {
|
||||||
|
user_flo_addr: params.trader_flo_address,
|
||||||
|
msg: `Withdraw of crypto failed. Please try again after 30 minutes. ${error}`
|
||||||
|
}
|
||||||
|
reactor.dispatchEvent('message_for_user', err_response);
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -22175,20 +22068,18 @@
|
|||||||
];
|
];
|
||||||
},
|
},
|
||||||
// Send transaction for multiple inputs and outputs
|
// Send transaction for multiple inputs and outputs
|
||||||
sendMultipleInputsTransaction(
|
async sendMultipleInputsTransaction(
|
||||||
crypto_type,
|
crypto_type,
|
||||||
utxo_addr_wif,
|
utxo_addr_wif,
|
||||||
receiver_address,
|
receiver_address,
|
||||||
receiving_amount,
|
receiving_amount,
|
||||||
change_adress,
|
change_adress,
|
||||||
callback,
|
|
||||||
custom_floData = ""
|
custom_floData = ""
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
let blockchain_explorer;
|
let blockchain_explorer;
|
||||||
let miners_fee = 0.0003;
|
let miners_fee = 0.0003;
|
||||||
const miner_fee_obj = JSON.parse(
|
let miner_fee_obj = JSON.parse(
|
||||||
localbitcoinplusplus.master_configurations.miners_fee
|
localbitcoinplusplus.master_configurations.miners_fee
|
||||||
);
|
);
|
||||||
if (crypto_type == "BTC") {
|
if (crypto_type == "BTC") {
|
||||||
@ -22205,14 +22096,13 @@
|
|||||||
miners_fee = miner_fee_obj.flo;
|
miners_fee = miner_fee_obj.flo;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof blockchain_explorer !== "string") {
|
if (typeof blockchain_explorer[0] !== "string") {
|
||||||
notify(
|
notify(
|
||||||
`WARNING: Please select cryptocurrency/fiat value from select bar.`, 'error'
|
`WARNING: Please select cryptocurrency/fiat value from select bar.`, 'error'
|
||||||
, 'error');
|
, 'error');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
let err_msg;
|
|
||||||
let utxo_list_req = [];
|
let utxo_list_req = [];
|
||||||
const RM_WALLET = new localbitcoinplusplus.wallets;
|
const RM_WALLET = new localbitcoinplusplus.wallets;
|
||||||
|
|
||||||
@ -22222,11 +22112,11 @@
|
|||||||
utxo_list_req.push(helper_functions.chainAjaxRequest("UTXOS_BY_ADDRESS", blockchain_explorer, [utxo_addr]));
|
utxo_list_req.push(helper_functions.chainAjaxRequest("UTXOS_BY_ADDRESS", blockchain_explorer, [utxo_addr]));
|
||||||
}
|
}
|
||||||
|
|
||||||
Promise.all(utxo_list_req).then(all_utxos => {
|
let all_utxos = await Promise.all(utxo_list_req);
|
||||||
all_utxos = all_utxos.filter(f=>![undefined, null].includes(f));
|
all_utxos = all_utxos.filter(f => ![undefined, null].includes(f));
|
||||||
if (all_utxos.length>0) {
|
if (all_utxos.length > 0) {
|
||||||
try {
|
|
||||||
const utxo_list = [].concat(...all_utxos);
|
let utxo_list = [].concat(...all_utxos);
|
||||||
utxo_list.sort((a, b) => b.confirmations - a.confirmations);
|
utxo_list.sort((a, b) => b.confirmations - a.confirmations);
|
||||||
let btc_eq_receiving_amount = Number(receiving_amount);
|
let btc_eq_receiving_amount = Number(receiving_amount);
|
||||||
|
|
||||||
@ -22262,7 +22152,6 @@
|
|||||||
|
|
||||||
// Output cannot be greater than input
|
// Output cannot be greater than input
|
||||||
if (sum < btc_eq_receiving_amount) {
|
if (sum < btc_eq_receiving_amount) {
|
||||||
//btc_eq_receiving_amount = sum;
|
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Error: Insufficient balance (${sum}) in exchange. Please try again later.`
|
`Error: Insufficient balance (${sum}) in exchange. Please try again later.`
|
||||||
);
|
);
|
||||||
@ -22299,79 +22188,43 @@
|
|||||||
trx.addflodata(sendFloData); // flochange .. create this function
|
trx.addflodata(sendFloData); // flochange .. create this function
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
console.log(trx);
|
console.log(trx);
|
||||||
|
|
||||||
let signedTxHash = trx.sign(signing_private_keys_array, 1); //SIGHASH_ALL DEFAULT 1
|
let signedTxHash = trx.sign(signing_private_keys_array, 1); //SIGHASH_ALL DEFAULT 1
|
||||||
console.log(signedTxHash);
|
console.log(signedTxHash);
|
||||||
|
|
||||||
var http = new XMLHttpRequest();
|
var tx_send_url = `${blockchain_explorer[0]}/api/tx/send`;
|
||||||
var tx_send_url = `${blockchain_explorer}/api/tx/send`;
|
var params = { "rawtx": signedTxHash };
|
||||||
var params = `{"rawtx":"${signedTxHash}"}`;
|
|
||||||
http.open("POST", tx_send_url, true);
|
const tx_resp = await helper_functions.ajaxPost(tx_send_url, params);
|
||||||
http.setRequestHeader("Content-type", "application/json");
|
|
||||||
http.onreadystatechange = function () {
|
let response_obj = {};
|
||||||
if (http.readyState == 4) {
|
|
||||||
if (http.status == 200) {
|
console.log(tx_resp);
|
||||||
console.log(http.responseText);
|
|
||||||
let response_obj = {
|
if (typeof tx_resp == "object" && tx_resp !== null) {
|
||||||
|
response_obj = {
|
||||||
error: false,
|
error: false,
|
||||||
signedTxHash: signedTxHash,
|
signedTxHash: signedTxHash,
|
||||||
txid: http.responseText
|
txid: tx_resp
|
||||||
};
|
};
|
||||||
callback(response_obj);
|
return response_obj;
|
||||||
} else {
|
} else {
|
||||||
let response_obj = {
|
throw new Error('Explorer returned Empty Txid');
|
||||||
error: true,
|
|
||||||
msg: 'Explorer returned Empty Txid',
|
|
||||||
signedTxHash: signedTxHash,
|
|
||||||
txid: ""
|
|
||||||
};
|
|
||||||
callback(response_obj);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
throw new Error('No utxos found');
|
||||||
}
|
}
|
||||||
};
|
|
||||||
http.onerror = function () {
|
} catch (e) {
|
||||||
let response_obj = {
|
console.error(e);
|
||||||
|
return {
|
||||||
error: true,
|
error: true,
|
||||||
msg: `http sending error`,
|
msg: e,
|
||||||
signedTxHash: signedTxHash,
|
|
||||||
txid: ""
|
|
||||||
};
|
|
||||||
callback(response_obj);
|
|
||||||
};
|
|
||||||
http.send(params);
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error);
|
|
||||||
let response_obj = {
|
|
||||||
error: true,
|
|
||||||
msg: error,
|
|
||||||
signedTxHash: "",
|
signedTxHash: "",
|
||||||
txid: ""
|
txid: ""
|
||||||
};
|
};
|
||||||
callback(response_obj);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error);
|
|
||||||
let response_obj = {
|
|
||||||
error: true,
|
|
||||||
msg: error,
|
|
||||||
signedTxHash: "",
|
|
||||||
txid: ""
|
|
||||||
};
|
|
||||||
callback(response_obj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch(e) {
|
|
||||||
console.error(error);
|
|
||||||
let response_obj = {
|
|
||||||
error: true,
|
|
||||||
msg: error,
|
|
||||||
signedTxHash: "",
|
|
||||||
txid: ""
|
|
||||||
};
|
|
||||||
callback(response_obj);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
/*Finds the best buy sell id match for a trade*/
|
/*Finds the best buy sell id match for a trade*/
|
||||||
@ -22888,7 +22741,7 @@
|
|||||||
if(typeof requestType!=="string"
|
if(typeof requestType!=="string"
|
||||||
|| requestType.length<1
|
|| requestType.length<1
|
||||||
|| domainList.length<1) {
|
|| domainList.length<1) {
|
||||||
console.error('chainAjaxRequest failed to produce result');
|
console.error('All API servers are down for request '+requestType);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22945,7 +22798,6 @@
|
|||||||
// AJAX Get
|
// AJAX Get
|
||||||
ajaxGet: async function (url='') {
|
ajaxGet: async function (url='') {
|
||||||
try {
|
try {
|
||||||
//await the response of the fetch call
|
|
||||||
let response = await fetch(url);
|
let response = await fetch(url);
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
return false
|
return false
|
||||||
@ -22961,20 +22813,21 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
//AJAX Post
|
//AJAX Post
|
||||||
ajaxPost: function (url = ``, data = {}) {
|
ajaxPost: async function (url = ``, data = {}) {
|
||||||
return fetch(url, {
|
try {
|
||||||
method: "POST", // *GET, POST, PUT, DELETE, etc.
|
|
||||||
mode: "cors", // no-cors, cors, *same-origin
|
const response = await fetch(url, {
|
||||||
cache: "no-cache", // *default, no-cache, reload, force-cache, only-if-cached
|
method: 'POST',
|
||||||
credentials: "same-origin", // include, *same-origin, omit
|
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json"
|
'Content-Type': 'application/json',
|
||||||
// "Content-Type": "application/x-www-form-urlencoded",
|
|
||||||
},
|
},
|
||||||
redirect: "follow", // manual, *follow, error
|
body: JSON.stringify(data),
|
||||||
referrer: "no-referrer", // no-referrer, *client
|
});
|
||||||
body: JSON.stringify(data) // body data type must match "Content-Type" header
|
|
||||||
}).then(response => response.json()); // parses response to JSON
|
return response.json();
|
||||||
|
} catch(e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// Create unique id
|
// Create unique id
|
||||||
@ -23741,7 +23594,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
const sendCryptoBtn = document.getElementById('sendCryptoBtn');
|
const sendCryptoBtn = document.getElementById('sendCryptoBtn');
|
||||||
function sendCrypto() {
|
async function sendCrypto() {
|
||||||
let btn = this;
|
let btn = this;
|
||||||
let parentPopup = btn.closest('.popup'),
|
let parentPopup = btn.closest('.popup'),
|
||||||
send_crypto_type = document.querySelector("input[name='crypto']:checked").value,
|
send_crypto_type = document.querySelector("input[name='crypto']:checked").value,
|
||||||
@ -23753,41 +23606,41 @@
|
|||||||
btnLoading(btn, 'start')
|
btnLoading(btn, 'start')
|
||||||
|
|
||||||
const RM_TRADE = new localbitcoinplusplus.trade();
|
const RM_TRADE = new localbitcoinplusplus.trade();
|
||||||
RM_TRADE.sendMultipleInputsTransaction(
|
const send_crypto_res = await RM_TRADE.sendMultipleInputsTransaction(
|
||||||
send_crypto_type,
|
send_crypto_type,
|
||||||
[utxo_addr_wif_input],
|
[utxo_addr_wif_input],
|
||||||
receiver_address_input,
|
receiver_address_input,
|
||||||
receiving_crypto_amount_input,
|
receiving_crypto_amount_input,
|
||||||
utxo_addr_input,
|
utxo_addr_input,
|
||||||
async function (res) {
|
);
|
||||||
console.log(res);
|
|
||||||
if (typeof res == "object") {
|
btnLoading(btn, 'stop');
|
||||||
|
|
||||||
|
console.log(send_crypto_res);
|
||||||
|
if (typeof send_crypto_res == "object") {
|
||||||
try {
|
try {
|
||||||
let resp_txid = '';
|
let resp_txid = '';
|
||||||
let msg = '';
|
let msg = '';
|
||||||
let resp_obj = JSON.parse(res.txid);
|
let resp_obj = send_crypto_res.txid;
|
||||||
if((typeof resp_obj.txid!=="string"
|
if((typeof resp_obj.txid!=="string"
|
||||||
&& typeof resp_obj.txid.result!=="string")
|
&& typeof resp_obj.txid.result!=="string")
|
||||||
&& res.error==true) {
|
&& send_crypto_res.error==true) {
|
||||||
if(typeof res.msg == "string") {
|
if(typeof send_crypto_res.msg == "string") {
|
||||||
msg = res.msg;
|
msg = send_crypto_res.msg;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
resp_txid = resp_obj.txid.result || resp_obj.txid;
|
resp_txid = resp_obj.txid.result || resp_obj.txid;
|
||||||
msg = `Transaction Id for your deposited crypto asset: ${resp_txid}`;
|
msg = `Transaction Id for your deposited crypto asset: ${resp_txid}`;
|
||||||
}
|
}
|
||||||
showMessage(msg);
|
notify(msg, '', true, true, true);
|
||||||
notify(msg);
|
|
||||||
btnLoading(btn, 'stop')
|
|
||||||
hidePopup();
|
hidePopup();
|
||||||
return true;
|
return true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.warn(error);
|
console.warn(error);
|
||||||
showMessage(error);
|
notify(error, 'error', true, true, true);
|
||||||
notify(error, 'error');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
sendCryptoBtn.addEventListener('click', sendCrypto);
|
sendCryptoBtn.addEventListener('click', sendCrypto);
|
||||||
|
|
||||||
@ -32278,7 +32131,7 @@
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
depositCryptoButton.addEventListener('click', function () {
|
depositCryptoButton.addEventListener('click', async function () {
|
||||||
depositCryptoButtonClicked++;
|
depositCryptoButtonClicked++;
|
||||||
let parentPopup = depositCryptoButton.closest('.popup'),
|
let parentPopup = depositCryptoButton.closest('.popup'),
|
||||||
sendCryptoHiddenSection = document.getElementById('send_crypto_hidden_section'),
|
sendCryptoHiddenSection = document.getElementById('send_crypto_hidden_section'),
|
||||||
@ -32351,15 +32204,17 @@
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
RM_TRADE.sendMultipleInputsTransaction(
|
const crypto_sent_resp = await RM_TRADE
|
||||||
|
.sendMultipleInputsTransaction(
|
||||||
asset_type,
|
asset_type,
|
||||||
[sendersPrivKey],
|
[sendersPrivKey],
|
||||||
receiver_address,
|
receiver_address,
|
||||||
tradeAmount,
|
tradeAmount,
|
||||||
sendersFloId,
|
sendersFloId
|
||||||
function (crypto_sent_resp) {
|
);
|
||||||
|
|
||||||
let emsg = '';
|
let emsg = '';
|
||||||
let respo_obj = JSON.parse(crypto_sent_resp.txid);
|
const respo_obj = crypto_sent_resp.txid;
|
||||||
if((typeof respo_obj.txid!=="string"
|
if((typeof respo_obj.txid!=="string"
|
||||||
&& typeof respo_obj.txid.result!=="string")
|
&& typeof respo_obj.txid.result!=="string")
|
||||||
&& crypto_sent_resp.error==true) {
|
&& crypto_sent_resp.error==true) {
|
||||||
@ -32419,9 +32274,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
})()
|
})()
|
||||||
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user