floDapps v2.4.1
- support for multiple cloud networks
This commit is contained in:
parent
471f291848
commit
5be35c28ce
52
floDapps.js
52
floDapps.js
@ -1,4 +1,4 @@
|
|||||||
(function (EXPORTS) { //floDapps v2.4.0
|
(function (EXPORTS) { //floDapps v2.4.1
|
||||||
/* General functions for FLO Dapps*/
|
/* General functions for FLO Dapps*/
|
||||||
'use strict';
|
'use strict';
|
||||||
const floDapps = EXPORTS;
|
const floDapps = EXPORTS;
|
||||||
@ -172,12 +172,7 @@
|
|||||||
//general
|
//general
|
||||||
lastTx: {},
|
lastTx: {},
|
||||||
//supernode (cloud list)
|
//supernode (cloud list)
|
||||||
supernodes: {
|
supernodes: {}
|
||||||
indexes: {
|
|
||||||
uri: null,
|
|
||||||
pubKey: null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
var obs_a = {
|
var obs_a = {
|
||||||
//login credentials
|
//login credentials
|
||||||
@ -257,7 +252,8 @@
|
|||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (!startUpOptions.cloud)
|
if (!startUpOptions.cloud)
|
||||||
return resolve("No cloud for this app");
|
return resolve("No cloud for this app");
|
||||||
compactIDB.readData("lastTx", floCloudAPI.SNStorageID, DEFAULT.root).then(lastTx => {
|
const CLOUD_KEY = "floCloudAPI#" + floCloudAPI.SNStorageID;
|
||||||
|
compactIDB.readData("lastTx", CLOUD_KEY, DEFAULT.root).then(lastTx => {
|
||||||
var query_options = { sentOnly: true, pattern: floCloudAPI.SNStorageName };
|
var query_options = { sentOnly: true, pattern: floCloudAPI.SNStorageName };
|
||||||
if (typeof lastTx == 'number') //lastTx is tx count (*backward support)
|
if (typeof lastTx == 'number') //lastTx is tx count (*backward support)
|
||||||
query_options.ignoreOld = lastTx;
|
query_options.ignoreOld = lastTx;
|
||||||
@ -265,25 +261,27 @@
|
|||||||
query_options.after = lastTx;
|
query_options.after = lastTx;
|
||||||
//fetch data from flosight
|
//fetch data from flosight
|
||||||
floBlockchainAPI.readData(floCloudAPI.SNStorageID, query_options).then(result => {
|
floBlockchainAPI.readData(floCloudAPI.SNStorageID, query_options).then(result => {
|
||||||
for (var i = result.data.length - 1; i >= 0; i--) {
|
compactIDB.readData("supernodes", CLOUD_KEY, DEFAULT.root).then(nodes => {
|
||||||
var content = JSON.parse(result.data[i])[floCloudAPI.SNStorageName];
|
nodes = nodes || {};
|
||||||
for (let sn in content.removeNodes)
|
for (var i = result.data.length - 1; i >= 0; i--) {
|
||||||
compactIDB.removeData("supernodes", sn, DEFAULT.root);
|
var content = JSON.parse(result.data[i])[floCloudAPI.SNStorageName];
|
||||||
for (let sn in content.newNodes)
|
for (let sn in content.removeNodes)
|
||||||
compactIDB.writeData("supernodes", content.newNodes[sn], sn, DEFAULT.root);
|
delete nodes[sn];
|
||||||
for (let sn in content.updateNodes)
|
for (let sn in content.newNodes)
|
||||||
compactIDB.readData("supernodes", sn, DEFAULT.root).then(r => {
|
nodes[sn] = content.newNodes[sn];
|
||||||
r = r || {}
|
for (let sn in content.updateNodes)
|
||||||
r.uri = content.updateNodes[sn];
|
if (sn in nodes) //check if node is listed
|
||||||
compactIDB.writeData("supernodes", r, sn, DEFAULT.root);
|
nodes[sn].uri = content.updateNodes[sn];
|
||||||
});
|
}
|
||||||
}
|
Promise.all([
|
||||||
compactIDB.writeData("lastTx", result.lastItem, floCloudAPI.SNStorageID, DEFAULT.root);
|
compactIDB.writeData("lastTx", result.lastItem, CLOUD_KEY, DEFAULT.root),
|
||||||
compactIDB.readAllData("supernodes", DEFAULT.root).then(nodes => {
|
compactIDB.writeData("supernodes", nodes, CLOUD_KEY, DEFAULT.root)
|
||||||
floCloudAPI.init(nodes)
|
]).then(_ => {
|
||||||
.then(result => resolve("Loaded Supernode list\n" + result))
|
floCloudAPI.init(nodes)
|
||||||
.catch(error => reject(error))
|
.then(result => resolve("Loaded Supernode list\n" + result))
|
||||||
})
|
.catch(error => reject(error))
|
||||||
|
}).catch(error => reject(error))
|
||||||
|
}).catch(error => reject(error))
|
||||||
})
|
})
|
||||||
}).catch(error => reject(error))
|
}).catch(error => reject(error))
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user