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)
|
||||
readSentData: function (addr, limit = 0) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.readAllTxs(addr).then(items => {
|
||||
var filteredItems = [];
|
||||
if (limit <= 0) limit = items.length;
|
||||
for (i = 0; i < items.length && filteredItems.length < limit; i++)
|
||||
if (items[i].vin[0].addr === addr)
|
||||
filteredItems.push(items[i].floData);
|
||||
console.log(filteredItems);
|
||||
resolve(filteredItems);
|
||||
/*Read flo Data from txs of given Address
|
||||
options can be used to filter data
|
||||
limit : maximum number of filtered data (default = 1000, negative = no limit)
|
||||
ignoreOld : ignore old txs (default = 0)
|
||||
sentOnly : filters only sent data
|
||||
pattern : filters data that starts with a pattern
|
||||
contains : filters data that contains a string
|
||||
filter : custom filter funtion for floData (eg . filter: d => {return d[0] == '$'})
|
||||
*/
|
||||
readData: function(addr,options = {}){
|
||||
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 => {
|
||||
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)
|
||||
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) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.openDB(dbName).then(db => {
|
||||
@ -6007,16 +5982,12 @@
|
||||
var obj = {
|
||||
lastTx:{},
|
||||
supernodes:{
|
||||
options:{keyPath:"floID"},
|
||||
indexes:{
|
||||
uri:null,
|
||||
pubKey:null
|
||||
}
|
||||
indexes:{ uri:null, pubKey:null }
|
||||
}
|
||||
}
|
||||
for(var i=0;i<storageList.length;i++){
|
||||
obj[storageList[i]] = {
|
||||
options:{keyPath:primaryKey},
|
||||
options:{keyPath:primaryKey,autoIncrement:true},
|
||||
indexes:{}
|
||||
}
|
||||
for(var j=0;j<IndexesList.length;j++)
|
||||
@ -6030,43 +6001,24 @@
|
||||
|
||||
function readSupernodeListFromAPI(){
|
||||
return new Promise((resolve,reject) => {
|
||||
floBlockchainAPI.readSentDataPattern(floGlobals.adminID,"SuperNode",true)
|
||||
.then(result => {
|
||||
for(var i=0;i<result.length;i++){
|
||||
var content = JSON.parse(result[i]).SuperNode;
|
||||
for(sn in content)
|
||||
if(!(sn in floGlobals.supernodes))
|
||||
floGlobals.supernodes[sn] = content[sn]
|
||||
resolve("Read supernode ")
|
||||
compactIDB.readData("lastTx",floGlobals.adminID).then(lastTx => {
|
||||
floBlockchainAPI.readData(floGlobals.adminID,{ignoreOld:lastTx,sendOnly:true,pattern:"SuperNodeStorage"}).then(result => {
|
||||
for(var i=result.length-1;i>=0;i--){
|
||||
var content = JSON.parse(result[i]).SuperNodeStorage;
|
||||
for(sn in content.removeNodes)
|
||||
compactIDB.removeData("supernodes",sn);
|
||||
for(sn in content.addNodes)
|
||||
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>
|
||||
|
||||
</body>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user