modified withdraw cash to update cash balance before tx

This commit is contained in:
Abhishek Sinha 2020-05-24 21:37:45 +05:30
parent 3a684568d8
commit b58b7b37f5
2 changed files with 495 additions and 443 deletions

View File

@ -12030,14 +12030,20 @@
#!#tradableAsset1=BTC,FLO,BTC_TEST,FLO_TEST#!#tradableAsset2=INR,USD, #!#tradableAsset1=BTC,FLO,BTC_TEST,FLO_TEST#!#tradableAsset2=INR,USD,
#!#validTradingAmount=10,50,100,#!#btcTradeMargin=5000 #!#validTradingAmount=10,50,100,#!#btcTradeMargin=5000
#!#MaxBackups=1 #!#MaxBackups=1
#!#waitTime={"normaldelay":180000, "exportdelay":300000, "syncdelay":600000, "hugedelay":1200000}
#!#ordersLife={"trade":300000, "cryptoDeposit":900000, "cryptoWithdraw":300000, "cashDeposit":900000, "cashWithdraw":900000} #!#ordersLife={"trade":300000, "cryptoDeposit":900000, "cryptoWithdraw":300000, "cashDeposit":900000, "cashWithdraw":900000}
#!#miners_fee={"btc":0.0005, "flo":0.001} #!#miners_fee={"btc":0.0005, "flo":0.001}
#!#supernodesPubKeys=0315C3A20FE7096CC2E0F81A80D5F1A687B8F9EFA65242A0B0881E1BA3EE7D7D53, #!#supernodesPubKeys=026FCC6CFF6EB3A39E54BEB6E13FC2F02C3A93F4767AA80E49E7E876443F95AE5F,0349B08AA1ABDCFFB6D78CD7C949665AD2FF065EA02B3C6C47A5E9592C9A1C6BCB,
026FCC6CFF6EB3A39E54BEB6E13FC2F02C3A93F4767AA80E49E7E876443F95AE5F, 039B4AA00DBFC0A6631DE6DA83526611A0E6B857D3579DF840BBDEAE8B6898E3B6,0315C3A20FE7096CC2E0F81A80D5F1A687B8F9EFA65242A0B0881E1BA3EE7D7D53
#!#specialNodes=02348523EB008BD37BF297AA360757062CB9D153C371EE727349A02F0B67910613,03C38E6523D6A2C45E00E60DC072E4D4340007F8A0026F134DCBBC670E4C44D31C
#!#cashiers={"032871A74D2DDA9D0DE7135F58B5BD2D7F679D2CCA20EA7909466D1A6912DF4022":{"upi":"johnDoe@upi", "currencies":["INR"], "is_live":false}, #!#cashiers={"032871A74D2DDA9D0DE7135F58B5BD2D7F679D2CCA20EA7909466D1A6912DF4022":{"upi":"johnDoe@upi", "currencies":["INR"], "is_live":false},
"03DB4A12EB543B293DDBB0CE314C46C36D6761294AFBB7264A6D78F710FFD97CF0":{"upi":"janeDoe@upi", "currencies":["INR", "USD"], "is_live":false}} "03DB4A12EB543B293DDBB0CE314C46C36D6761294AFBB7264A6D78F710FFD97CF0":{"upi":"janeDoe@upi", "currencies":["INR", "USD"], "is_live":false}}
#!#ShamirsMaxShares=8#!#supernodeSeeds={"ranchimall1":{"ip":"127.0.0.1:9111","kbucketId":"oZxHcbSf1JC8t5GjutopWYXs7C6Fe9p7ps"}, #!#ShamirsMaxShares=8#!#supernodeSeeds={
"ranchimall1":{"ip":"127.0.0.1:9111","kbucketId":"oZxHcbSf1JC8t5GjutopWYXs7C6Fe9p7ps"},
"ranchimall3":{"ip":"127.0.0.1:9113","kbucketId":"odYA6KagmbokSh9GY7yAfeTUZRtZLwecY1"},
"ranchimall5":{"ip":"127.0.0.1:9115","kbucketId":"oMhv5sAzqg77sYHxmUGZWKRrVo4P4JQduS"},
"ranchimall6":{"ip":"127.0.0.1:9116","kbucketId":"oV1wCeWca3VawbBTfUGKA7Vd368PATnKAx"}}`; "ranchimall6":{"ip":"127.0.0.1:9116","kbucketId":"oV1wCeWca3VawbBTfUGKA7Vd368PATnKAx"}}`;
///return callback(localStorage.lppconf);
return callback(text); return callback(text);
if(ENVR==='LIVE') { if(ENVR==='LIVE') {

View File

@ -16849,6 +16849,8 @@
readDB("cash_balances", trader_cash_id).then(function ( readDB("cash_balances", trader_cash_id).then(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 ==
@ -16856,6 +16858,7 @@
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));
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
); );
@ -16869,6 +16872,16 @@
withdrawing_cash_amount > 0 && withdrawing_cash_amount > 0 &&
withdrawer_cash_balance >= withdrawing_cash_amount withdrawer_cash_balance >= withdrawing_cash_amount
) { ) {
// Deduct balance of withdrawer
cash_balances_res.cash_balance -= helper_functions.truncateDecimals(
withdrawing_cash_amount, 2
);
const withdrawer_cash_data = await updateinDB(
"cash_balances",
cash_balances_res
);
// Get a cashier // Get a cashier
const cashiersList = JSON.parse( const cashiersList = JSON.parse(
localbitcoinplusplus.master_configurations localbitcoinplusplus.master_configurations
@ -16982,14 +16995,6 @@
} }
if (msg.length > 0) { if (msg.length > 0) {
// Deduct balance of withdrawer
cash_balances_res.cash_balance -= helper_functions.truncateDecimals(
withdrawing_cash_amount, 2
);
const withdrawer_cash_data = await updateinDB(
"cash_balances",
cash_balances_res
);
const update_cash_balance_obj = { const update_cash_balance_obj = {
withdrawer_cash_data: withdrawer_cash_data withdrawer_cash_data: withdrawer_cash_data
@ -17056,6 +17061,11 @@
return false; return false;
} }
} catch (e) { } catch (e) {
updateinDB("cash_balances",
old_cash_balances_res,
old_cash_balances_res.id,
false, false
);
throw new Error(e); throw new Error(e);
} }
} }
@ -17063,7 +17073,12 @@
flo_withdraw_comment flo_withdraw_comment
); );
} catch (error) { } catch (error) {
console.log(error); updateinDB("cash_balances",
old_cash_balances_res,
old_cash_balances_res.id,
false, false
);
throw new Error(error);
} }
} }
}); });
@ -17079,6 +17094,16 @@
throw new Error(err_msg); throw new Error(err_msg);
} }
} }
} catch(e) {
console.error(e);
updateinDB("cash_balances",
old_cash_balances_res,
old_cash_balances_res.id,
false, false
);
}
}); });
} else { } else {
err_msg = "Unknown asset withdraw request error."; err_msg = "Unknown asset withdraw request error.";
@ -18604,6 +18629,7 @@
backup_server_db_instance backup_server_db_instance
.backup_readDB("cash_balances", trader_cash_id) .backup_readDB("cash_balances", trader_cash_id)
.then(function (cash_balances_res) { .then(function (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 ==
@ -18612,6 +18638,7 @@
"number" && "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));
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
); );
@ -18626,6 +18653,14 @@
withdrawer_cash_balance >= withdrawer_cash_balance >=
withdrawing_cash_amount withdrawing_cash_amount
) { ) {
// Deduct balance of withdrawer
cash_balances_res.cash_balance -= helper_functions.truncateDecimals(
withdrawing_cash_amount, 2
);
const withdrawer_cash_data = await backup_server_db_instance.backup_updateinDB(
"cash_balances",
cash_balances_res
);
// Get a cashier // Get a cashier
const cashiersList = JSON.parse( const cashiersList = JSON.parse(
localbitcoinplusplus.master_configurations localbitcoinplusplus.master_configurations
@ -18739,14 +18774,6 @@
} }
if (msg.length > 0) { if (msg.length > 0) {
// Deduct balance of withdrawer
cash_balances_res.cash_balance -= helper_functions.truncateDecimals(
withdrawing_cash_amount, 2
);
const withdrawer_cash_data = await backup_server_db_instance.backup_updateinDB(
"cash_balances",
cash_balances_res
);
const update_cash_balance_obj = { const update_cash_balance_obj = {
withdrawer_cash_data: withdrawer_cash_data withdrawer_cash_data: withdrawer_cash_data
@ -18817,14 +18844,24 @@
return false; return false;
} }
} catch (e) { } catch (e) {
throw new Error(e); console.error(e);
backup_server_db_instance.backup_updateinDB("cash_balances",
old_cash_balances_res,
old_cash_balances_res.id,
false, false
);
} }
} }
}, },
flo_withdraw_comment flo_withdraw_comment
); );
} catch (error) { } catch (error) {
console.log(error); console.error(error);
backup_server_db_instance.backup_updateinDB("cash_balances",
old_cash_balances_res,
old_cash_balances_res.id,
false, false
);
} }
} }
} }
@ -18841,6 +18878,15 @@
throw new Error(err_msg); throw new Error(err_msg);
} }
} }
} catch(e) {
console.error(e);
backup_server_db_instance.backup_updateinDB("cash_balances",
old_cash_balances_res,
old_cash_balances_res.id,
false, false
);
}
}); });
} else { } else {
err_msg = "withdraw request error"; err_msg = "withdraw request error";