floCloudAPI_v2.0.2d | floDapps_v2.0.1b
floCloudAPI_v2.0.2d - Fixed bug: syntax error in requestObjectData - Added closeRequest: closes the active live requests floDapps_v2.0.1b - minor improvements and alignment. - Fixed: deleteAppData deletes the lastTx data of the adminID.
This commit is contained in:
parent
1a57f74704
commit
b5532444fb
@ -38,7 +38,7 @@
|
|||||||
|
|
||||||
//floDapps.addStartUpFunction('Sample', Promised Function)
|
//floDapps.addStartUpFunction('Sample', Promised Function)
|
||||||
//floDapps.setAppObjectStores({sampleObs1:{}, sampleObs2:{options{autoIncrement:true, keyPath:'SampleKey'}, Indexes:{sampleIndex:{}}}})
|
//floDapps.setAppObjectStores({sampleObs1:{}, sampleObs2:{options{autoIncrement:true, keyPath:'SampleKey'}, Indexes:{sampleIndex:{}}}})
|
||||||
//floDapps.setCustomPrivKeyInput( () => { FUNCTION BODY *must return private key* } )
|
//floDapps.setCustomPrivKeyInput( () => { FUNCTION BODY *must resolve private key* } )
|
||||||
|
|
||||||
floDapps.launchStartUp().then(result => {
|
floDapps.launchStartUp().then(result => {
|
||||||
console.log(result)
|
console.log(result)
|
||||||
@ -7925,7 +7925,7 @@ Bitcoin.Util = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<script id="floCloudAPI" version="2.0.2c">
|
<script id="floCloudAPI" version="2.0.2d">
|
||||||
/* FLO Cloud operations to send/request application data*/
|
/* FLO Cloud operations to send/request application data*/
|
||||||
const floCloudAPI = {
|
const floCloudAPI = {
|
||||||
|
|
||||||
@ -8468,7 +8468,7 @@ Bitcoin.Util = {
|
|||||||
}
|
}
|
||||||
delete options.callback;
|
delete options.callback;
|
||||||
}
|
}
|
||||||
this.requestApplicationData(objectName, options).then(data).then(dataSet => {
|
this.requestApplicationData(objectName, options).then(dataSet => {
|
||||||
this.util.updateObject(dataSet)
|
this.util.updateObject(dataSet)
|
||||||
delete options.comment;
|
delete options.comment;
|
||||||
options.lowerVectorClock = floGlobals.lastVC[objectName] + 1
|
options.lowerVectorClock = floGlobals.lastVC[objectName] + 1
|
||||||
@ -8490,6 +8490,19 @@ Bitcoin.Util = {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
closeRequest: function(requestID) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
let conn = this.util.liveRequest[requestID]
|
||||||
|
if (!conn)
|
||||||
|
return reject('Request not found')
|
||||||
|
conn.onclose = evt => {
|
||||||
|
delete this.util.liveRequest[requestID]
|
||||||
|
resolve('Request connection closed')
|
||||||
|
}
|
||||||
|
conn.close()
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
//reset or initialize an object and send it to cloud
|
//reset or initialize an object and send it to cloud
|
||||||
resetObjectData: function(objectName, options = {}) {
|
resetObjectData: function(objectName, options = {}) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
@ -8700,7 +8713,7 @@ Bitcoin.Util = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<script id="floDapps" version="2.0.1a">
|
<script id="floDapps" version="2.0.1b">
|
||||||
/* General functions for FLO Dapps*/
|
/* General functions for FLO Dapps*/
|
||||||
const floDapps = {
|
const floDapps = {
|
||||||
|
|
||||||
@ -8775,32 +8788,25 @@ Bitcoin.Util = {
|
|||||||
|
|
||||||
readSupernodeListFromAPI: function() {
|
readSupernodeListFromAPI: function() {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
compactIDB.readData("lastTx", floGlobals.SNStorageID, "floDapps").then(
|
compactIDB.readData("lastTx", floGlobals.SNStorageID, "floDapps").then(lastTx => {
|
||||||
lastTx => {
|
|
||||||
floBlockchainAPI.readData(floGlobals.SNStorageID, {
|
floBlockchainAPI.readData(floGlobals.SNStorageID, {
|
||||||
ignoreOld: lastTx,
|
ignoreOld: lastTx,
|
||||||
sentOnly: true,
|
sentOnly: true,
|
||||||
pattern: "SuperNodeStorage"
|
pattern: "SuperNodeStorage"
|
||||||
}).then(result => {
|
}).then(result => {
|
||||||
for (var i = result.data.length - 1; i >= 0; i--) {
|
for (var i = result.data.length - 1; i >= 0; i--) {
|
||||||
var content = JSON.parse(result.data[i])
|
var content = JSON.parse(result.data[i]).SuperNodeStorage;
|
||||||
.SuperNodeStorage;
|
|
||||||
for (sn in content.removeNodes)
|
for (sn in content.removeNodes)
|
||||||
compactIDB.removeData("supernodes", sn,
|
compactIDB.removeData("supernodes", sn, "floDapps");
|
||||||
"floDapps");
|
|
||||||
for (sn in content.newNodes)
|
for (sn in content.newNodes)
|
||||||
compactIDB.writeData("supernodes", content
|
compactIDB.writeData("supernodes", content.newNodes[sn], sn, "floDapps");
|
||||||
.newNodes[sn], sn, "floDapps");
|
|
||||||
}
|
}
|
||||||
compactIDB.writeData("lastTx", result.totalTxs,
|
compactIDB.writeData("lastTx", result.totalTxs, floGlobals.SNStorageID, "floDapps");
|
||||||
floGlobals.SNStorageID, "floDapps");
|
compactIDB.readAllData("supernodes", "floDapps").then(result => {
|
||||||
compactIDB.readAllData("supernodes", "floDapps").then(
|
|
||||||
result => {
|
|
||||||
floGlobals.supernodes = result;
|
floGlobals.supernodes = result;
|
||||||
floCloudAPI.util.kBucket.launch()
|
floCloudAPI.util.kBucket.launch()
|
||||||
.then(result => resolve(
|
.then(result => resolve("Loaded Supernode list\n" + result))
|
||||||
"Loaded Supernode list\n" +
|
.catch(error => reject(error))
|
||||||
result))
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}).catch(error => reject(error))
|
}).catch(error => reject(error))
|
||||||
@ -8809,42 +8815,32 @@ Bitcoin.Util = {
|
|||||||
|
|
||||||
readAppConfigFromAPI: function() {
|
readAppConfigFromAPI: function() {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
compactIDB.readData("lastTx", floGlobals.adminID, "floDapps").then(lastTx => {
|
compactIDB.readData("lastTx", `${floGlobals.application}|${floGlobals.adminID}`, "floDapps").then(lastTx => {
|
||||||
floBlockchainAPI.readData(floGlobals.adminID, {
|
floBlockchainAPI.readData(floGlobals.adminID, {
|
||||||
ignoreOld: lastTx,
|
ignoreOld: lastTx,
|
||||||
sentOnly: true,
|
sentOnly: true,
|
||||||
pattern: floGlobals.application
|
pattern: floGlobals.application
|
||||||
}).then(result => {
|
}).then(result => {
|
||||||
for (var i = result.data.length - 1; i >= 0; i--) {
|
for (var i = result.data.length - 1; i >= 0; i--) {
|
||||||
var content = JSON.parse(result.data[i])[floGlobals
|
var content = JSON.parse(result.data[i])[floGlobals.application];
|
||||||
.application];
|
|
||||||
if (!content || typeof content !== "object")
|
if (!content || typeof content !== "object")
|
||||||
continue;
|
continue;
|
||||||
if (Array.isArray(content.removeSubAdmin))
|
if (Array.isArray(content.removeSubAdmin))
|
||||||
for (var j = 0; j < content.removeSubAdmin
|
for (var j = 0; j < content.removeSubAdmin.length; j++)
|
||||||
.length; j++)
|
compactIDB.removeData("subAdmins", content.removeSubAdmin[j]);
|
||||||
compactIDB.removeData("subAdmins", content
|
|
||||||
.removeSubAdmin[j]);
|
|
||||||
if (Array.isArray(content.addSubAdmin))
|
if (Array.isArray(content.addSubAdmin))
|
||||||
for (var k = 0; k < content.addSubAdmin
|
for (var k = 0; k < content.addSubAdmin.length; k++)
|
||||||
.length; k++)
|
compactIDB.writeData("subAdmins", true, content.addSubAdmin[k]);
|
||||||
compactIDB.writeData("subAdmins", true,
|
|
||||||
content.addSubAdmin[k]);
|
|
||||||
if (content.settings)
|
if (content.settings)
|
||||||
for (let l in content.settings)
|
for (let l in content.settings)
|
||||||
compactIDB.writeData("settings", content
|
compactIDB.writeData("settings", content.settings[l], l)
|
||||||
.settings[l], l)
|
|
||||||
}
|
}
|
||||||
compactIDB.writeData("lastTx", result.totalTxs,
|
compactIDB.writeData("lastTx", result.totalTxs, `${floGlobals.application}|${floGlobals.adminID}`, "floDapps");
|
||||||
floGlobals.adminID, "floDapps");
|
|
||||||
compactIDB.readAllData("subAdmins").then(result => {
|
compactIDB.readAllData("subAdmins").then(result => {
|
||||||
floGlobals.subAdmins = Object.keys(result);
|
floGlobals.subAdmins = Object.keys(result);
|
||||||
compactIDB.readAllData("settings").then(
|
compactIDB.readAllData("settings").then(result => {
|
||||||
result => {
|
|
||||||
floGlobals.settings = result;
|
floGlobals.settings = result;
|
||||||
resolve(
|
resolve("Read app configuration from blockchain");
|
||||||
"Read app configuration from blockchain"
|
|
||||||
);
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -8897,7 +8893,7 @@ Bitcoin.Util = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const writeSharesToIDB = function(shares, i = 0, resultIndexes = []) {
|
const writeSharesToIDB = function(shares, i = 0, resultIndexes = []) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise(resolve => {
|
||||||
if (i >= shares.length)
|
if (i >= shares.length)
|
||||||
return resolve(resultIndexes)
|
return resolve(resultIndexes)
|
||||||
var n = floCrypto.randInt(0, 100000)
|
var n = floCrypto.randInt(0, 100000)
|
||||||
@ -8935,25 +8931,18 @@ Bitcoin.Util = {
|
|||||||
if (!privKey)
|
if (!privKey)
|
||||||
return;
|
return;
|
||||||
var threshold = floCrypto.randInt(10, 20)
|
var threshold = floCrypto.randInt(10, 20)
|
||||||
writeSharesToIDB(floCrypto.createShamirsSecretShares(
|
var shares = floCrypto.createShamirsSecretShares(privKey, threshold, threshold)
|
||||||
privKey, threshold, threshold)).then(
|
writeSharesToIDB(shares).then(resultIndexes => {
|
||||||
resultIndexes => {
|
|
||||||
//store index keys in localStorage
|
//store index keys in localStorage
|
||||||
localStorage.setItem(
|
localStorage.setItem(`${floGlobals.application}#privKey`, JSON.stringify(resultIndexes))
|
||||||
`${floGlobals.application}#privKey`,
|
|
||||||
JSON.stringify(resultIndexes))
|
|
||||||
//also add a dummy privatekey to the IDB
|
//also add a dummy privatekey to the IDB
|
||||||
var randomPrivKey = floCrypto
|
var randomPrivKey = floCrypto.generateNewID().privKey
|
||||||
.generateNewID().privKey
|
var randomThreshold = floCrypto.randInt(10, 20)
|
||||||
var randomThreshold = floCrypto.randInt(10,
|
var randomShares = floCrypto.createShamirsSecretShares(randomPrivKey, randomThreshold, randomThreshold)
|
||||||
20)
|
writeSharesToIDB(randomShares)
|
||||||
writeSharesToIDB(floCrypto
|
|
||||||
.createShamirsSecretShares(
|
|
||||||
randomPrivKey, randomThreshold,
|
|
||||||
randomThreshold))
|
|
||||||
//resolve private Key
|
//resolve private Key
|
||||||
resolve(privKey)
|
resolve(privKey)
|
||||||
}).catch(error => reject(error))
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -8971,8 +8960,7 @@ Bitcoin.Util = {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
reject("Access Denied: Incorrect PIN/Password")
|
reject("Access Denied: Incorrect PIN/Password")
|
||||||
}
|
}
|
||||||
}).catch(error => reject(
|
}).catch(error => reject("Access Denied: PIN/Password required"))
|
||||||
"Access Denied: PIN/Password required"))
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -9005,15 +8993,11 @@ Bitcoin.Util = {
|
|||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.startUpFunctions[fname]().then(result => {
|
this.startUpFunctions[fname]().then(result => {
|
||||||
this.callStartUpFunction.completed += 1
|
this.callStartUpFunction.completed += 1
|
||||||
this.startUpLog(true,
|
this.startUpLog(true, `${result}\nCompleted ${this.callStartUpFunction.completed}/${this.callStartUpFunction.total} Startup functions`)
|
||||||
`${result}\nCompleted ${this.callStartUpFunction.completed}/${this.callStartUpFunction.total} Startup functions`
|
|
||||||
)
|
|
||||||
resolve(true)
|
resolve(true)
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
this.callStartUpFunction.failed += 1
|
this.callStartUpFunction.failed += 1
|
||||||
this.startUpLog(false,
|
this.startUpLog(false, `${error}\nFailed ${this.callStartUpFunction.failed}/${this.callStartUpFunction.total} Startup functions`)
|
||||||
`${error}\nFailed ${this.callStartUpFunction.failed}/${this.callStartUpFunction.total} Startup functions`
|
|
||||||
)
|
|
||||||
reject(false)
|
reject(false)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -9024,8 +9008,7 @@ Bitcoin.Util = {
|
|||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.util.initIndexedDB().then(log => {
|
this.util.initIndexedDB().then(log => {
|
||||||
console.log(log)
|
console.log(log)
|
||||||
this.util.callStartUpFunction.total = Object.keys(this.util
|
this.util.callStartUpFunction.total = Object.keys(this.util.startUpFunctions).length
|
||||||
.startUpFunctions).length
|
|
||||||
this.util.callStartUpFunction.completed = 0
|
this.util.callStartUpFunction.completed = 0
|
||||||
this.util.callStartUpFunction.failed = 0
|
this.util.callStartUpFunction.failed = 0
|
||||||
var p0 = []
|
var p0 = []
|
||||||
@ -9165,8 +9148,7 @@ Bitcoin.Util = {
|
|||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (!Array.isArray(addList) || !addList.length) addList = undefined;
|
if (!Array.isArray(addList) || !addList.length) addList = undefined;
|
||||||
if (!Array.isArray(rmList) || !rmList.length) rmList = undefined;
|
if (!Array.isArray(rmList) || !rmList.length) rmList = undefined;
|
||||||
if (!settings || typeof settings !== "object" || !Object.keys(settings).length)
|
if (!settings || typeof settings !== "object" || !Object.keys(settings).length) settings = undefined;
|
||||||
settings = undefined;
|
|
||||||
if (!addList && !rmList && !settings)
|
if (!addList && !rmList && !settings)
|
||||||
return reject("No configuration change")
|
return reject("No configuration change")
|
||||||
var floData = {
|
var floData = {
|
||||||
@ -9213,8 +9195,10 @@ Bitcoin.Util = {
|
|||||||
compactIDB.deleteDB(floGlobals.application).then(result => {
|
compactIDB.deleteDB(floGlobals.application).then(result => {
|
||||||
localStorage.removeItem(`${floGlobals.application}#privKey`)
|
localStorage.removeItem(`${floGlobals.application}#privKey`)
|
||||||
myPrivKey = myPubKey = myFloID = undefined;
|
myPrivKey = myPubKey = myFloID = undefined;
|
||||||
resolve("App database(local) deleted")
|
compactIDB.removeData('lastTx', `${floGlobals.application}|${floGlobals.adminID}`, 'floDapps')
|
||||||
})
|
.then(result => resolve("App database(local) deleted"))
|
||||||
|
.catch(error => reject(error))
|
||||||
|
}).catch(error => reject(error))
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -9308,9 +9292,8 @@ Bitcoin.Util = {
|
|||||||
let vc = Object.keys(response).sort().pop()
|
let vc = Object.keys(response).sort().pop()
|
||||||
let sync = JSON.parse(Crypto.AES.decrypt(response[vc].message, myPrivKey))
|
let sync = JSON.parse(Crypto.AES.decrypt(response[vc].message, myPrivKey))
|
||||||
let promises = []
|
let promises = []
|
||||||
let store = (key, val, obs) =>
|
let store = (key, val, obs) => promises.push(compactIDB.writeData(obs, val, key, `floDapps#${floID}`));
|
||||||
promises.push(compactIDB.writeData(obs, val, key, `floDapps#${floID}`))[
|
["contacts", "pubKeys", "messages"].forEach(c => {
|
||||||
"contacts", "pubKeys", "messages"].forEach(c => {
|
|
||||||
for (let i in sync[c]) {
|
for (let i in sync[c]) {
|
||||||
store(i, sync[c][i], c)
|
store(i, sync[c][i], c)
|
||||||
floGlobals[c][i] = sync[c][i]
|
floGlobals[c][i] = sync[c][i]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user