updated to latest standard_operations and store supernode details in IDB
This commit is contained in:
parent
f2da7f0a35
commit
65284528a5
180
index.html
180
index.html
@ -5115,81 +5115,43 @@
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
//Read Data Sent from Address (if limit is specified, only return newest sent data)
|
/*Read flo Data from txs of given Address
|
||||||
readSentData: function (addr, limit = 0) {
|
options can be used to filter data
|
||||||
return new Promise((resolve, reject) => {
|
limit : maximum number of filtered data (default = 1000, negative = no limit)
|
||||||
this.readAllTxs(addr).then(items => {
|
ignoreOld : ignore old txs (default = 0)
|
||||||
var filteredItems = [];
|
sentOnly : filters only sent data
|
||||||
if (limit <= 0) limit = items.length;
|
pattern : filters data that starts with a pattern
|
||||||
for (i = 0; i < items.length && filteredItems.length < limit; i++)
|
contains : filters data that contains a string
|
||||||
if (items[i].vin[0].addr === addr)
|
filter : custom filter funtion for floData (eg . filter: d => {return d[0] == '$'})
|
||||||
filteredItems.push(items[i].floData);
|
*/
|
||||||
console.log(filteredItems);
|
readData: function(addr,options = {}){
|
||||||
resolve(filteredItems);
|
options.limit = options.limit | 1000
|
||||||
|
options.ignoreOld = options.ignoreOld | 0
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
this.promisedAJAX("GET", `api/addrs/${addr}/txs?from=0&to=1`).then(response => {
|
||||||
|
var newItems = JSON.parse(response).totalItems - options.ignoreOld;
|
||||||
|
this.promisedAJAX("GET", `api/addrs/${addr}/txs?from=0&to=${newItems*2}`).then(response => {
|
||||||
|
response = JSON.parse(response)
|
||||||
|
if (options.limit <= 0)
|
||||||
|
options.limit = response.items.length;
|
||||||
|
var filteredData = [];
|
||||||
|
for (i = 0; i < (response.totalItems - options.ignoreOld) && filteredData.length < options.limit; i++){
|
||||||
|
if(options.sentOnly && response.items[i].vin[0].addr !== addr)
|
||||||
|
continue;
|
||||||
|
if(options.pattern && !response.items[i].floData.startsWith(options.pattern, 0) && !response.items[i].floData.startsWith(options.pattern, 2))
|
||||||
|
continue;
|
||||||
|
if(options.contains && !response.items[i].floData.includes(options.contains))
|
||||||
|
continue;
|
||||||
|
if(options.filter && !options.filter(response.items[i].floData))
|
||||||
|
continue;
|
||||||
|
filteredData.push(response.items[i].floData);
|
||||||
|
}
|
||||||
|
resolve({totalTxs:response.totalItems , data:filteredData});
|
||||||
|
}).catch(error => {
|
||||||
|
reject(error);
|
||||||
|
});
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
reject(error)
|
reject(error);
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
//Read newest 'limit' Data matching 'pattern'
|
|
||||||
readDataPattern: function (addr, pattern, jsonType = false, limit = 1000) {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
this.readAllTxs(addr).then(items => {
|
|
||||||
var filteredItems = [];
|
|
||||||
var pos = (jsonType ? 2 : 0);
|
|
||||||
for (i = 0; i < items.length && filteredItems.length < limit; i++)
|
|
||||||
if (items[i].floData.startsWith(pattern, pos))
|
|
||||||
filteredItems.push(items[i].floData);
|
|
||||||
resolve(filteredItems);
|
|
||||||
}).catch(error => {
|
|
||||||
reject(error)
|
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
//Read newest 'limit' Data Sent from Address and matching 'pattern'
|
|
||||||
readSentDataPattern: function (addr, pattern, jsonType = false, limit = 1000) {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
this.readAllTxs(addr).then(items => {
|
|
||||||
var filteredItems = [];
|
|
||||||
var pos = (jsonType ? 2 : 0);
|
|
||||||
for (i = 0; i < items.length && filteredItems.length < limit; i++)
|
|
||||||
if (items[i].vin[0].addr === addr && items[i].floData.startsWith(pattern, pos))
|
|
||||||
filteredItems.push(items[i].floData);
|
|
||||||
resolve(filteredItems);
|
|
||||||
}).catch(error => {
|
|
||||||
reject(error)
|
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
//Read newest 'limit' Data containing 'keyword'
|
|
||||||
readDataContains: function (addr, keyword, limit = 1000) {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
this.readAllTxs(addr).then(items => {
|
|
||||||
var filteredItems = [];
|
|
||||||
for (i = 0; i < items.length && filteredItems.length < limit; i++)
|
|
||||||
if (items[i].floData.includes(keyword))
|
|
||||||
filteredItems.push(items[i].floData);
|
|
||||||
resolve(filteredItems);
|
|
||||||
}).catch(error => {
|
|
||||||
reject(error)
|
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
//Read newest 'limit' Data Sent from Address and containing 'keyword'
|
|
||||||
readSentDataContains: function (addr, keyword, limit = 1000) {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
this.readAllTxs(addr).then(items => {
|
|
||||||
var filteredItems = [];
|
|
||||||
for (i = 0; i < items.length && filteredItems.length < limit; i++)
|
|
||||||
if (items[i].vin[0].addr === addr && items[i].floData.includes(keyword))
|
|
||||||
filteredItems.push(items[i].floData);
|
|
||||||
resolve(filteredItems);
|
|
||||||
}).catch(error => {
|
|
||||||
reject(error)
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -5516,6 +5478,19 @@
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
removeData: function (obsName, key, dbName = this.dbName) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
this.openDB(dbName).then(db => {
|
||||||
|
var obs = db.transaction(obsName, "readwrite").objectStore(obsName);
|
||||||
|
let delReq = obs.delete(key);
|
||||||
|
delReq.onsuccess = (evt) => resolve(`Removed Data ${key}`);
|
||||||
|
delReq.onerror = (evt) => reject(
|
||||||
|
`Remove data unsuccessful [${evt.target.error.name}] ${evt.target.error.message}`);
|
||||||
|
db.close();
|
||||||
|
}).catch(error => reject(error));
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
readData: function (obsName, key, dbName = this.dbName) {
|
readData: function (obsName, key, dbName = this.dbName) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.openDB(dbName).then(db => {
|
this.openDB(dbName).then(db => {
|
||||||
@ -6007,16 +5982,12 @@
|
|||||||
var obj = {
|
var obj = {
|
||||||
lastTx:{},
|
lastTx:{},
|
||||||
supernodes:{
|
supernodes:{
|
||||||
options:{keyPath:"floID"},
|
indexes:{ uri:null, pubKey:null }
|
||||||
indexes:{
|
|
||||||
uri:null,
|
|
||||||
pubKey:null
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for(var i=0;i<storageList.length;i++){
|
for(var i=0;i<storageList.length;i++){
|
||||||
obj[storageList[i]] = {
|
obj[storageList[i]] = {
|
||||||
options:{keyPath:primaryKey},
|
options:{keyPath:primaryKey,autoIncrement:true},
|
||||||
indexes:{}
|
indexes:{}
|
||||||
}
|
}
|
||||||
for(var j=0;j<IndexesList.length;j++)
|
for(var j=0;j<IndexesList.length;j++)
|
||||||
@ -6030,43 +6001,24 @@
|
|||||||
|
|
||||||
function readSupernodeListFromAPI(){
|
function readSupernodeListFromAPI(){
|
||||||
return new Promise((resolve,reject) => {
|
return new Promise((resolve,reject) => {
|
||||||
floBlockchainAPI.readSentDataPattern(floGlobals.adminID,"SuperNode",true)
|
compactIDB.readData("lastTx",floGlobals.adminID).then(lastTx => {
|
||||||
.then(result => {
|
floBlockchainAPI.readData(floGlobals.adminID,{ignoreOld:lastTx,sendOnly:true,pattern:"SuperNodeStorage"}).then(result => {
|
||||||
for(var i=0;i<result.length;i++){
|
for(var i=result.length-1;i>=0;i--){
|
||||||
var content = JSON.parse(result[i]).SuperNode;
|
var content = JSON.parse(result[i]).SuperNodeStorage;
|
||||||
for(sn in content)
|
for(sn in content.removeNodes)
|
||||||
if(!(sn in floGlobals.supernodes))
|
compactIDB.removeData("supernodes",sn);
|
||||||
floGlobals.supernodes[sn] = content[sn]
|
for(sn in content.addNodes)
|
||||||
resolve("Read supernode ")
|
compactIDB.writeData("supernodes",content.addNodes[sn],sn);
|
||||||
}
|
}
|
||||||
}).catch(error => reject(error))
|
compactIDB.writeData("lastTx",result.totalTxs,floGlobals.adminID);
|
||||||
|
compactIDB.readAllData("supernodes").then(result => {
|
||||||
|
floGlobals.supernodes = result
|
||||||
|
resolve("Read supernode from blockchain");
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}).catch(error => reject(error))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function editInternDetails(about,contact){
|
|
||||||
var data = {
|
|
||||||
floID:myFloID,
|
|
||||||
internDetails: {about:about,contact:contact},
|
|
||||||
time:Date.now(),
|
|
||||||
}
|
|
||||||
data.sign = floCrypto.signData(JSON.stringify(data.internDetails)+data.time,myPrivKey)
|
|
||||||
|
|
||||||
floSupernode.sendData(JSON.stringify(data),myFloID)
|
|
||||||
.then(result => console.log(result))
|
|
||||||
.catch(error => console.log(error))
|
|
||||||
}
|
|
||||||
function updateInternDetails(about,contact){
|
|
||||||
var data = {
|
|
||||||
floID:myFloID,
|
|
||||||
internDetails: {about:about,contact:contact},
|
|
||||||
time:Date.now(),
|
|
||||||
}
|
|
||||||
data.sign = floCrypto.signData(JSON.stringify(data.internDetails)+data.time,myPrivKey)
|
|
||||||
|
|
||||||
floSupernode.sendData(JSON.stringify(data),myFloID)
|
|
||||||
.then(result => console.log(result))
|
|
||||||
.catch(error => console.log(error))
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user