Merge pull request #14 from avishkarabhishek786/hotfixes

added code to backup idb as json, fixed backup syncing issues
This commit is contained in:
Abhishek Sinha 2020-04-15 14:18:47 +05:30 committed by GitHub
commit 1eb28fe074
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 1302 additions and 1756 deletions

View File

@ -12007,24 +12007,37 @@
localbitcoinplusplus.actions = { localbitcoinplusplus.actions = {
parse_flo_comments: async function(callback) { parse_flo_comments: async function(callback) {
// text = `masterFLOPubKey=03EA5E2CAB18DA585400D6EC569438D415FAF200528E05D0E2B9BEAA2B5C3DCA90
// #!#tradableAsset1=BTC,FLO,BTC_TEST,FLO_TEST#!#tradableAsset2=INR,USD,
// #!#validTradingAmount=10,50,100,#!#btcTradeMargin=5000
// #!#MaxBackups=1
// #!#miners_fee={"btc":0.0003, "flo":0.0003}
// #!#supernodesPubKeys=0315C3A20FE7096CC2E0F81A80D5F1A687B8F9EFA65242A0B0881E1BA3EE7D7D53,
// 03F7493F11B8E44B9798CD434D20FBE7FA34B9779D144984889D11A17C56A18742,039B4AA00DBFC0A6631DE6DA83526611A0E6B857D3579DF840BBDEAE8B6898E3B6,
// 03C8E3836C9A77E2AF03D4265D034BA85732738919708EAF6A16382195AE796EDF,0349B08AA1ABDCFFB6D78CD7C949665AD2FF065EA02B3C6C47A5E9592C9A1C6BCB,
// 026FCC6CFF6EB3A39E54BEB6E13FC2F02C3A93F4767AA80E49E7E876443F95AE5F,
// #!#externalFiles={"d3js":"58f54395efa8346e8e94d12609770f66b916897e7f4e05f6c98780cffa5c70a3"}
// #!#cashiers={"032871A74D2DDA9D0DE7135F58B5BD2D7F679D2CCA20EA7909466D1A6912DF4022":"johnDoe@upi",
// "03DB4A12EB543B293DDBB0CE314C46C36D6761294AFBB7264A6D78F710FFD97CF0":"janeDoe@upi"}
// #!#ShamirsMaxShares=8#!#supernodeSeeds={"ranchimall1":{"ip":"127.0.0.1:9111","kbucketId":"oZxHcbSf1JC8t5GjutopWYXs7C6Fe9p7ps"},
// "ranchimall2":{"ip":"127.0.0.1:9112","kbucketId":"oTWjPupy3Z7uMdPcu5uXd521HBkcsLuSuM"},
// "ranchimall3":{"ip":"127.0.0.1:9113","kbucketId":"odYA6KagmbokSh9GY7yAfeTUZRtZLwecY1"},
// "ranchimall4":{"ip":"127.0.0.1:9114","kbucketId":"oJosrve9dBv2Hj2bfncxv2oEpTysg3Wejv"},
// "ranchimall5":{"ip":"127.0.0.1:9115","kbucketId":"oMhv5sAzqg77sYHxmUGZWKRrVo4P4JQduS"},
// "ranchimall6":{"ip":"127.0.0.1:9116","kbucketId":"oV1wCeWca3VawbBTfUGKA7Vd368PATnKAx"}}`;
text = `masterFLOPubKey=03EA5E2CAB18DA585400D6EC569438D415FAF200528E05D0E2B9BEAA2B5C3DCA90 text = `masterFLOPubKey=03EA5E2CAB18DA585400D6EC569438D415FAF200528E05D0E2B9BEAA2B5C3DCA90
#!#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
#!#miners_fee={"btc":0.0003, "flo":0.0003} #!#miners_fee={"btc":0.0003, "flo":0.0003}
#!#supernodesPubKeys=0315C3A20FE7096CC2E0F81A80D5F1A687B8F9EFA65242A0B0881E1BA3EE7D7D53, #!#supernodesPubKeys=026FCC6CFF6EB3A39E54BEB6E13FC2F02C3A93F4767AA80E49E7E876443F95AE5F,
03F7493F11B8E44B9798CD434D20FBE7FA34B9779D144984889D11A17C56A18742,039B4AA00DBFC0A6631DE6DA83526611A0E6B857D3579DF840BBDEAE8B6898E3B6, #!#cashiers={"032871A74D2DDA9D0DE7135F58B5BD2D7F679D2CCA20EA7909466D1A6912DF4022":"johnDoe@upi",
03C8E3836C9A77E2AF03D4265D034BA85732738919708EAF6A16382195AE796EDF,0349B08AA1ABDCFFB6D78CD7C949665AD2FF065EA02B3C6C47A5E9592C9A1C6BCB, "03DB4A12EB543B293DDBB0CE314C46C36D6761294AFBB7264A6D78F710FFD97CF0":"janeDoe@upi"}
026FCC6CFF6EB3A39E54BEB6E13FC2F02C3A93F4767AA80E49E7E876443F95AE5F, #!#ShamirsMaxShares=8#!#supernodeSeeds={
#!#externalFiles={"d3js":"58f54395efa8346e8e94d12609770f66b916897e7f4e05f6c98780cffa5c70a3"} "ranchimall6":{"ip":"127.0.0.1:9116","kbucketId":"oV1wCeWca3VawbBTfUGKA7Vd368PATnKAx"}
#!#cashiers={"032871A74D2DDA9D0DE7135F58B5BD2D7F679D2CCA20EA7909466D1A6912DF4022":"johnDoe@upi", }`;
"03DB4A12EB543B293DDBB0CE314C46C36D6761294AFBB7264A6D78F710FFD97CF0":"janeDoe@upi"}
#!#ShamirsMaxShares=8#!#supernodeSeeds={"ranchimall1":{"ip":"127.0.0.1:9111","kbucketId":"oZxHcbSf1JC8t5GjutopWYXs7C6Fe9p7ps"},
"ranchimall2":{"ip":"127.0.0.1:9112","kbucketId":"oTWjPupy3Z7uMdPcu5uXd521HBkcsLuSuM"},
"ranchimall3":{"ip":"127.0.0.1:9113","kbucketId":"odYA6KagmbokSh9GY7yAfeTUZRtZLwecY1"},
"ranchimall4":{"ip":"127.0.0.1:9114","kbucketId":"oJosrve9dBv2Hj2bfncxv2oEpTysg3Wejv"},
"ranchimall5":{"ip":"127.0.0.1:9115","kbucketId":"oMhv5sAzqg77sYHxmUGZWKRrVo4P4JQduS"},
"ranchimall6":{"ip":"127.0.0.1:9116","kbucketId":"oV1wCeWca3VawbBTfUGKA7Vd368PATnKAx"}}`;
return callback(text); return callback(text);
if(ENVR==='LIVE') { if(ENVR==='LIVE') {
@ -12053,7 +12066,7 @@
fetch_configs: function(callback) { fetch_configs: function(callback) {
this.parse_flo_comments(function(floData) { this.parse_flo_comments(function(floData) {
let RMAssets = floData.trim(); let RMAssets = removeWhiteSpaces(floData);
let floAssetsArray = RMAssets.split("#!#"); let floAssetsArray = RMAssets.split("#!#");
if ( if (
@ -12698,10 +12711,7 @@
}, },
getSupernodeSeed: function() { getSupernodeSeed: function() {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
let nearestSupernodeAddresslist = await readAllDB( await removeAllinDB("supernodesList");
"supernodesList"
);
if (nearestSupernodeAddresslist.length < 1) {
const supernodeSeeds = const supernodeSeeds =
localbitcoinplusplus.master_configurations.supernodeSeeds; localbitcoinplusplus.master_configurations.supernodeSeeds;
if (typeof supernodeSeeds !== "object") if (typeof supernodeSeeds !== "object")
@ -12713,7 +12723,7 @@
throw new Error(e); throw new Error(e);
}); });
}); });
}
resolve(nearestSupernodeAddresslist); resolve(nearestSupernodeAddresslist);
}); });
}, },
@ -13434,7 +13444,7 @@
} }
let t = ``; let t = ``;
let deposits_table = document.getElementById("deposits_list"); let deposits_table = document.getElementById("deposits_list");
deposits_table.innerHTML = ''; //deposits_table.innerHTML = '';
for (const m of responseData.responseData.data) { for (const m of responseData.responseData.data) {
let su_res = await localbitcoinplusplus.kademlia.determineClosestSupernode(m.trader_flo_address); let su_res = await localbitcoinplusplus.kademlia.determineClosestSupernode(m.trader_flo_address);
@ -13470,7 +13480,7 @@
(async function() { (async function() {
let v = ``; let v = ``;
const withdraws_table = document.getElementById("withdraws_list"); const withdraws_table = document.getElementById("withdraws_list");
withdraws_table.innerHTML = ''; //withdraws_table.innerHTML = '';
for (const m of responseData.responseData.data) { for (const m of responseData.responseData.data) {
const user_upi = localbitcoinplusplus.encrypt.decryptMessage( const user_upi = localbitcoinplusplus.encrypt.decryptMessage(
m.receivinAddress.secret, m.receivinAddress.secret,
@ -13752,6 +13762,10 @@
}, []); }, []);
} }
function removeWhiteSpaces(text='') {
return text.replace(/\s/g,'');
}
/*CODE_JUNCTION: Operating codes start*/ /*CODE_JUNCTION: Operating codes start*/
// Fetch configs from Master Key // Fetch configs from Master Key
@ -13804,7 +13818,7 @@
} }
// Fetch Deposit or Withdraw requests // Fetch Deposit or Withdraw requests
function send_deposit_withdraw_req(websocket_flo_id="", job="", parent_flo_id="") { async function send_deposit_withdraw_req(websocket_flo_id="", job="") {
if (localbitcoinplusplus.MY_UPI_ID.length < 1) { if (localbitcoinplusplus.MY_UPI_ID.length < 1) {
showMessage( showMessage(
`WARNING: Your UPI Id is not set.` `WARNING: Your UPI Id is not set.`
@ -13812,7 +13826,7 @@
return false; return false;
} }
const websocket_name = localbitcoinplusplus.supernode_conns[websocket_flo_id]; let websocket_name = localbitcoinplusplus.supernode_conns[websocket_flo_id];
if(typeof websocket_name!=="object") return; if(typeof websocket_name!=="object") return;
if(job.length<1) return; if(job.length<1) return;
@ -13826,16 +13840,29 @@
receiver_flo_address: websocket_flo_id, receiver_flo_address: websocket_flo_id,
} }
// For case where parent supernode is dead req_body.parent_supernode = websocket_flo_id;
if(websocket_flo_id !== parent_flo_id && parent_flo_id.length>0) {
req_body.parent_supernode = parent_flo_id;
req_body.requesting_supernode = websocket_flo_id;
}
if(parent_flo_id.length<1 || websocket_flo_id==parent_flo_id) { // For case where parent supernode is dead
req_body.parent_supernode = websocket_flo_id; if(localbitcoinplusplus.supernode_conns[websocket_flo_id].readyState!==1) {
req_body.requesting_supernode = websocket_flo_id; const sn_list = await localbitcoinplusplus.kademlia.determineClosestSupernode(
} "",
localbitcoinplusplus.master_configurations.MaxBackups,
supernodeKBucket,
websocket_flo_id
);
for (const sn of sn_list) {
if(sn.data.id !== websocket_flo_id &&
localbitcoinplusplus.supernode_conns[sn.data.id].readyState===1) {
req_body.requesting_supernode = sn.data.id;
req_body.receiver_flo_address = sn.data.id;
websocket_name = localbitcoinplusplus.supernode_conns[sn.data.id];
break;
}
}
} else {
req_body.requesting_supernode = websocket_flo_id;
}
RM_RPC.send_rpc RM_RPC.send_rpc
.call(this, job, req_body) .call(this, job, req_body)
@ -13862,6 +13889,7 @@
const RM_WALLET = new localbitcoinplusplus.wallets; const RM_WALLET = new localbitcoinplusplus.wallets;
Array.from(recv_deposit_btn).forEach(function(element) { Array.from(recv_deposit_btn).forEach(function(element) {
element.addEventListener("click", async function(evt) { element.addEventListener("click", async function(evt) {
let btn = this;
evt.preventDefault(); evt.preventDefault();
const deposit_id = this.value; const deposit_id = this.value;
const req_info = document.getElementById(`depositSpan${deposit_id}`); const req_info = document.getElementById(`depositSpan${deposit_id}`);
@ -13879,16 +13907,35 @@
const confirmTx = confirm(token_transfer_statement); const confirmTx = confirm(token_transfer_statement);
if(!confirmTx) return; if(!confirmTx) return;
const websocket_conn = localbitcoinplusplus.supernode_conns[requesting_supernode]; // Get the closest Supernode alive for this user
let closestSuList = await localbitcoinplusplus.kademlia
.determineClosestSupernode(websocket_name,
localbitcoinplusplus.master_configurations.supernodesPubKeys.length);
let closest_live_su = '';
for(su_node in closestSuList) {
let su = closestSuList[su_node].data.id;
if(typeof localbitcoinplusplus.supernode_conns[su]=="object"
&& localbitcoinplusplus.supernode_conns[su] !== null
&& localbitcoinplusplus.supernode_conns[su].readyState===WebSocket.OPEN) {
closest_live_su = su;
break;
}
}
if(closest_live_su=='') closest_live_su = requesting_supernode;
//const websocket_conn = localbitcoinplusplus.supernode_conns[requesting_supernode];
const websocket_conn = localbitcoinplusplus.supernode_conns[closest_live_su];
if(typeof websocket_conn!=="object") return; if(typeof websocket_conn!=="object") return;
let flo_txid = ''; let flo_txid = '';
const flo_tx = await RM_WALLET.sendTransaction( const flo_tx = await RM_WALLET.sendTransaction(
localbitcoinplusplus.assets.FLO, localbitcoinplusplus.BASE_BLOCKCHAIN,
localbitcoinplusplus.wallets.my_local_flo_address, localbitcoinplusplus.wallets.my_local_flo_address,
localbitcoinplusplus.wallets.MY_SUPERNODE_PRIVATE_KEY, localbitcoinplusplus.wallets.MY_SUPERNODE_PRIVATE_KEY,
requesting_supernode, closest_live_su,
tx_amount, tx_amount,
localbitcoinplusplus.wallets.my_local_flo_address, localbitcoinplusplus.wallets.my_local_flo_address,
token_transfer_statement token_transfer_statement
@ -13906,7 +13953,7 @@
localbitcoinplusplus.wallets.my_local_flo_address, localbitcoinplusplus.wallets.my_local_flo_address,
cashier_pubKey: cashier_pubKey:
localbitcoinplusplus.wallets.my_local_flo_public_key, localbitcoinplusplus.wallets.my_local_flo_public_key,
receiver_flo_address: requesting_supernode, receiver_flo_address: closest_live_su,
flo_txid: flo_txid, flo_txid: flo_txid,
deposit_id: deposit_id, deposit_id: deposit_id,
parent_supernode: websocket_name, parent_supernode: websocket_name,
@ -13938,10 +13985,10 @@
.call(this, "cashier_confirms_user_cash_deposit", req_body) .call(this, "cashier_confirms_user_cash_deposit", req_body)
.then(resp => doSend(websocket_conn, resp)); .then(resp => doSend(websocket_conn, resp));
this.classList.remove('cnf_deposits'); btn.classList.remove('cnf_deposits');
this.classList.remove('btn-info'); btn.classList.remove('btn-info');
this.classList.add('btn-success'); btn.classList.add('btn-success');
this.innerText = "Success"; btn.innerText = "Success";
return true; return true;
@ -13952,14 +13999,14 @@
// Failed to validate token transfer. Save in local db // Failed to validate token transfer. Save in local db
await addDB('failed_deposit_confirms', req_body, req_body.flo_txid); await addDB('failed_deposit_confirms', req_body, req_body.flo_txid);
this.classList.remove('cnf_deposits'); btn.classList.remove('cnf_deposits');
this.classList.remove('btn-info'); btn.classList.remove('btn-info');
this.classList.add('btn-danger'); btn.classList.add('btn-danger');
this.innerText = "Failed to inform Supernode. Please contact the Admin."; btn.innerText = "Failed to inform Supernode. Please contact the Admin.";
throw new Error(`Failed to inform Supernode of cash deposit: ${flo_txid}`); throw new Error(`Failed to inform Supernode of cash deposit: ${flo_txid}`);
} }
})() }.bind(btn))()
}); });
}); });
@ -13973,6 +14020,7 @@
element.addEventListener("click", function(evt) { element.addEventListener("click", function(evt) {
evt.preventDefault(); evt.preventDefault();
let btn = this;
const withdraw_id = this.value; const withdraw_id = this.value;
const req_info = document.getElementById(`withdrawSpan${withdraw_id}`); const req_info = document.getElementById(`withdrawSpan${withdraw_id}`);
const req_info_arr = req_info.value.split("_"); const req_info_arr = req_info.value.split("_");
@ -13984,7 +14032,24 @@
const upi_txid = prompt("Enter Transferred Cash UPI Txid: "); const upi_txid = prompt("Enter Transferred Cash UPI Txid: ");
if (upi_txid.length < 1) return; if (upi_txid.length < 1) return;
const websocket_conn = localbitcoinplusplus.supernode_conns[requesting_supernode]; // Get the closest Supernode alive for this user
let closestSuList = await localbitcoinplusplus.kademlia
.determineClosestSupernode(websocket_name,
localbitcoinplusplus.master_configurations.supernodesPubKeys.length);
let closest_live_su = '';
for(su_node in closestSuList) {
let su = closestSuList[su_node].data.id;
if(typeof localbitcoinplusplus.supernode_conns[su]=="object"
&& localbitcoinplusplus.supernode_conns[su] !== null
&& localbitcoinplusplus.supernode_conns[su].readyState===WebSocket.OPEN) {
closest_live_su = su;
break;
}
}
if(closest_live_su=='') closest_live_su = requesting_supernode;
const websocket_conn = localbitcoinplusplus.supernode_conns[closestSuList];
if(typeof websocket_conn!=="object") return; if(typeof websocket_conn!=="object") return;
RM_RPC.send_rpc RM_RPC.send_rpc
@ -13993,21 +14058,21 @@
localbitcoinplusplus.wallets.my_local_flo_address, localbitcoinplusplus.wallets.my_local_flo_address,
cashier_pubKey: cashier_pubKey:
localbitcoinplusplus.wallets.my_local_flo_public_key, localbitcoinplusplus.wallets.my_local_flo_public_key,
receiver_flo_address: requesting_supernode, receiver_flo_address: closestSuList,
withdraw_id: withdraw_id, withdraw_id: withdraw_id,
upi_txid: upi_txid, upi_txid: upi_txid,
parent_supernode: websocket_name, parent_supernode: websocket_name,
}) })
.then(resp => doSend(websocket_conn, resp)); .then(resp => doSend(websocket_conn, resp));
this.classList.remove('cnf_withdrawal'); btn.classList.remove('cnf_withdrawal');
this.classList.remove('btn-info'); btn.classList.remove('btn-info');
this.classList.add('btn-success'); btn.classList.add('btn-success');
this.innerText = "Success"; btn.innerText = "Success";
return true; return true;
}); }.bind(btn));
}); });
} }

2879
index.html

File diff suppressed because it is too large Load Diff