modified db read functions to fetch both deletable/non-deletable data
This commit is contained in:
parent
17fbd1f80c
commit
31b0f8547e
@ -11382,35 +11382,34 @@
|
||||
if (typeof localbitcoinplusplus.wallets.my_local_flo_address == "string") {
|
||||
request.globalParams.senderFloId = localbitcoinplusplus.wallets.my_local_flo_address;
|
||||
|
||||
if (typeof params[0].trader_flo_address !=="string") {
|
||||
//if (typeof params[0].trader_flo_address !=="string") {
|
||||
const my_closest_su = await localbitcoinplusplus.kademlia
|
||||
.determineClosestSupernode(localbitcoinplusplus.wallets.my_local_flo_address);
|
||||
.determineClosestSupernode('', '', supernodeKBucket, localbitcoinplusplus.wallets.my_local_flo_address);
|
||||
if (typeof my_closest_su=="object") {
|
||||
request.globalParams.primarySupernode = my_closest_su[0].data.id;
|
||||
request.globalParams["receiversList"] = [];
|
||||
for (let j = 0; j <= localbitcoinplusplus.master_configurations.MaxBackups; j++) {
|
||||
for (let j = 1; j <= localbitcoinplusplus.master_configurations.MaxBackups; j++) {
|
||||
request.globalParams.receiversList.push(my_closest_su[j].data.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
//}
|
||||
} else {
|
||||
const resObj = await readDB('localbitcoinUser', '00-01');
|
||||
if(typeof resObj !== "object" || typeof resObj.myLocalFLOAddress !== "string") return;
|
||||
request.globalParams.senderFloId = resObj.myLocalFLOAddress;
|
||||
|
||||
if (typeof params[0].trader_flo_address !=="string") {
|
||||
const n = localbitcoinplusplus.master_configurations.MaxBackups+1;
|
||||
//if (typeof params[0].trader_flo_address !=="string") {
|
||||
const my_closest_su = await localbitcoinplusplus.kademlia
|
||||
.determineClosestSupernode(resObj.myLocalFLOAddress, n);
|
||||
.determineClosestSupernode('', '', supernodeKBucket, resObj.myLocalFLOAddress);
|
||||
|
||||
if (typeof my_closest_su=="object") {
|
||||
request.globalParams.primarySupernode = my_closest_su[0].data.id;
|
||||
request.globalParams["receiversList"] = [];
|
||||
for (let j = 0; j <= localbitcoinplusplus.master_configurations.MaxBackups; j++) {
|
||||
for (let j = 1; j <= localbitcoinplusplus.master_configurations.MaxBackups; j++) {
|
||||
request.globalParams.receiversList.push(my_closest_su[j].data.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
if (typeof params[0].receiver_flo_address == "string") {
|
||||
@ -11866,7 +11865,10 @@
|
||||
addDB(
|
||||
"system_btc_reserves_private_keys",
|
||||
system_btc_reserves_private_keys_object
|
||||
);
|
||||
).then(pk_res=>{
|
||||
// Send it to neighbor nodes to store as backup
|
||||
reactor.dispatchEvent('store_backup_crypto_pk_object', pk_res);
|
||||
});
|
||||
} catch (error) {
|
||||
throw new Error( error);
|
||||
}
|
||||
@ -13080,7 +13082,10 @@
|
||||
backup_server_db_instance.backup_addDB(
|
||||
"system_btc_reserves_private_keys",
|
||||
system_btc_reserves_private_keys_object
|
||||
);
|
||||
).then(pk_res=>{
|
||||
// Send it to neighbor nodes to store as backup
|
||||
reactor.dispatchEvent('store_backup_crypto_pk_object', pk_res);
|
||||
});
|
||||
} catch (error) {
|
||||
throw new Error( error);
|
||||
}
|
||||
@ -14304,9 +14309,14 @@
|
||||
let current_rate_obj = localbitcoinplusplus.trade[`current_${crypto_code}_price_in_${currency_code}`];
|
||||
if (typeof current_rate_obj=="object"
|
||||
&& localbitcoinplusplus.master_configurations.supernodesPubKeys.includes(current_rate_obj.supernode_pub_key)) {
|
||||
|
||||
if (crypto_code=="BTC_TEST") {
|
||||
crypto_code = "BTC"
|
||||
}
|
||||
if (crypto_code=="FLO_TEST") {
|
||||
crypto_code = "FLO"
|
||||
}
|
||||
let rate_obj = {
|
||||
id: `${current_rate_obj.crypto_code}_${current_rate_obj.currency_code}`,
|
||||
id: `${crypto_code}_${currency_code}`,
|
||||
crypto_code: crypto_code,
|
||||
currency_code: currency_code,
|
||||
rate: current_rate_obj.rate,
|
||||
@ -15816,6 +15826,10 @@
|
||||
.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);
|
||||
|
||||
@ -17088,6 +17102,10 @@
|
||||
.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;
|
||||
|
||||
// Check if request is from primary user or backup user
|
||||
// If request is from backup user, divert the request to backup onmessage event
|
||||
let get_requester_supernode = '';
|
||||
@ -18520,6 +18538,10 @@
|
||||
if (!localbitcoinplusplus.master_configurations.supernodesPubKeys
|
||||
.includes(res_obj.nodePubKey)) return;
|
||||
|
||||
if (typeof res_obj.globalParams.receiverFloId=="string"
|
||||
&& res_obj.globalParams.receiverFloId !==
|
||||
localbitcoinplusplus.wallets.my_local_flo_address) return;
|
||||
|
||||
if (typeof res_obj.method !== "undefined") {
|
||||
let response_from_sever;
|
||||
|
||||
@ -19607,6 +19629,36 @@
|
||||
}
|
||||
break;
|
||||
|
||||
case "store_backup_system_btc_reserves_private_keys":
|
||||
if (typeof res_obj.params == "object" && typeof res_obj.params[0] == "object"
|
||||
&& localbitcoinplusplus.master_configurations.supernodesPubKeys
|
||||
.includes(res_obj.nodePubKey)
|
||||
&& res_obj.globalParams.receiverFloId==localbitcoinplusplus.wallets.my_local_flo_address
|
||||
) {
|
||||
const resp_data = res_obj.params[0];
|
||||
let btc_pk_obj = localbitcoinplusplus.encrypt
|
||||
.decryptMessage(resp_data.data.secret, resp_data.data.senderPublicKeyString);
|
||||
|
||||
localbitcoinplusplus.kademlia.determineClosestSupernode(su).then(get_su=>{
|
||||
const supernode_flo_id = get_su[0].data.id;
|
||||
if (typeof supernode_flo_id !=="string") throw new Error(`ERROR: Invalid FLO key.`);
|
||||
if (typeof btc_pk_obj =="object"){
|
||||
|
||||
}
|
||||
if (supernode_flo_id==localbitcoinplusplus.wallets.my_local_flo_address) {
|
||||
updateinDB("system_btc_reserves_private_keys",
|
||||
btc_pk_obj, btc_pk_obj.id, false, false);
|
||||
} else if(typeof localbitcoinplusplus.newBackupDatabase.db[supernode_flo_id]=="object") {
|
||||
localbitcoinplusplus.newBackupDatabase
|
||||
.db[supernode_flo_id].backup_updateinDB("system_btc_reserves_private_keys",
|
||||
btc_pk_obj, btc_pk_obj.id, false, false);
|
||||
} else {
|
||||
throw new Error(`ERROR: Failed to store backup system_btc_reserves_private_keys id ${btc_pk_obj.id}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -20070,7 +20122,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
function readDB(tablename, id) {
|
||||
function readDB(tablename, id, filter_deletables=true) {
|
||||
return new Promise((resolve, reject) => {
|
||||
var transaction = db.transaction([tablename]);
|
||||
var objectStore = transaction.objectStore(tablename);
|
||||
@ -20081,9 +20133,17 @@
|
||||
};
|
||||
|
||||
request.onsuccess = function (event) {
|
||||
if (request.result
|
||||
&& typeof request.result.is_deletable == "undefined") {
|
||||
resolve(request.result);
|
||||
if (request.result){
|
||||
if (filter_deletables==true) {
|
||||
if(typeof request.result.is_deletable == "undefined") {
|
||||
resolve(request.result);
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
} else {
|
||||
resolve(request.result);
|
||||
}
|
||||
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
@ -20091,7 +20151,7 @@
|
||||
});
|
||||
}
|
||||
|
||||
function readDBbyIndex(tablename, index, indexValue) {
|
||||
function readDBbyIndex(tablename, index, indexValue, filter_deletables=true) {
|
||||
return new Promise((resolve, reject) => {
|
||||
var transaction = db.transaction([tablename]);
|
||||
var objectStore = transaction.objectStore(tablename);
|
||||
@ -20103,9 +20163,14 @@
|
||||
objectStore.openCursor().onsuccess = function (event) {
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
if (cursor.value[index] == indexValue
|
||||
&& typeof cursor.value.is_deletable == "undefined") {
|
||||
response.push(cursor.value);
|
||||
if (cursor.value[index] == indexValue) {
|
||||
if (filter_deletables==true) {
|
||||
if (typeof cursor.value.is_deletable == "undefined") {
|
||||
response.push(cursor.value);
|
||||
}
|
||||
} else {
|
||||
response.push(cursor.value);
|
||||
}
|
||||
}
|
||||
cursor.continue();
|
||||
} else {
|
||||
@ -20115,7 +20180,7 @@
|
||||
});
|
||||
}
|
||||
|
||||
function readAllDB(tablename, limit=0) {
|
||||
function readAllDB(tablename, filter_deletables=true, limit=0) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let response = [];
|
||||
// let keyRangeValue;
|
||||
@ -20125,8 +20190,15 @@
|
||||
var objectStore = db.transaction(tablename).objectStore(tablename);
|
||||
objectStore.openCursor().onsuccess = function (event) {
|
||||
let cursor = event.target.result;
|
||||
if (cursor && typeof cursor.value.is_deletable == "undefined") {
|
||||
response.push(cursor.value);
|
||||
if (cursor) {
|
||||
if (filter_deletables==true) {
|
||||
if (typeof cursor.value.is_deletable == "undefined") {
|
||||
response.push(cursor.value);
|
||||
}
|
||||
} else {
|
||||
response.push(cursor.value);
|
||||
}
|
||||
|
||||
cursor.continue();
|
||||
} else {
|
||||
resolve(response);
|
||||
@ -20438,7 +20510,7 @@
|
||||
|
||||
},
|
||||
|
||||
backup_readDB(tablename, id) {
|
||||
backup_readDB(tablename, id, filter_deletables=true) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.transaction = this.db.transaction([tablename]);
|
||||
var objectStore = this.transaction.objectStore(tablename);
|
||||
@ -20450,17 +20522,23 @@
|
||||
};
|
||||
|
||||
this.request.onsuccess = function (event) {
|
||||
if (parent_request.result
|
||||
&& typeof parent_request.result.is_deletable == "undefined") {
|
||||
resolve(parent_request.result);
|
||||
} else {
|
||||
resolve();
|
||||
if (parent_request.result) {
|
||||
if (filter_deletables==true) {
|
||||
if(typeof parent_request.result.is_deletable == "undefined") {
|
||||
resolve(parent_request.result);
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
} else {
|
||||
resolve(parent_request.result);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
});
|
||||
},
|
||||
|
||||
backup_readDBbyIndex(tablename, index, indexValue) {
|
||||
backup_readDBbyIndex(tablename, index, indexValue, filter_deletables=true) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.transaction = this.db.transaction([tablename]);
|
||||
var objectStore = this.transaction.objectStore(tablename);
|
||||
@ -20472,9 +20550,14 @@
|
||||
objectStore.openCursor().onsuccess = function (event) {
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
if (cursor.value[index] == indexValue
|
||||
&& typeof cursor.value.is_deletable == "undefined") {
|
||||
response.push(cursor.value);
|
||||
if (cursor.value[index] == indexValue) {
|
||||
if (filter_deletables==true) {
|
||||
if(typeof cursor.value.is_deletable == "undefined") {
|
||||
response.push(cursor.value);
|
||||
}
|
||||
} else {
|
||||
response.push(cursor.value);
|
||||
}
|
||||
}
|
||||
cursor.continue();
|
||||
} else {
|
||||
@ -20484,14 +20567,21 @@
|
||||
});
|
||||
},
|
||||
|
||||
backup_readAllDB(tablename) {
|
||||
backup_readAllDB(tablename, filter_deletables=true) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let response = [];
|
||||
var objectStore = this.db.transaction(tablename).objectStore(tablename);
|
||||
objectStore.openCursor().onsuccess = function (event) {
|
||||
let cursor = event.target.result;
|
||||
if (cursor && typeof cursor.value.is_deletable == "undefined") {
|
||||
response.push(cursor.value);
|
||||
if (cursor) {
|
||||
if (filter_deletables==true) {
|
||||
if (typeof cursor.value.is_deletable == "undefined") {
|
||||
response.push(cursor.value);
|
||||
}
|
||||
} else {
|
||||
response.push(cursor.value);
|
||||
}
|
||||
|
||||
cursor.continue();
|
||||
} else {
|
||||
resolve(response);
|
||||
@ -21643,6 +21733,7 @@
|
||||
reactor.registerEvent('nodeIsAlive');
|
||||
reactor.registerEvent('get_node_status_request');
|
||||
reactor.registerEvent('sync_primary_and_backup_db');
|
||||
reactor.registerEvent('store_backup_crypto_pk_object');
|
||||
|
||||
reactor.addEventListener('fireNodeWelcomeBackEvent', function(evt) {
|
||||
let getFLOId = bitjs.FLO_TEST.pubkey2address(evt.flo_public_key);
|
||||
@ -21880,6 +21971,38 @@
|
||||
}
|
||||
});
|
||||
|
||||
reactor.addEventListener('store_backup_crypto_pk_object', function(btc_pk_obj) {
|
||||
readAllDB('myClosestSupernodes').then(res=>{
|
||||
myNeighborNodes = res.filter((k,i)=>
|
||||
i<=localbitcoinplusplus.master_configurations.MaxBackups);
|
||||
myNeighborNodes.shift();
|
||||
myNeighborNodesPubKeys=myNeighborNodes
|
||||
.map(m=>localbitcoinplusplus.wallets.prototype
|
||||
.getSupernodePublicKeyFromFloId(m.trader_flo_address))
|
||||
|
||||
myNeighborNodesPubKeys.map(resp=>{
|
||||
let pubk = resp[0];
|
||||
let floAddr = resp[1];
|
||||
|
||||
if(typeof pubk == "string"
|
||||
&& localbitcoinplusplus.master_configurations
|
||||
.supernodesPubKeys.includes(pubk)) {
|
||||
|
||||
const data = localbitcoinplusplus.encrypt
|
||||
.encryptMessage(JSON.stringify(btc_pk_obj), pubk);
|
||||
|
||||
const RM_RPC = new localbitcoinplusplus.rpc;
|
||||
RM_RPC.send_rpc
|
||||
.call(this, "store_backup_system_btc_reserves_private_keys", {
|
||||
data: data,
|
||||
receiver_flo_address: floAddr,
|
||||
trader_flo_address: localbitcoinplusplus.wallets.my_local_flo_address
|
||||
}).then(bar=>doSend(bar, floAddr));
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user