diff --git a/supernode/cash_payments_handler.html b/supernode/cash_payments_handler.html
index 1cd5d2d..23f3da8 100644
--- a/supernode/cash_payments_handler.html
+++ b/supernode/cash_payments_handler.html
@@ -2,7 +2,7 @@
-
+
Handling Cash Payments For Localbitcoinplusplus
@@ -10,8 +10,50 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -9722,7 +9941,7 @@
return false;
},
manually_assign_my_private_key: function() {
- readDB('localbitcoinUser', '00-01').then(usr=>{
+ readDB('paymentsHandlerDetails', '00-01').then(usr=>{
if (typeof usr=="object" && usr.myLocalFLOAddress.length>0) {
const RM_WALLET = new localbitcoinplusplus.wallets;
const pk_manual = prompt("Please enter your private key: ");
@@ -9751,6 +9970,112 @@
Promise.reject(mes);
});
},
+ reset_flo_keys: () => {
+ updateinDB('paymentsHandlerDetails', {
+ id: "00-01",
+ myLocalFLOAddress: "",
+ myLocalFLOPublicKey: "",
+ }, "00-01").then(() => true).catch(e => false);
+ return Promise.resolve(true);
+ },
+ }
+
+ /* CODE_JUNCTION: RPC */
+
+ var Rpc = localbitcoinplusplus.rpc = function () {
+ this.rpc_req_id;
+ this.valid_job = ["trade_buy", "trade_sell", "sync"];
+ }
+ Rpc.prototype = {
+
+ send_rpc(method, ...params) {
+
+ return new Promise((resolve, reject)=>{
+ var request = new JSON_RPC.Request(method, params);
+ var id = request.id;
+ this.rpc_req_id = id;
+ request.globalParams.rpc_protocol = '__FOR__CASHIER__';
+
+ (async function(request) {
+
+ if (typeof localbitcoinplusplus.wallets.my_local_flo_address == "string") {
+ request.globalParams.senderFloId = localbitcoinplusplus.wallets.my_local_flo_address;
+ }
+
+ if (typeof params[0].receiver_flo_address == "string") {
+ request.globalParams.receiverFloId = params[0].receiver_flo_address;
+ if (typeof request.globalParams.receiversList == "object") {
+ if(typeof request.globalParams["receiversList"] !== "object") request.globalParams["receiversList"] = [];
+ if (!request.globalParams.receiversList.includes(params[0].receiver_flo_address)) {
+ request.globalParams.receiversList.push(params[0].receiver_flo_address);
+ }
+ }
+ }
+
+ return resolve(request.toString());
+
+ })(request);
+ })
+
+ },
+
+ filter_legit_requests: function (flo_id=null, callback) {
+ if (typeof localbitcoinplusplus.wallets.MY_SUPERNODE_PRIVATE_KEY === "string" &&
+ localbitcoinplusplus.wallets.MY_SUPERNODE_PRIVATE_KEY.length > 0
+ ) {
+ const RM_WALLET = new localbitcoinplusplus.wallets;
+ let user_keys = RM_WALLET.generateFloKeys(localbitcoinplusplus.wallets.MY_SUPERNODE_PRIVATE_KEY);
+ if (typeof user_keys == "object" && typeof user_keys.pubKeyHex == "string") {
+ if (localbitcoinplusplus.master_configurations.supernodesPubKeys.includes(user_keys.pubKeyHex)) {
+ if (typeof flo_id !== null || typeof flo_id !== 'undefined') {
+ localbitcoinplusplus.kademlia.determineClosestSupernode(flo_id, 4)
+ .then(my_closest_su=>{
+ if (user_keys.address === my_closest_su[0].data.id) {
+ return callback(true);
+ } else {
+ let su_arr = my_closest_su.map(m=>m.data.id);
+ if(su_arr.includes(flo_id)) {
+ return callback(true);
+ } else {
+ return callback(false);
+ }
+ }
+ });
+ } else {
+ return callback(false);
+ }
+ }
+ }
+ } else {
+ return callback(false);
+ }
+ },
+
+ async receive_rpc_response(request) {
+ var request = JSON.parse(request);
+ var params = request.params[0];
+ var method = request.method;
+
+ if (typeof params == "object" && typeof method == "string") {
+
+ const RM_WALLET = new localbitcoinplusplus.wallets;
+ const RM_RPC = new localbitcoinplusplus.rpc;
+
+ let respective_trader_id = '';
+ if (typeof params.trader_flo_address == "string") respective_trader_id = params.trader_flo_address;
+ request.response = {};
+ let err_msg;
+
+ let recvr_flo_id = params.receiver_flo_address || request.globalParams.receiverFloId;
+ if (typeof recvr_flo_id == "string"
+ && recvr_flo_id.length > 0
+ && recvr_flo_id !== localbitcoinplusplus.wallets.my_local_flo_address) return;
+
+ console.log(request);
+
+ }
+ },
+
}
// kbucket functions
@@ -9762,22 +10087,21 @@
k.splice(-4, 4)
return Crypto.util.bytesToHex(k)
},
- launchSupernodesKBucket: function() {
-
- localbitcoinplusplus.master_configurations.supernodesPubKeys.map(pubKey=>{
- return new Promise((resolve, reject)=>{
- try {
- let flo_id = bitjs.FLO_TEST.pubkey2address(pubKey);
- let kname = `SKBucket_${pubKey}`;
- const KBucketId = localbitcoinplusplus.kademlia.floIdToKbucketId('FLO_TEST', flo_id);
- const kbOptions = { localNodeId: KBucketId }
- window[kname] = new BuildKBucket(kbOptions);
- resolve(true);
- } catch (error) {
- reject(error);
- }
- })
- })
+ launchKBucket: function() {
+ return new Promise((resolve, reject)=>{
+ try {
+ const master_flo_pubKey = localbitcoinplusplus.master_configurations.masterFLOPubKey;
+ const master_flo_addr = bitjs.FLO_TEST.pubkey2address(master_flo_pubKey);
+ if(typeof master_flo_addr !== "string") return reject(false);
+ const SuKBucketId = localbitcoinplusplus.kademlia.floIdToKbucketId('FLO_TEST', master_flo_addr);
+ const SukbOptions = { localNodeId: SuKBucketId }
+ window.supernodeKBucket = new BuildKBucket(SukbOptions);
+
+ resolve(true);
+ } catch (error) {
+ reject(error);
+ }
+ });
},
addContact: function (id, data, KB=KBucket) {
const contact = {
@@ -9843,7 +10167,10 @@
if (typeof supernodeSeeds !== "object") reject("Failed to get supernode seeds.");
let supernodeSeedsObj = JSON.parse(supernodeSeeds);
nearestSupernodeAddresslist = Object.values(supernodeSeedsObj);
- nearestSupernodeAddresslist.map(m=>updateinDB('supernodesList', m));
+ nearestSupernodeAddresslist.map((m, i)=>{
+ m.id = i+1;
+ updateinDB('supernodesList', m).catch(e=>{throw new Error(e)});
+ });
}
resolve(nearestSupernodeAddresslist);
});
@@ -9892,7 +10219,6 @@
})
},
-
}
/* CODE_JUNCTION: Indexed DB */
@@ -9938,6 +10264,8 @@
unique: true
});
objectStore.put({
+ id: "00-01",
+ myLocalFLOAddress: "",
myLocalFLOPublicKey: "",
upiID: "",
last_tx_time: "",
@@ -9982,7 +10310,7 @@
var objectStore = db.createObjectStore("supernodesList", {
keyPath: 'id'
});
- objectStore.createIndex('trader_flo_address', 'trader_flo_address', {
+ objectStore.createIndex('kbucketId', 'kbucketId', {
unique: true
});
objectStore.createIndex('ip', 'ip', {
@@ -10179,6 +10507,14 @@
}
function onOpen(evt) {
+ readAllDB('supernodesList').then(list=>{
+ list.some(m=>{
+ let ws_res = `ws://${m.ip}:${m.port}/`;
+ if(ws_res==websocket.url)
+ localbitcoinplusplus.CONNECTED_SUPERNODE_FLO_ADDRESS
+ = m.kbucketId;
+ });
+ });
console.info(`INFO: Connected succesfully to ${evt.srcElement.url}.`)
}
@@ -10192,14 +10528,147 @@
}
}
- function onMessage(evt) {
- console.log(evt);
+ async function onMessage(evt) {
+ var response = evt.data || evt;
+ console.log('RESPONSE: ' + response);
+
+ let is_message_for_cashier = response.search('__FOR__CASHIER__');
+ if (!is_message_for_cashier) return;
+
+ var res_pos = response.indexOf('{');
+ if (res_pos >= 0) {
+ var res = response.substr(res_pos);
+ try {
+ var res_obj = JSON.parse(res);
+
+ if (typeof res_obj.globalParams !== "object"
+ || (localbitcoinplusplus.master_configurations.supernodesPubKeys
+ .includes(localbitcoinplusplus.wallets.my_local_flo_public_key)
+ && typeof res_obj.globalParams.receiversList == "object"
+ && !res_obj.globalParams.receiversList
+ .includes(localbitcoinplusplus.wallets.my_local_flo_address)
+ )) return;
+
+ if (typeof res_obj.globalParams.receiverFloId=="string"
+ && res_obj.globalParams.receiverFloId !==
+ localbitcoinplusplus.wallets.my_local_flo_address) return;
+
+ const isIncomingMessageValid = await validateIncomingMessage(res);
+ console.log("isIncomingMessageValid: ", isIncomingMessageValid);
+
+ if (!isIncomingMessageValid) return;
+
+ if(typeof res_obj.globalParams.senderFloId !=="string")
+ throw new Error(`WARNING: The request did not contain sender FLO Id. Request Aborted.`);
+
+ if (typeof res_obj.method !== "undefined") {
+ let response_from_sever;
+
+ const RM_WALLET = new localbitcoinplusplus.wallets;
+ const RM_RPC = new localbitcoinplusplus.rpc;
+
+ switch (res_obj.method) {
+ case "":
+
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ } catch(e) {
+ throw new Error(e);
+ }
+ }
}
function onError(evt) {
console.error(`ERROR: Websocket Connection to ${evt.srcElement.url} returned error.`);
}
+ function doSend(message="") {
+
+ let finalMessage = message;
+
+ const msgObj = JSON.parse(message);
+
+ const RM_WALLET = new localbitcoinplusplus.wallets;
+
+ message = JSON.stringify(msgObj);
+ const message256hash = Crypto.SHA256(message);
+
+ if(typeof localbitcoinplusplus.wallets.MY_SUPERNODE_PRIVATE_KEY !== "string")
+ throw new Error(`WARNING: Private key could not be found.`);
+
+ const nodeSignedMessage = RM_WALLET.sign(message256hash, localbitcoinplusplus.wallets.MY_SUPERNODE_PRIVATE_KEY);
+
+ msgObj.nodeMessage256hash = message256hash;
+ msgObj.nodeSignedMessage = nodeSignedMessage;
+ msgObj.nodePubKey = localbitcoinplusplus.wallets.my_local_flo_public_key;
+
+ finalMessage = JSON.stringify(msgObj);
+
+ // The message is for usernodes and all backup supernodes
+ try {
+ websocket.send(finalMessage);
+
+ } catch(error) {
+ throw new Error(error);
+ }
+
+ console.log("SENT: " + finalMessage);
+
+ }
+
+ function validateIncomingMessage(message) {
+ return new Promise((resolve, reject)=>{
+ if(message.length <1) {
+ showMessage(`WARNING: The incoming websocket message on was empty.`);
+ reject(false)};
+ const request_array = ['send_back_shamirs_secret_supernode_pvtkey',
+ 'retrieve_shamirs_secret_supernode_pvtkey',
+ 'store_shamirs_secret_pvtkey_shares'];
+
+ try {
+ const msgObj = JSON.parse(message);
+
+ if (request_array.includes(msgObj.method)) return resolve(true);
+
+ const getFloId = bitjs.FLO_TEST.pubkey2address(msgObj.nodePubKey);
+
+ // Check if the public key belongs to real sender
+ if (getFloId !== msgObj.globalParams.senderFloId) {
+ showMessage(`Sender FLO address did not match signer FLO address.`);
+ reject(false)
+ }
+ const initialMsgObj = {
+ jsonrpc:msgObj.jsonrpc,
+ id:msgObj.id,
+ method:msgObj.method,
+ params:msgObj.params,
+ globalParams:msgObj.globalParams,
+ }
+
+ const initialMsgObjStr = JSON.stringify(initialMsgObj);
+
+ const initialMsgObjStrHash = Crypto.SHA256(initialMsgObjStr);
+
+ const RM_WALLET = new localbitcoinplusplus.wallets;
+ if (RM_WALLET.verify(initialMsgObjStrHash, msgObj.nodeSignedMessage, msgObj.nodePubKey)) {
+ resolve(true);
+ } else {
+ showMessage(`WARNING: Incoming Websocket message verification failed.`)
+ reject(false);
+ }
+
+ } catch (error) {
+ reject(error);
+ }
+ })
+ }
+
+
/*CODE_JUNCTION: Random functions*/
// log event in the console
@@ -10211,11 +10680,12 @@
function showMessage(msg='', t=10000) {
if (msg.length>0) LogEvent(msg);
- displayMessages();
- setTimeout(function(){
- closeMessage();
- clearTimeout();
- }, t);
+ console.info(msg);
+ //displayMessages();
+ // setTimeout(function(){
+ // closeMessage();
+ // clearTimeout();
+ // }, t);
}
function displayMessages() {
@@ -10273,8 +10743,10 @@
try {
var rm_configs = localbitcoinplusplus.actions.fetch_configs(async function (...fetch_configs_res) {
localbitcoinplusplus.is_ui_loaded = false;
- showMessage(`Connecting to Supernode server. Please wait...`);
+ window.bitjs = []; // Launch bitjs
+ localbitcoinplusplus.master_configurations.tradableAsset1.map(asset => bitjslib(asset));
kickInit();
+ loadResetFloBtnUi();
});
} catch (error) {
showMessage(`WARNING: System failed to collect configurations.
@@ -10291,22 +10763,113 @@
console.info('Load pending withdrawals');
}
+ // Connect to Supernode
function loadSupernodesConnectUi() {
- //wsUri = await localbitcoinplusplus.kademlia.getSupernodeSeed();
+ const supernodeSeeds = localbitcoinplusplus.master_configurations.supernodeSeeds;
+ if (typeof supernodeSeeds !== "object") return showMessage("Failed to get supernode list.");
+ let supernodeSeedsObj = JSON.parse(supernodeSeeds);
+ let supernodeSeedsArray = Object.values(supernodeSeedsObj);
- // Connect with primary supernodes
- //await startWebSocket(`ws://${wsUri[0].ip}:${wsUri[0].port}`);
+ let supernode_seedsInput = ``;
+ supernode_seedsInput += ``;
+
+ const supernode_seeds_div = document.getElementById('supernode_seeds_div');
+ supernode_seeds_div.innerHTML = supernode_seedsInput;
+
+ const supn_conn_btn = document.getElementById('supn_conn_btn');
+ supn_conn_btn.addEventListener("click", function(evt) {
+ const selected_su = document.getElementById('supernode_seeds');
+ if (typeof websocket == "object" && websocket.readyState === WebSocket.OPEN) {
+ if (websocket.url===`${selected_su.value}/`) {
+ showMessage(`INFO: Websocket already connected.`);
+ return;
+ }
+ websocket.close();
+ }
+
+ try {
+ startWebSocket(selected_su.value);
+
+ } catch (error) {
+ showMessage('Error: '+error);
+ return;
+ }
+ });
}
- // localbitcoinUser Database
+ // Ask Connected Supernode to give pending deposits/withdrawals
+ function AskSupernodeForLatestDepositsAndWithdrawalsData() {
+
+ const fetch_deposits_btn = document.getElementById('fetch_deposits');
+ fetch_deposits_btn.addEventListener("click", function(evt) {
+
+ console.log(localbitcoinplusplus);
+ console.log(localbitcoinplusplus.MY_UPI_ID);
+ console.log(localbitcoinplusplus.CONNECTED_SUPERNODE_FLO_ADDRESS);
+
+ if (localbitcoinplusplus.MY_UPI_ID.length < 1
+ || localbitcoinplusplus.CONNECTED_SUPERNODE_FLO_ADDRESS.length < 1) {
+ showMessage(`WARNING: Your UPI Id or connected Supernode is not set.`);
+ return false;
+ }
+
+ const RM_RPC = new localbitcoinplusplus.rpc;
+ RM_RPC
+ .send_rpc
+ .call(this, "give_cashier_latest_pending_cash_deposits", {
+ trader_flo_address: localbitcoinplusplus.wallets.my_local_flo_address,
+ cashier_pubKey: localbitcoinplusplus.wallets.my_local_flo_public_key,
+ cashier_upi: localbitcoinplusplus.MY_UPI_ID,
+ receiver_flo_address: localbitcoinplusplus.CONNECTED_SUPERNODE_FLO_ADDRESS,
+ }).then(resp=>doSend(resp));
+
+ });
+ }
+
+ // Reset Flo Id
+ function loadResetFloBtnUi() {
+ // RESET KEYS
+ const reset_flo_keys_div = document.getElementById('flo_keys_div');
+ const reset_flo_keys_btn = document.createElement('button');
+ reset_flo_keys_btn.className += ` button bg-purple mg-5 `;
+ const reset_flo_keys_btn_text = document.createTextNode(`Reset FLO Keys`);
+ reset_flo_keys_btn.appendChild(reset_flo_keys_btn_text);
+ reset_flo_keys_div.appendChild(reset_flo_keys_btn);
+
+ reset_flo_keys_btn.onclick = function () {
+ if (confirm(
+ `This will reset your old keys along with data associated with it. Are you sure you want to continue?`
+ )) {
+ const RM_WALLET = new localbitcoinplusplus.wallets;
+ RM_WALLET.reset_flo_keys().then(reset_success => {
+ if (reset_success) {
+ showMessage("INFO: FLO keys have been reset successfully.");
+ } else {
+ showMessage(`INFO: Failed to reset FLO keys.`);
+ }
+ });
+ }
+ }
+ }
+
+ // paymentsHandlerDetails Database
const dataBaseUIOperations = async function () {
localbitcoinplusplus.is_ui_loaded = true;
const RM_WALLET = new localbitcoinplusplus.wallets;
- const RM_TRADE = new localbitcoinplusplus.trade;
const RM_RPC = new localbitcoinplusplus.rpc;
try {
@@ -10316,10 +10879,7 @@
idbData.myLocalFLOAddress;
const MY_LOCAL_FLO_PUBLIC_KEY = localbitcoinplusplus.wallets.my_local_flo_public_key =
idbData.myLocalFLOPublicKey;
-
- // Build Supernodes KBuckets
- launchSupernodesKBuckects = await localbitcoinplusplus.kademlia.launchSupernodesKBucket();
-
+
// Load Supernodes Connection Select UI
loadSupernodesConnectUi();
@@ -10329,14 +10889,17 @@
// Load Pending Withdrawals UI
loadPendingWithdrawals();
+ // Fetch Deposits
+ AskSupernodeForLatestDepositsAndWithdrawalsData();
+
showMessage(`Connection successfull. Welocome to Local Bitcoin Plus Plus Cash Handling platform.`);
});
} catch (e) {
- showMessage("ERROR: Failed to initialise the localbitcoinUser database. You are unable to trade at the moment.");
+ showMessage("ERROR: Failed to initialise the paymentsHandlerDetails database. You are unable to trade at the moment.");
throw new Error(
- "ERROR: Failed to initialise the localbitcoinUser database. You are unable to trade at the moment."
+ "ERROR: Failed to initialise the paymentsHandlerDetails database. You are unable to trade at the moment."
);
}
@@ -10348,27 +10911,54 @@
return new Promise(resolve => {
readDB("paymentsHandlerDetails", "00-01").then(async function (idbData) {
-
+ let localbitcoinplusplusObj = {
+ id: "00-01",
+ myLocalFLOAddress: "",
+ myLocalFLOPublicKey: "",
+ upiID: "",
+ last_tx_time: "",
+ last_active_time: + new Date()
+ }
if (typeof idbData.myLocalFLOPublicKey == "undefined" || idbData.myLocalFLOPublicKey
.trim() == '') {
let user_pvt_key = prompt(
"Please Enter a valid FLO private key if you have any. Else leave blank."
);
+ const user_upi = prompt("Please Enter a valid UPI id!");
if (user_pvt_key.trim() == "" || user_pvt_key.length < 1) user_pvt_key = null;
+ if (user_upi.trim() == "" || user_upi.length < 1) return showMessage(`Warning: You must provide a valid UPI id.`);
let newKeys = RM_WALLET.generateFloKeys(user_pvt_key);
if (typeof newKeys == 'object' && newKeys.privateKeyWIF.length > 0 &&
newKeys.address.length > 0) {
- localbitcoinplusplusObj.myLocalFLOAddress = newKeys.address;
- localbitcoinplusplusObj.myLocalFLOPublicKey = newKeys.pubKeyHex;
- localbitcoinplusplusObj.lastConnectedTime = + new Date();
-
- await updateinDB("paymentsHandlerDetails", localbitcoinplusplusObj);
- //wsUri = await localbitcoinplusplus.kademlia.getSupernodeSeed();
+ localbitcoinplusplusObj.myLocalFLOAddress= newKeys.address,
+ localbitcoinplusplusObj.myLocalFLOPublicKey= newKeys.pubKeyHex,
+ localbitcoinplusplusObj.upiID= user_upi,
+ localbitcoinplusplusObj.last_active_time= + new Date()
+
+ await updateinDB("paymentsHandlerDetails", localbitcoinplusplusObj);
- //await startWebSocket(`ws://${wsUri[0].ip}:${wsUri[0].port}`);
+ Object.defineProperty(localbitcoinplusplus, "MY_UPI_ID", {
+ value: user_upi,
+ writable: false,
+ configurable: false,
+ enumerable: false
+ });
+
+ // launch KBuckets
+ launchKBuckects = await localbitcoinplusplus.kademlia.launchKBucket();
+
+ if (!launchKBuckects) {
+ const kmsg = `ERROR: Failed to build KBuckets. System cannot proceed further.`;
+ showMessage(kmsg);
+ throw new Error(kmsg);
+ }
+
+ await localbitcoinplusplus.kademlia.restoreSupernodeKBucket();
+
+ await localbitcoinplusplus.kademlia.getSupernodeSeed();
if ((typeof localbitcoinplusplus.wallets.MY_SUPERNODE_PRIVATE_KEY!=='string'
|| localbitcoinplusplus.wallets.MY_SUPERNODE_PRIVATE_KEY.length<1)
@@ -10390,12 +10980,30 @@
}
}
+ if (typeof idbData.upiID !=="string" || idbData.upiID.length<1) {
+ showMessage(`ERROR: No UPI ID found.`);
+ return false;
+ }
+
+ Object.defineProperty(localbitcoinplusplus, "MY_UPI_ID", {
+ value: idbData.upiID,
+ writable: false,
+ configurable: false,
+ enumerable: false
+ });
+
+ // launch KBuckets
+ launchKBuckects = await localbitcoinplusplus.kademlia.launchKBucket();
+
+ if (!launchKBuckects) {
+ const kmsg = `ERROR: Failed to build KBuckets. System cannot proceed further.`;
+ showMessage(kmsg);
+ throw new Error(kmsg);
+ }
+
await localbitcoinplusplus.kademlia.restoreSupernodeKBucket();
-
- //wsUri = await localbitcoinplusplus.kademlia.getSupernodeSeed();
-
- // Connect with primary supernodes
- //await startWebSocket(`ws://${wsUri[0].ip}:${wsUri[0].port}`);
+
+ await localbitcoinplusplus.kademlia.getSupernodeSeed();
if ((typeof localbitcoinplusplus.wallets.MY_SUPERNODE_PRIVATE_KEY!=='string'
|| localbitcoinplusplus.wallets.MY_SUPERNODE_PRIVATE_KEY.length<1)
@@ -10415,10 +11023,8 @@
})();
-
-
-
+
\ No newline at end of file
diff --git a/supernode/index.html b/supernode/index.html
index 5bbf803..d5f40f6 100644
--- a/supernode/index.html
+++ b/supernode/index.html
@@ -10543,7 +10543,7 @@
const master_flo_pubKey = localbitcoinplusplus.master_configurations.masterFLOPubKey;
const master_flo_addr = bitjs.FLO_TEST.pubkey2address(master_flo_pubKey);
- if(typeof master_flo_pubKey !== "string") return reject(false);
+ if(typeof master_flo_addr !== "string") return reject(false);
const SuKBucketId = localbitcoinplusplus.kademlia.floIdToKbucketId('FLO_TEST', master_flo_addr);
const SukbOptions = { localNodeId: SuKBucketId }
window.supernodeKBucket = new BuildKBucket(SukbOptions);
@@ -10769,7 +10769,6 @@
}
})
},
-
addClosestSupernodeInDB: function(flo_addr, KB=supernodeKBucket) {
return new Promise(async (resolve, reject)=>{
const supernodeSeeds = localbitcoinplusplus.master_configurations.supernodeSeeds;
@@ -12496,6 +12495,8 @@
.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();
@@ -13677,6 +13678,8 @@
.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();
@@ -14729,7 +14732,7 @@
"deposit_asset_request", deposit_request_object)
.then(deposit_request=>doSend(deposit_request));
},
- depositCash(amount, currency, userFLOaddress) {
+ depositCash(amount, currency, userFLOaddress, user_upi) {
if (typeof localbitcoinplusplus.master_configurations.tradableAsset2 == 'undefined' ||
(!localbitcoinplusplus.master_configurations.tradableAsset2
.includes(currency))) {
@@ -14749,11 +14752,16 @@
err_msg = "Error: Invalid deposit amount.";
showMessage(err_msg);
throw new Error(err_msg);
+ } else if (typeof user_upi!=="string" || user_upi.length<1) {
+ err_msg = "Error: Invalid UPI id.";
+ showMessage(err_msg);
+ throw new Error(err_msg);
}
let deposit_request_object = {
trader_flo_address: userFLOaddress,
depositing_amount: amount,
currency: currency,
+ user_upi: user_upi,
operation_type: "deposit_cash",
receiver_flo_address:localbitcoinplusplus.MY_SUPERNODE_FLO_ADDRESS,
}
@@ -16360,9 +16368,15 @@
// If the message is about leaving of a node determine its FLO Id
// and fire respective events
let isItANodeLeavingMessage = response.search(`\\-- left`);
-
if(isItANodeLeavingMessage >= 0) {
reactor.dispatchEvent('fireNodeGoodByeEvent', response);
+ return;
+ }
+
+ const isMsgFromCashier = response.search('__FOR__CASHIER__');
+ if (isMsgFromCashier>=0) {
+ handleCashierMessages(response);
+ return;
}
var res_pos = response.indexOf('{');
@@ -16648,8 +16662,8 @@
let counterTraderAccountAddress =
`Please pay the amount to following UPI ID:
${resp.msg}`;
- showMessage(counterTraderAccountAddress);
- modalWindow(counterTraderAccountAddress);
+ showMessage(counterTraderAccountAddress);
+ modalWindow(counterTraderAccountAddress);
}
});
}
@@ -19470,6 +19484,35 @@
});
break;
+ case "deposit_cash_request_response":
+ if (typeof res_obj.params !== "object"
+ || typeof res_obj.params[0] !== "object") return;
+ let deposit_res_data = res_obj.params[0];
+ RM_RPC.filter_legit_backup_requests(deposit_res_data.trader_flo_address,
+ async function (is_valid_request) {
+ if(!is_valid_request) return false;
+ if (typeof res_obj.params == "object" && typeof res_obj.params[0] == "object"
+ && typeof res_obj.params[0].data == "object") {
+ let resp = res_obj.params[0];
+ if (RM_WALLET
+ .verify(resp.data.depositDataHash, resp.data.order_validator_sign, resp.data.order_validator_public_key)
+ ) {
+ let getPrimarySuObj = await localbitcoinplusplus.kademlia.determineClosestSupernode(resp.data.trader_flo_address);
+ const primarySupernode = getPrimarySuObj[0].data.id;
+ const backup_server_db_instance = localbitcoinplusplus.newBackupDatabase.db[primarySupernode];
+ if(typeof backup_server_db_instance !== "object") {
+ let backup_db_error_msg = `WARNING: Unknown DB instance. DB Backup failed.`;
+ showMessage(backup_db_error_msg);
+ throw new Error(backup_db_error_msg);
+ };
+
+ backup_server_db_instance.backup_addDB('cash_deposits', resp.data);
+
+ }
+ }
+ });
+ break;
+
case "withdrawal_request_response":
if (typeof res_obj.params !== "object"
|| typeof res_obj.params[0] !== "object") return;
@@ -20467,6 +20510,10 @@
}
}
+ async function handleCashierMessages(response) {
+ console.log(response);
+ }
+
function onError(evt) {
let msg = `ERROR: Websocket Connection to ${evt.srcElement.url} returned error.`;
showMessage(msg);
@@ -22294,6 +22341,12 @@
// asset_button_box.appendChild(withdrawAssetButton);
depositAssetButton.addEventListener('click', function () {
+ const user_upi = prompt('Please provide the UPI id you are paying from!');
+ if (typeof user_upi!=="string" || user_upi.length<1) {
+ err_msg = "Invalid or empty UPI id.";
+ showMessage(err_msg);
+ throw new Error(err_msg);
+ }
let asset_type = assetTypeInput.value;
let tradeAmount = Number(tradeAmountSelect.value);
let fiatCurrency = currencySelect.value;
@@ -22305,7 +22358,7 @@
if (typeof localbitcoinplusplus.master_configurations.tradableAsset2 !== 'undefined' &&
localbitcoinplusplus.master_configurations.tradableAsset2.includes(asset_type)
) {
- RM_TRADE.depositCash(tradeAmount, fiatCurrency, userFLOaddress);
+ RM_TRADE.depositCash(tradeAmount, fiatCurrency, userFLOaddress, user_upi);
} else {
err_msg = "Error while depositing your address.";
showMessage(err_msg);