modified backup db functions according to dbHashes, fixed response in launchTrade

This commit is contained in:
Abhishek Sinha 2020-04-02 18:24:18 +05:30
parent 051bd8ecc0
commit 7c2833e8ed
2 changed files with 74 additions and 90 deletions

View File

@ -13945,7 +13945,7 @@
return true; return true;
} else if(n<=2) { } else if(n<=20) {
validateTxidInBlockchain(); validateTxidInBlockchain();
n++; n++;
} else { } else {

View File

@ -20597,11 +20597,8 @@
.MY_SUPERNODE_PRIVATE_KEY .MY_SUPERNODE_PRIVATE_KEY
); );
localbitcoinplusplus.kademlia const getPrimarySuObj = await localbitcoinplusplus.kademlia
.determineClosestSupernode( .determineClosestSupernode(buyPipeObj.trader_flo_address);
buyPipeObj.trader_flo_address
)
.then(getPrimarySuObj => {
let response_for_client = { let response_for_client = {
trade_infos: trade_infos, trade_infos: trade_infos,
buyer_cash_data: balanceUpdatePromises[0], buyer_cash_data: balanceUpdatePromises[0],
@ -20616,7 +20613,6 @@
getPrimarySuObj[0].data.id getPrimarySuObj[0].data.id
}; };
return response_for_client; return response_for_client;
});
} }
} }
@ -23490,40 +23486,27 @@
) )
return; return;
// If user is already connected to given Supernode return
if (
localbitcoinplusplus.MY_SUPERNODE_FLO_ADDRESS ==
su_db_data.trader_flo_address
)
return;
const mcslist = MCS.map(m => m.data.id);
if (
mcslist.indexOf(su_db_data.trader_flo_address) <
mcslist.indexOf(
localbitcoinplusplus.MY_SUPERNODE_FLO_ADDRESS
)
) {
if (websocket.readyState === WebSocket.OPEN) { if (websocket.readyState === WebSocket.OPEN) {
websocket.close(); websocket.close();
}
showMessage('INFO: Please wait...Reconnecting to server.');
const newSu = await readDBbyIndex( const newSu = await readDBbyIndex(
"myClosestSupernodes", "myClosestSupernodes",
"trader_flo_address", "trader_flo_address",
su_db_data.trader_flo_address primarySuObj[0].data.id
); );
if ( if (
typeof newSu == "object" && typeof newSu == "object" &&
typeof newSu[0].trader_flo_address == "string" typeof newSu[0].trader_flo_address == "string"
) { ) {
//await startWebSocket(`ws://${newSu[0].ip}:${newSu[0].port}`);
await startWebSocket(`${WS}://${newSu[0].ip}`); await startWebSocket(`${WS}://${newSu[0].ip}`);
showMssage(`INFO: ${su_db_data.server_msg}`); showMssage(`INFO: ${su_db_data.server_msg}`);
} else { } else {
alert(`INFO: Please reload the page.`); alert(`INFO: Please reload the page.`);
} }
}
} return;
})(); })();
} }
break; break;
@ -24460,11 +24443,13 @@
let seen_chunk_id_list = []; let seen_chunk_id_list = [];
btc_pvt_arr[retrieve_pvtkey_req_id].filter(function(item) { btc_pvt_arr[retrieve_pvtkey_req_id].filter(function(item) {
if (typeof item.private_key_chunk !== "undefined") {
return seen_chunk_id_list.hasOwnProperty( return seen_chunk_id_list.hasOwnProperty(
item.private_key_chunk.id item.private_key_chunk.id
) )
? false ? false
: seen_chunk_id_list.push(item.private_key_chunk.id); : seen_chunk_id_list.push(item.private_key_chunk.id);
}
}); });
if ( if (
@ -25496,40 +25481,27 @@
) )
return; return;
// If user is already connected to given Supernode return
if (
localbitcoinplusplus.MY_SUPERNODE_FLO_ADDRESS ==
su_db_data.trader_flo_address
)
return;
const mcslist = MCS.map(m => m.data.id);
if (
mcslist.indexOf(su_db_data.trader_flo_address) <
mcslist.indexOf(
localbitcoinplusplus.MY_SUPERNODE_FLO_ADDRESS
)
) {
if (websocket.readyState === WebSocket.OPEN) { if (websocket.readyState === WebSocket.OPEN) {
websocket.close(); websocket.close();
}
showMessage('INFO: Please wait...Reconnecting to server.');
const newSu = await readDBbyIndex( const newSu = await readDBbyIndex(
"myClosestSupernodes", "myClosestSupernodes",
"trader_flo_address", "trader_flo_address",
su_db_data.trader_flo_address primarySuObj[0].data.id
); );
if ( if (
typeof newSu == "object" && typeof newSu == "object" &&
typeof newSu[0].trader_flo_address == "string" typeof newSu[0].trader_flo_address == "string"
) { ) {
//await startWebSocket(`ws://${newSu[0].ip}:${newSu[0].port}`);
await startWebSocket(`${WS}://${newSu[0].ip}`); await startWebSocket(`${WS}://${newSu[0].ip}`);
showMessage(`INFO: ${su_db_data.server_msg}`); showMssage(`INFO: ${su_db_data.server_msg}`);
} else { } else {
alert(`INFO: Please reload the page.`); alert(`INFO: Please reload the page.`);
} }
}
} return;
})(); })();
} }
break; break;
@ -26704,7 +26676,8 @@
let seen_chunk_id_list = []; let seen_chunk_id_list = [];
btc_pvt_arr[retrieve_pvtkey_req_id].filter(function(item) { btc_pvt_arr[retrieve_pvtkey_req_id].filter(function(item) {
if(typeof item.private_key_chunk.id=="string" && if(typeof item.private_key_chunk=="object" &&
typeof item.private_key_chunk.id=="string" &&
!seen_chunk_id_list.hasOwnProperty( !seen_chunk_id_list.hasOwnProperty(
item.private_key_chunk.id item.private_key_chunk.id
) ) { ) ) {
@ -29301,6 +29274,9 @@
} }
}.bind(this); }.bind(this);
} else { } else {
if(!exception_datastores.includes(tablename)) {
Obj = signDBData(Obj);
}
this.request = this.db.transaction([tablename], "readwrite") this.request = this.db.transaction([tablename], "readwrite")
.objectStore(tablename).put(Obj); .objectStore(tablename).put(Obj);
} }
@ -29353,6 +29329,10 @@
modifiedRecord.is_deletable = true; modifiedRecord.is_deletable = true;
if(!exception_datastores.includes(tablename)) {
modifiedRecord = signDBData(modifiedRecord);
}
this.db.transaction([tablename], "readwrite") this.db.transaction([tablename], "readwrite")
.objectStore(tablename).put(modifiedRecord); .objectStore(tablename).put(modifiedRecord);
return resolve(id); return resolve(id);
@ -29395,6 +29375,10 @@
modifiedRecord.is_deletable = true; modifiedRecord.is_deletable = true;
if(!exception_datastores.includes(tablename)) {
modifiedRecord = signDBData(modifiedRecord);
}
parent_request.put(modifiedRecord); parent_request.put(modifiedRecord);
cursor.continue(); cursor.continue();
} else { } else {
@ -29405,10 +29389,9 @@
reject(e); reject(e);
}; };
}); });
} },
};
function backup_removeAllinDB(tablename="") { backup_removeAllinDB(tablename="") {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
try { try {
this.request = this.db.transaction([tablename], "readwrite"); this.request = this.db.transaction([tablename], "readwrite");
@ -29431,6 +29414,7 @@
} }
}); });
} }
};
</script> </script>
<!-- Initialization of objects --> <!-- Initialization of objects -->