modified logic of cash in backup

This commit is contained in:
Abhishek Sinha 2019-11-21 14:40:47 +05:30
parent 24dcc080d6
commit 36d45a102f
2 changed files with 60 additions and 118 deletions

1
.gitignore vendored
View File

@ -9,5 +9,6 @@ supernode/test/in/index4.html
supernode/flosend.html supernode/flosend.html
supernode/index1 (copy).html supernode/index1 (copy).html
supernode/websocket_chat supernode/websocket_chat
supernode/cash_payments_handler2.html
.vscode/ .vscode/
supernode/test/ supernode/test/

View File

@ -11514,7 +11514,9 @@
btc_testnet: "https://test-insight.bitpay.com", btc_testnet: "https://test-insight.bitpay.com",
flo_mainnet: "http://flosight.duckdns.org", flo_mainnet: "http://flosight.duckdns.org",
//flo_testnet: "http://testnet-flosight.duckdns.org" //flo_testnet: "http://testnet-flosight.duckdns.org"
flo_testnet: "https://testnet.flocha.in" flo_testnet: "https://testnet.flocha.in",
//flo_api_testnet: "https://ranchimallflo-testnet.duckdns.org",
flo_api_testnet: "ranchimall1.duckdns.org:5109"
}, },
writable: false, writable: false,
configurable: false, configurable: false,
@ -15668,17 +15670,12 @@
JSON.stringify(receivedTradeInfo) JSON.stringify(receivedTradeInfo)
); );
receivedTradeInfo[ receivedTradeInfo["depositDataHash"] = receivedTradeInfoHash;
"depositDataHash" receivedTradeInfo["order_validator_sign"] = RM_WALLET.sign(
] = receivedTradeInfoHash;
receivedTradeInfo[
"order_validator_sign"
] = RM_WALLET.sign(
receivedTradeInfoHash, receivedTradeInfoHash,
localbitcoinplusplus.wallets.MY_SUPERNODE_PRIVATE_KEY localbitcoinplusplus.wallets.MY_SUPERNODE_PRIVATE_KEY
); );
receivedTradeInfo["order_validator_public_key"] = receivedTradeInfo["order_validator_public_key"] = su_data.myLocalFLOPublicKey;
su_data.myLocalFLOPublicKey;
try { try {
const cashiersList = JSON.parse( const cashiersList = JSON.parse(
@ -15698,8 +15695,7 @@
); );
} }
receivedTradeInfo.cashier_upi = receivedTradeInfo.cashier_upi = cashiersList[getAPaymentHandler];
cashiersList[getAPaymentHandler];
receivedTradeInfo.cashier_pubKey = getAPaymentHandler; receivedTradeInfo.cashier_pubKey = getAPaymentHandler;
const receivedTradeInfoResp = await addDB( const receivedTradeInfoResp = await addDB(
"cash_deposits", "cash_deposits",
@ -17243,108 +17239,46 @@
); );
break; break;
case "deposit_cash_request": case "deposit_cash_request":
RM_RPC.filter_legit_requests( console.info(`INFO: Cash deposits are prohibited in backup mode.`);
RM_RPC.filter_legit_backup_requests(
params.trader_flo_address, params.trader_flo_address,
async function(is_valid_request) { async function(is_valid_request) {
if (is_valid_request !== true) return false; if (is_valid_request !== true) return false;
// This code will only run for supernodes let receivedTradeInfo = { ...params };
if (
typeof params.depositing_amount !== "undefined" &&
localbitcoinplusplus.master_configurations.tradableAsset2.includes(
params.currency
) &&
typeof localbitcoinplusplus.master_configurations
.validTradingAmount !== "undefined" &&
localbitcoinplusplus.master_configurations.validTradingAmount.includes(
parseFloat(params.depositing_amount)
) &&
typeof params.trader_flo_address == "string" &&
params.trader_flo_address.length > 0 &&
typeof params.user_upi == "string" &&
params.user_upi.length > 0
) {
params.id = helper_functions.unique_id();
params.status = 1;
let receivedTradeInfo = { ...params };
const su_data = await readDB("localbitcoinUser", "00-01"); let receivedTradeInfoHash = Crypto.SHA256(
JSON.stringify(receivedTradeInfo)
);
if ( receivedTradeInfo["depositDataHash"] = receivedTradeInfoHash;
typeof su_data == "object" && receivedTradeInfo["order_validator_sign"] = RM_WALLET.sign(
typeof su_data.myLocalFLOPublicKey == "string" && receivedTradeInfoHash,
su_data.myLocalFLOPublicKey.length > 0 && localbitcoinplusplus.wallets.MY_SUPERNODE_PRIVATE_KEY
localbitcoinplusplus.master_configurations.supernodesPubKeys.includes( );
su_data.myLocalFLOPublicKey receivedTradeInfo["order_validator_public_key"] =
) su_data.myLocalFLOPublicKey;
) {
let receivedTradeInfoHash = Crypto.SHA256(
JSON.stringify(receivedTradeInfo)
);
receivedTradeInfo[ let deposit_response_object = {
"depositDataHash" error: true,
] = receivedTradeInfoHash; method: "deposit_cash_request_response",
receivedTradeInfo[ msg: "Primary server is temporarily down. For now you can only trade, deposit and withdraw cryptos.",
"order_validator_sign" data: null,
] = RM_WALLET.sign( receiver_flo_address: receivedTradeInfo.trader_flo_address,
receivedTradeInfoHash, trader_flo_address: receivedTradeInfo.trader_flo_address
localbitcoinplusplus.wallets.MY_SUPERNODE_PRIVATE_KEY };
);
receivedTradeInfo["order_validator_public_key"] =
su_data.myLocalFLOPublicKey;
try { RM_RPC.send_rpc
const cashiersList = JSON.parse( .call(
localbitcoinplusplus.master_configurations.cashiers this,
); "deposit_cash_request_response",
const getAPaymentHandler = randomNoRepeats( deposit_response_object
Object.keys(cashiersList) )
)(); .then(deposit_request_response =>
doSend(deposit_request_response)
if ( );
!Object.keys(cashiersList).includes( return true;
getAPaymentHandler
)
) {
throw new Error(
`ERROR: ${getAPaymentHandler} is not recognized as any Cashier's Public Key.`
);
}
receivedTradeInfo.cashier_upi =
cashiersList[getAPaymentHandler];
receivedTradeInfo.cashier_pubKey = getAPaymentHandler;
const receivedTradeInfoResp = await backup_server_db_instance
.backup_addDB("cash_deposits", receivedTradeInfo);
let deposit_response_object = {
error: false,
method: "deposit_cash_request_response",
msg: receivedTradeInfo.cashier_upi,
data: receivedTradeInfoResp,
receiver_flo_address:
receivedTradeInfo.trader_flo_address,
trader_flo_address:
receivedTradeInfo.trader_flo_address
};
RM_RPC.send_rpc
.call(
this,
"deposit_cash_request_response",
deposit_response_object
)
.then(deposit_request_response =>
doSend(deposit_request_response)
);
return true;
} catch (e) {
console.error(e);
}
}
}
} }
); );
break; break;
@ -18524,8 +18458,10 @@
// Validate Flo txid // Validate Flo txid
const validate_flo_txid = await helper_functions const validate_flo_txid = await helper_functions
.ajaxGet(`https://ranchimallflo-testnet.duckdns.org/api/v1.0/getTransactionDetails/${params.flo_txid}`); .ajaxGet(`${flo_api_testnet}/api/v1.0/getTransactionDetails/${params.flo_txid}`);
/** IMP: CHECK WHETHER VIN IS A VALID SUPERNODE FLO ID HERE **/
if(typeof validate_flo_txid !== "object" if(typeof validate_flo_txid !== "object"
|| typeof validate_flo_txid.transactionDetails !== "object" || typeof validate_flo_txid.transactionDetails !== "object"
|| typeof validate_flo_txid.transactionDetails.floData !== "string" || typeof validate_flo_txid.transactionDetails.floData !== "string"
@ -18533,9 +18469,10 @@
) throw new Error(`Error: Txid ${params.flo_txid} not found in Blockchain.`); ) throw new Error(`Error: Txid ${params.flo_txid} not found in Blockchain.`);
let amount_deposited = Number(validate_flo_txid.transactionDetails.floData.match(/\d+/g)[0]); let amount_deposited = Number(validate_flo_txid.transactionDetails.floData.match(/\d+/g)[0]);
if(typeof amount_deposited !== "number" || amount_deposited < 1 || amount_deposited===NaN) {
amount_deposited = cash_deposited_by_user; // if(typeof amount_deposited !== "number" || amount_deposited < 1 || amount_deposited===NaN) {
} // amount_deposited = cash_deposited_by_user;
// }
amount_deposited = Number(amount_deposited); amount_deposited = Number(amount_deposited);
@ -18564,7 +18501,12 @@
if (typeof updateUserBalance!=="object" && updateUserBalance==null) if (typeof updateUserBalance!=="object" && updateUserBalance==null)
throw new Error(`Error: Failed to update balance of User Cash Id: ${user_cash_id}.`); throw new Error(`Error: Failed to update balance of User Cash Id: ${user_cash_id}.`);
_removeinDB("cash_deposits", params.deposit_id); if (localbitcoinplusplus.wallets.my_local_flo_address!==parent_supernode) {
user_deposit_req.token_transfer_txid = params.flo_txid;
_updateinDB("cash_deposits", user_deposit_req);
} else {
_removeinDB("cash_deposits", params.deposit_id);
}
// 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 = {
@ -23429,7 +23371,7 @@
} }
break; break;
case "deposit_cash_request": case "deposit_cash_request":
response_from_sever = RM_RPC.receive_rpc_response.call( response_from_sever = RM_RPC.backup_receive_rpc_response.call(
this, this,
JSON.stringify(res_obj) JSON.stringify(res_obj)
); );
@ -23448,15 +23390,13 @@
resp.data.order_validator_public_key resp.data.order_validator_public_key
) )
) { ) {
addDB("cash_deposits", resp.data);
readDB("localbitcoinUser", "00-01").then(function(user) { readDB("localbitcoinUser", "00-01").then(function(user) {
if ( if (
typeof user == "object" && typeof user == "object" &&
user.myLocalFLOAddress == resp.data.trader_flo_address user.myLocalFLOAddress == resp.data.trader_flo_address
) { ) {
let counterTraderAccountAddress = let counterTraderAccountAddress = resp.msg;
`Please pay the amount to following UPI ID: ${resp.msg}`;
showMessage(counterTraderAccountAddress); showMessage(counterTraderAccountAddress);
modalWindow(counterTraderAccountAddress); modalWindow(counterTraderAccountAddress);
} }
@ -26497,11 +26437,11 @@
localbitcoinplusplus.kademlia localbitcoinplusplus.kademlia
.determineClosestSupernode( .determineClosestSupernode(
res_obj.params[0].trader_flo_address res_obj.params[0].trader_flo_address,
localbitcoinplusplus.master_configurations.supernodesPubKeys.length
) )
.then(async my_closest_su_list => { .then(async subject_floId_closest_su_list => {
const primarySupernodeOfThisUser = const primarySupernodeOfThisUser = subject_floId_closest_su_list[0].data.id;
my_closest_su_list[0].data.id;
let _readAllDB = readAllDB; let _readAllDB = readAllDB;
if ( if (
@ -26511,6 +26451,7 @@
primarySupernodeOfThisUser !== primarySupernodeOfThisUser !==
localbitcoinplusplus.wallets.my_local_flo_address localbitcoinplusplus.wallets.my_local_flo_address
) { ) {
if ( if (
typeof localbitcoinplusplus.newBackupDatabase.db[ typeof localbitcoinplusplus.newBackupDatabase.db[
primarySupernodeOfThisUser primarySupernodeOfThisUser