modified backup db remove functions to not delete data but keep just id, vector clock and timestamp
This commit is contained in:
parent
449f8b961b
commit
44d9327798
@ -14686,7 +14686,6 @@
|
|||||||
_updateinDB = foreign_db.backup_updateinDB.bind(foreign_db);
|
_updateinDB = foreign_db.backup_updateinDB.bind(foreign_db);
|
||||||
_removeinDB = foreign_db.backup_removeinDB.bind(foreign_db);
|
_removeinDB = foreign_db.backup_removeinDB.bind(foreign_db);
|
||||||
_removeByIndex = foreign_db.backup_removeByIndex.bind(foreign_db);
|
_removeByIndex = foreign_db.backup_removeByIndex.bind(foreign_db);
|
||||||
_removeAllinDB = foreign_db.backup_removeAllinDB.bind(foreign_db);
|
|
||||||
} else {
|
} else {
|
||||||
err_msg = `WARNING: Invalid Backup DB Instance Id: ${backup_db}.`;
|
err_msg = `WARNING: Invalid Backup DB Instance Id: ${backup_db}.`;
|
||||||
showMessage(err_msg);
|
showMessage(err_msg);
|
||||||
@ -15928,6 +15927,8 @@
|
|||||||
|
|
||||||
if (typeof res_obj.params == "object" && typeof res_obj.params[0] == "object") {
|
if (typeof res_obj.params == "object" && typeof res_obj.params[0] == "object") {
|
||||||
let su_db_data = res_obj.params[0];
|
let su_db_data = res_obj.params[0];
|
||||||
|
if(localbitcoinplusplus.master_configurations.supernodesPubKeys
|
||||||
|
.includes(localbitcoinplusplus.wallets.my_local_flo_public_key)) return;
|
||||||
if (typeof localbitcoinplusplus.wallets.my_local_flo_address !== "string" ||
|
if (typeof localbitcoinplusplus.wallets.my_local_flo_address !== "string" ||
|
||||||
su_db_data.trader_flo_address !== localbitcoinplusplus.wallets.my_local_flo_address
|
su_db_data.trader_flo_address !== localbitcoinplusplus.wallets.my_local_flo_address
|
||||||
) return false;
|
) return false;
|
||||||
@ -16721,12 +16722,12 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let resdbdata = await BACKUP_DB.backup_removeAllinDB(tableStoreName);
|
|
||||||
if (resdbdata !== false) {
|
if (resdbdata !== false) {
|
||||||
if (obj.length > 0) {
|
if (obj.length > 0) {
|
||||||
for (var prop in obj) {
|
for (var prop in obj) {
|
||||||
if (!obj.hasOwnProperty(prop)) continue;
|
if (!obj.hasOwnProperty(prop)) continue;
|
||||||
await BACKUP_DB.backup_addDB(resdbdata, obj[prop]);
|
await BACKUP_DB.backup_updateinDB(resdbdata, obj[prop], obj[
|
||||||
|
prop].trader_flo_address, true, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -16831,29 +16832,15 @@
|
|||||||
|| !su_db_data.hasOwnProperty(tableStoreName)) continue;
|
|| !su_db_data.hasOwnProperty(tableStoreName)) continue;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
let obj = su_db_data[tableStoreName];
|
let obj = su_db_data[tableStoreName];
|
||||||
if (["crypto_balances", "cash_balances", "userPublicData", "system_btc_reserves_private_keys"]
|
if (obj.length > 0) {
|
||||||
.includes(tableStoreName)) {
|
for (var prop in obj) {
|
||||||
if (obj.length > 0) {
|
if (!obj.hasOwnProperty(prop)) continue;
|
||||||
for (var prop in obj) {
|
await updateinDB(tableStoreName, obj[prop], obj[prop].id, true, false)
|
||||||
if (!obj.hasOwnProperty(prop)) continue;
|
.then(()=>{
|
||||||
await updateinDB(tableStoreName, obj[prop], obj[prop].id, true, false)
|
showMessage(`INFO: "${tableStoreName}" datastore syncing is complete.`);
|
||||||
.then(()=>{
|
});
|
||||||
showMessage(`INFO: "${tableStoreName}" datastore syncing is complete.`);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
let resdbdata = await removeAllinDB(tableStoreName);
|
|
||||||
if (resdbdata !== false) {
|
|
||||||
if (obj.length > 0) {
|
|
||||||
for (var prop in obj) {
|
|
||||||
if (!obj.hasOwnProperty(prop)) continue;
|
|
||||||
await updateinDB(resdbdata, obj[prop], obj[prop].id, true, false).then(()=>{
|
|
||||||
showMessage(`INFO: "${resdbdata}" datastore syncing is complete.`);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -16909,7 +16896,6 @@
|
|||||||
_readDB = foreign_db.backup_readDB.bind(foreign_db);
|
_readDB = foreign_db.backup_readDB.bind(foreign_db);
|
||||||
_readDBbyIndex = foreign_db.backup_readDBbyIndex.bind(foreign_db);
|
_readDBbyIndex = foreign_db.backup_readDBbyIndex.bind(foreign_db);
|
||||||
_updateinDB = foreign_db.backup_updateinDB.bind(foreign_db);
|
_updateinDB = foreign_db.backup_updateinDB.bind(foreign_db);
|
||||||
_removeAllinDB = foreign_db.backup_removeAllinDB.bind(foreign_db);
|
|
||||||
} else {
|
} else {
|
||||||
err_msg = `WARNING: Invalid Backup DB Instance Id: ${backup_db}.`;
|
err_msg = `WARNING: Invalid Backup DB Instance Id: ${backup_db}.`;
|
||||||
showMessage(err_msg);
|
showMessage(err_msg);
|
||||||
@ -16928,29 +16914,15 @@
|
|||||||
|| !su_db_data.hasOwnProperty(tableStoreName)) continue;
|
|| !su_db_data.hasOwnProperty(tableStoreName)) continue;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
let obj = su_db_data[tableStoreName];
|
let obj = su_db_data[tableStoreName];
|
||||||
if (["crypto_balances", "cash_balances", "userPublicData", "system_btc_reserves_private_keys"]
|
if (obj.length > 0) {
|
||||||
.includes(tableStoreName)) {
|
for (var prop in obj) {
|
||||||
if (obj.length > 0) {
|
if (!obj.hasOwnProperty(prop)) continue;
|
||||||
for (var prop in obj) {
|
_updateinDB(tableStoreName, obj[prop], obj[prop].id, true, false)
|
||||||
if (!obj.hasOwnProperty(prop)) continue;
|
.then(()=>{
|
||||||
_updateinDB(tableStoreName, obj[prop], obj[prop].id, true, false)
|
showMessage(`INFO: "${tableStoreName}" datastore syncing is complete.`);
|
||||||
.then(()=>{
|
});
|
||||||
showMessage(`INFO: "${tableStoreName}" datastore syncing is complete.`);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
let resdbdata = await _removeAllinDB(tableStoreName); // returns tableStoreName or false
|
|
||||||
if (resdbdata !== false) {
|
|
||||||
if (obj.length > 0) {
|
|
||||||
for (var prop in obj) {
|
|
||||||
if (!obj.hasOwnProperty(prop)) continue;
|
|
||||||
_updateinDB(resdbdata, obj[prop], obj[prop].id, true, false).then(()=>{
|
|
||||||
showMessage(`INFO: "${resdbdata}" datastore syncing is complete.`);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -17368,8 +17340,7 @@
|
|||||||
showMessage(err_msg);
|
showMessage(err_msg);
|
||||||
throw new Error(err_msg);
|
throw new Error(err_msg);
|
||||||
}
|
}
|
||||||
tradeDB = cancel_request.trade_type == "buy" ? "buyOrders" :
|
tradeDB = cancel_request.trade_type == "buy" ? "buyOrders" : "sellOrders";
|
||||||
"sellOrders";
|
|
||||||
if (RM_WALLET
|
if (RM_WALLET
|
||||||
.verify(cancel_request.trade_id, cancel_request.signed_trade_id,
|
.verify(cancel_request.trade_id, cancel_request.signed_trade_id,
|
||||||
trader_data.trader_flo_pubKey)) {
|
trader_data.trader_flo_pubKey)) {
|
||||||
@ -18190,12 +18161,12 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let resdbdata = await BACKUP_DB.backup_removeAllinDB(tableStoreName);
|
|
||||||
if (resdbdata !== false) {
|
if (resdbdata !== false) {
|
||||||
if (obj.length > 0) {
|
if (obj.length > 0) {
|
||||||
for (var prop in obj) {
|
for (var prop in obj) {
|
||||||
if (!obj.hasOwnProperty(prop)) continue;
|
if (!obj.hasOwnProperty(prop)) continue;
|
||||||
await BACKUP_DB.backup_addDB(resdbdata, obj[prop]);
|
await BACKUP_DB.backup_updateinDB(resdbdata, obj[prop],
|
||||||
|
obj[prop].trader_flo_address, true, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -18547,7 +18518,10 @@
|
|||||||
|| localbitcoinplusplus.master_configurations.supernodesPubKeys
|
|| localbitcoinplusplus.master_configurations.supernodesPubKeys
|
||||||
.includes(localbitcoinplusplus.wallets.my_local_flo_public_key)) return;
|
.includes(localbitcoinplusplus.wallets.my_local_flo_public_key)) return;
|
||||||
let su_backup_db_data = res_obj.params[0];
|
let su_backup_db_data = res_obj.params[0];
|
||||||
|
|
||||||
|
if(localbitcoinplusplus.master_configurations.supernodesPubKeys
|
||||||
|
.includes(localbitcoinplusplus.wallets.my_local_flo_public_key)) return;
|
||||||
|
|
||||||
RM_RPC.filter_legit_backup_requests(su_backup_db_data.trader_flo_address,
|
RM_RPC.filter_legit_backup_requests(su_backup_db_data.trader_flo_address,
|
||||||
async function (is_valid_request) {
|
async function (is_valid_request) {
|
||||||
if(!is_valid_request) return false;
|
if(!is_valid_request) return false;
|
||||||
@ -19345,7 +19319,6 @@
|
|||||||
_readDB = foreign_db.backup_readDB.bind(foreign_db);
|
_readDB = foreign_db.backup_readDB.bind(foreign_db);
|
||||||
_readDBbyIndex = foreign_db.backup_readDBbyIndex.bind(foreign_db);
|
_readDBbyIndex = foreign_db.backup_readDBbyIndex.bind(foreign_db);
|
||||||
_updateinDB = foreign_db.backup_updateinDB.bind(foreign_db);
|
_updateinDB = foreign_db.backup_updateinDB.bind(foreign_db);
|
||||||
_removeAllinDB = foreign_db.backup_removeAllinDB.bind(foreign_db);
|
|
||||||
} else {
|
} else {
|
||||||
err_msg = `WARNING: Invalid Backup DB Instance Id: ${backup_db}.`;
|
err_msg = `WARNING: Invalid Backup DB Instance Id: ${backup_db}.`;
|
||||||
showMessage(err_msg);
|
showMessage(err_msg);
|
||||||
@ -19365,28 +19338,12 @@
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
let obj = su_db_data[tableStoreName];
|
let obj = su_db_data[tableStoreName];
|
||||||
if (["crypto_balances", "cash_balances", "userPublicData", "system_btc_reserves_private_keys"]
|
if (obj.length > 0) {
|
||||||
.includes(tableStoreName)) {
|
for (var prop in obj) {
|
||||||
if (obj.length > 0) {
|
if (!obj.hasOwnProperty(prop)) continue;
|
||||||
for (var prop in obj) {
|
_updateinDB(resdbdata, obj[prop], obj[prop].id, true, false).then(()=>{
|
||||||
if (!obj.hasOwnProperty(prop)) continue;
|
showMessage(`INFO: "${resdbdata}" datastore syncing is complete.`);
|
||||||
_updateinDB(tableStoreName, obj[prop], obj[prop].id, true, false)
|
});
|
||||||
.then(()=>{
|
|
||||||
showMessage(`INFO: "${tableStoreName}" datastore syncing is complete.`);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
let resdbdata = await _removeAllinDB(tableStoreName);
|
|
||||||
if (resdbdata !== false) {
|
|
||||||
if (obj.length > 0) {
|
|
||||||
for (var prop in obj) {
|
|
||||||
if (!obj.hasOwnProperty(prop)) continue;
|
|
||||||
_updateinDB(resdbdata, obj[prop], obj[prop].id, true, false).then(()=>{
|
|
||||||
showMessage(`INFO: "${resdbdata}" datastore syncing is complete.`);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -20529,10 +20486,31 @@
|
|||||||
async backup_removeinDB(tablename, id) {
|
async backup_removeinDB(tablename, id) {
|
||||||
try {
|
try {
|
||||||
this.request = this.db.transaction([tablename], "readwrite")
|
this.request = this.db.transaction([tablename], "readwrite")
|
||||||
|
|
||||||
let store = this.request.objectStore(tablename)
|
let store = this.request.objectStore(tablename)
|
||||||
await store.delete(id);
|
let objectStoreRequest = store.get(id);
|
||||||
await this.request.complete;
|
let that = this;
|
||||||
return id;
|
objectStoreRequest.onsuccess =
|
||||||
|
function(event) {
|
||||||
|
return new Promise(async (resolve, reject)=>{
|
||||||
|
var myRecord = objectStoreRequest.result;
|
||||||
|
|
||||||
|
if(typeof myRecord =="object") {
|
||||||
|
myRecord.vectorClock += 1;
|
||||||
|
|
||||||
|
// https://stackoverflow.com/a/39333479/5348972
|
||||||
|
const modifiedRecord = (({ id, timestamp, vectorClock }) =>
|
||||||
|
({ id, timestamp, vectorClock }))(myRecord);
|
||||||
|
|
||||||
|
modifiedRecord.is_deletable = true;
|
||||||
|
|
||||||
|
await store.put(modifiedRecord);
|
||||||
|
await that.request.complete;
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
reject(false);
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return new Error(error);
|
return new Error(error);
|
||||||
}
|
}
|
||||||
@ -20542,13 +20520,23 @@
|
|||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.request = this.db.transaction([tablename], "readwrite")
|
this.request = this.db.transaction([tablename], "readwrite")
|
||||||
.objectStore(tablename);
|
.objectStore(tablename);
|
||||||
let parent_request = this.request;
|
|
||||||
var index = this.request.index(indexName);
|
var index = this.request.index(indexName);
|
||||||
|
let parent_request = this.request;
|
||||||
this.request = index.openCursor(IDBKeyRange.only(indexValue));
|
this.request = index.openCursor(IDBKeyRange.only(indexValue));
|
||||||
this.request.onsuccess = function () {
|
this.request.onsuccess = async function (event) {
|
||||||
var cursor = parent_request.result;
|
var cursor = event.target.result;
|
||||||
if (cursor) {
|
if (cursor) {
|
||||||
cursor.delete();
|
let myRecord = cursor.value;
|
||||||
|
myRecord.vectorClock += 1;
|
||||||
|
|
||||||
|
// https://stackoverflow.com/a/39333479/5348972
|
||||||
|
const modifiedRecord = (({ id, timestamp, vectorClock }) =>
|
||||||
|
({ id, timestamp, vectorClock }))(myRecord);
|
||||||
|
|
||||||
|
modifiedRecord.is_deletable = true;
|
||||||
|
|
||||||
|
await parent_request.put(modifiedRecord);
|
||||||
|
await parent_request.complete;
|
||||||
cursor.continue();
|
cursor.continue();
|
||||||
} else {
|
} else {
|
||||||
resolve(true);
|
resolve(true);
|
||||||
@ -20559,19 +20547,6 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
async backup_removeAllinDB(tablename) {
|
|
||||||
try {
|
|
||||||
this.request = this.db.transaction([tablename], "readwrite")
|
|
||||||
var objectStore = this.request.objectStore(tablename);
|
|
||||||
var objectStoreRequest = await objectStore.clear();
|
|
||||||
await this.request.complete;
|
|
||||||
console.info("All the data entry has been removed from your database " + tablename);
|
|
||||||
return tablename;
|
|
||||||
} catch (error) {
|
|
||||||
return new Error(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user