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,26 +20597,22 @@
.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 let response_for_client = {
) trade_infos: trade_infos,
.then(getPrimarySuObj => { buyer_cash_data: balanceUpdatePromises[0],
let response_for_client = { seller_cash_data: balanceUpdatePromises[1],
trade_infos: trade_infos, buyer_btc_data: balanceUpdatePromises[2],
buyer_cash_data: balanceUpdatePromises[0], seller_btc_data: balanceUpdatePromises[3],
seller_cash_data: balanceUpdatePromises[1], data_hash: hashed_data,
buyer_btc_data: balanceUpdatePromises[2], supernode_sign: signed_data,
seller_btc_data: balanceUpdatePromises[3], supernodePubKey:
data_hash: hashed_data, user_data.myLocalFLOPublicKey,
supernode_sign: signed_data, trader_flo_address:
supernodePubKey: getPrimarySuObj[0].data.id
user_data.myLocalFLOPublicKey, };
trader_flo_address: return response_for_client;
getPrimarySuObj[0].data.id
};
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) {
return seen_chunk_id_list.hasOwnProperty( if (typeof item.private_key_chunk !== "undefined") {
item.private_key_chunk.id return seen_chunk_id_list.hasOwnProperty(
) item.private_key_chunk.id
? false )
: seen_chunk_id_list.push(item.private_key_chunk.id); ? false
: 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,32 +29389,32 @@
reject(e); reject(e);
}; };
}); });
},
backup_removeAllinDB(tablename="") {
return new Promise((resolve, reject) => {
try {
this.request = this.db.transaction([tablename], "readwrite");
var objectStore = this.request.objectStore(tablename);
var objectStoreRequest = objectStore.clear();
objectStoreRequest.onsuccess = function(event) {
console.info(
"All the data entry has been removed from backup database " +
tablename
);
resolve(tablename);
};
objectStoreRequest.onerror = function(event) {
reject(event);
}
} catch (error) {
reject(event);
return new Error(error);
}
});
} }
}; };
function backup_removeAllinDB(tablename="") {
return new Promise((resolve, reject) => {
try {
this.request = this.db.transaction([tablename], "readwrite");
var objectStore = this.request.objectStore(tablename);
var objectStoreRequest = objectStore.clear();
objectStoreRequest.onsuccess = function(event) {
console.info(
"All the data entry has been removed from backup database " +
tablename
);
resolve(tablename);
};
objectStoreRequest.onerror = function(event) {
reject(event);
}
} catch (error) {
reject(event);
return new Error(error);
}
});
}
</script> </script>
<!-- Initialization of objects --> <!-- Initialization of objects -->