Beautify the scripts
This commit is contained in:
parent
3d0c8883b7
commit
0a6fb69349
@ -13,7 +13,9 @@
|
|||||||
|
|
||||||
//Required for blockchain API operators
|
//Required for blockchain API operators
|
||||||
apiURL: {
|
apiURL: {
|
||||||
FLO: ['https://explorer.mediciland.com/', 'https://livenet.flocha.in/', 'https://flosight.duckdns.org/', 'http://livenet-explorer.floexperiments.com/'],
|
FLO: ['https://explorer.mediciland.com/', 'https://livenet.flocha.in/', 'https://flosight.duckdns.org/',
|
||||||
|
'http://livenet-explorer.floexperiments.com/'
|
||||||
|
],
|
||||||
FLO_TEST: ['https://testnet-flosight.duckdns.org/', 'https://testnet.flocha.in/']
|
FLO_TEST: ['https://testnet-flosight.duckdns.org/', 'https://testnet.flocha.in/']
|
||||||
},
|
},
|
||||||
adminID: "FKAEdnPfjXLHSYwrXQu377ugN4tXU7VGdf",
|
adminID: "FKAEdnPfjXLHSYwrXQu377ugN4tXU7VGdf",
|
||||||
@ -7091,7 +7093,8 @@ Bitcoin.Util = {
|
|||||||
|
|
||||||
deriveSharedKeyReceiver: function (senderPublicKeyString, receiverPrivateKey) {
|
deriveSharedKeyReceiver: function (senderPublicKeyString, receiverPrivateKey) {
|
||||||
try {
|
try {
|
||||||
return ellipticCurveEncryption.receiverSharedKeyDerivation(senderPublicKeyString.XValuePublicString,
|
return ellipticCurveEncryption.receiverSharedKeyDerivation(senderPublicKeyString
|
||||||
|
.XValuePublicString,
|
||||||
senderPublicKeyString.YValuePublicString, receiverPrivateKey);
|
senderPublicKeyString.YValuePublicString, receiverPrivateKey);
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -7128,7 +7131,8 @@ Bitcoin.Util = {
|
|||||||
if (alphaNumeric)
|
if (alphaNumeric)
|
||||||
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
||||||
else
|
else
|
||||||
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_+-./*?@#&$<>=[]{}():';
|
var characters =
|
||||||
|
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_+-./*?@#&$<>=[]{}():';
|
||||||
for (var i = 0; i < length; i++)
|
for (var i = 0; i < length; i++)
|
||||||
result += characters.charAt(Math.floor(Math.random() * characters.length));
|
result += characters.charAt(Math.floor(Math.random() * characters.length));
|
||||||
return result;
|
return result;
|
||||||
@ -7137,7 +7141,8 @@ Bitcoin.Util = {
|
|||||||
//Encrypt Data using public-key
|
//Encrypt Data using public-key
|
||||||
encryptData: function (data, receiverCompressedPublicKey) {
|
encryptData: function (data, receiverCompressedPublicKey) {
|
||||||
var senderECKeyData = this.util.getSenderPublicKeyString();
|
var senderECKeyData = this.util.getSenderPublicKeyString();
|
||||||
var senderDerivedKey = this.util.deriveSharedKeySender(receiverCompressedPublicKey, senderECKeyData.privateKey);
|
var senderDerivedKey = this.util.deriveSharedKeySender(receiverCompressedPublicKey, senderECKeyData
|
||||||
|
.privateKey);
|
||||||
let senderKey = senderDerivedKey.XValue + senderDerivedKey.YValue;
|
let senderKey = senderDerivedKey.XValue + senderDerivedKey.YValue;
|
||||||
let secret = Crypto.AES.encrypt(data, senderKey);
|
let secret = Crypto.AES.encrypt(data, senderKey);
|
||||||
return {
|
return {
|
||||||
@ -7156,7 +7161,8 @@ Bitcoin.Util = {
|
|||||||
"Failed to detremine your private key.");
|
"Failed to detremine your private key.");
|
||||||
receiverECKeyData.privateKey = privateKey.privateKeyDecimal;
|
receiverECKeyData.privateKey = privateKey.privateKeyDecimal;
|
||||||
|
|
||||||
var receiverDerivedKey = this.util.deriveReceiverSharedKey(data.senderPublicKeyString, receiverECKeyData
|
var receiverDerivedKey = this.util.deriveReceiverSharedKey(data.senderPublicKeyString,
|
||||||
|
receiverECKeyData
|
||||||
.privateKey);
|
.privateKey);
|
||||||
|
|
||||||
let receiverKey = receiverDerivedKey.XValue + receiverDerivedKey.YValue;
|
let receiverKey = receiverDerivedKey.XValue + receiverDerivedKey.YValue;
|
||||||
@ -7381,7 +7387,8 @@ Bitcoin.Util = {
|
|||||||
for (var i = utxos.length - 1;
|
for (var i = utxos.length - 1;
|
||||||
(i >= 0) && (utxoAmt < sendAmt + fee); i--) {
|
(i >= 0) && (utxoAmt < sendAmt + fee); i--) {
|
||||||
if (utxos[i].confirmations) {
|
if (utxos[i].confirmations) {
|
||||||
trx.addinput(utxos[i].txid, utxos[i].vout, utxos[i].scriptPubKey)
|
trx.addinput(utxos[i].txid, utxos[i].vout, utxos[i]
|
||||||
|
.scriptPubKey)
|
||||||
utxoAmt += utxos[i].amount;
|
utxoAmt += utxos[i].amount;
|
||||||
} else break;
|
} else break;
|
||||||
}
|
}
|
||||||
@ -7462,22 +7469,32 @@ Bitcoin.Util = {
|
|||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.promisedAPI(`api/addrs/${addr}/txs?from=0&to=1`).then(response => {
|
this.promisedAPI(`api/addrs/${addr}/txs?from=0&to=1`).then(response => {
|
||||||
var newItems = response.totalItems - options.ignoreOld;
|
var newItems = response.totalItems - options.ignoreOld;
|
||||||
this.promisedAPI(`api/addrs/${addr}/txs?from=0&to=${newItems*2}`).then(response => {
|
this.promisedAPI(`api/addrs/${addr}/txs?from=0&to=${newItems*2}`).then(
|
||||||
|
response => {
|
||||||
if (options.limit <= 0)
|
if (options.limit <= 0)
|
||||||
options.limit = response.items.length;
|
options.limit = response.items.length;
|
||||||
var filteredData = [];
|
var filteredData = [];
|
||||||
for (i = 0; i < (response.totalItems - options.ignoreOld) && filteredData.length < options.limit; i++){
|
for (i = 0; i < (response.totalItems - options.ignoreOld) &&
|
||||||
if(options.sentOnly && response.items[i].vin[0].addr !== addr)
|
filteredData.length < options.limit; i++) {
|
||||||
|
if (options.sentOnly && response.items[i].vin[0].addr !==
|
||||||
|
addr)
|
||||||
continue;
|
continue;
|
||||||
if(options.pattern && !response.items[i].floData.startsWith(options.pattern, 0) && !response.items[i].floData.startsWith(options.pattern, 2))
|
if (options.pattern && !response.items[i].floData
|
||||||
|
.startsWith(options.pattern, 0) && !response.items[i]
|
||||||
|
.floData.startsWith(options.pattern, 2))
|
||||||
continue;
|
continue;
|
||||||
if(options.contains && !response.items[i].floData.includes(options.contains))
|
if (options.contains && !response.items[i].floData.includes(
|
||||||
|
options.contains))
|
||||||
continue;
|
continue;
|
||||||
if(options.filter && !options.filter(response.items[i].floData))
|
if (options.filter && !options.filter(response.items[i]
|
||||||
|
.floData))
|
||||||
continue;
|
continue;
|
||||||
filteredData.push(response.items[i].floData);
|
filteredData.push(response.items[i].floData);
|
||||||
}
|
}
|
||||||
resolve({totalTxs:response.totalItems , data:filteredData});
|
resolve({
|
||||||
|
totalTxs: response.totalItems,
|
||||||
|
data: filteredData
|
||||||
|
});
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
reject(error);
|
reject(error);
|
||||||
});
|
});
|
||||||
@ -7508,7 +7525,8 @@ Bitcoin.Util = {
|
|||||||
const nodeIdNewInt8Array = new Uint8Array(nodeIdBytes);
|
const nodeIdNewInt8Array = new Uint8Array(nodeIdBytes);
|
||||||
return nodeIdNewInt8Array;
|
return nodeIdNewInt8Array;
|
||||||
},
|
},
|
||||||
launch: function (superNodeList = Object.keys(floGlobals.supernodes), master_floID = floGlobals.adminID) {
|
launch: function (superNodeList = Object.keys(floGlobals.supernodes), master_floID = floGlobals
|
||||||
|
.adminID) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
const SuKBucketId = this.floIdToKbucketId(master_floID);
|
const SuKBucketId = this.floIdToKbucketId(master_floID);
|
||||||
@ -8123,7 +8141,6 @@ Bitcoin.Util = {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
<script id="compactIDB">
|
<script id="compactIDB">
|
||||||
/* Compact IndexedDB operations */
|
/* Compact IndexedDB operations */
|
||||||
@ -8151,15 +8168,18 @@ Bitcoin.Util = {
|
|||||||
idb.onupgradeneeded = (event) => {
|
idb.onupgradeneeded = (event) => {
|
||||||
var db = event.target.result;
|
var db = event.target.result;
|
||||||
for (obs in objectStores) {
|
for (obs in objectStores) {
|
||||||
var objectStore = db.createObjectStore(obs, objectStores[obs].options || {});
|
var objectStore = db.createObjectStore(obs, objectStores[obs].options ||
|
||||||
if (objectStores[obs].indexes && typeof objectStores[obs].indexes === 'object')
|
{});
|
||||||
|
if (objectStores[obs].indexes && typeof objectStores[obs].indexes ===
|
||||||
|
'object')
|
||||||
for (i in objectStores[obs].indexes)
|
for (i in objectStores[obs].indexes)
|
||||||
objectStore.createIndex(i, i, objectStores[obs].indexes[i] || {});
|
objectStore.createIndex(i, i, objectStores[obs].indexes[i] || {});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
idb.onsuccess = (event) => {
|
idb.onsuccess = (event) => {
|
||||||
var db = event.target.result;
|
var db = event.target.result;
|
||||||
if (JSON.stringify(Object.values(db.objectStoreNames).sort()) === JSON.stringify(Object.keys(
|
if (JSON.stringify(Object.values(db.objectStoreNames).sort()) === JSON
|
||||||
|
.stringify(Object.keys(
|
||||||
objectStores).sort()))
|
objectStores).sort()))
|
||||||
resolve("Initiated IndexedDB");
|
resolve("Initiated IndexedDB");
|
||||||
else
|
else
|
||||||
@ -8192,7 +8212,8 @@ Bitcoin.Util = {
|
|||||||
let writeReq = (key ? obs.put(data, key) : obs.put(data));
|
let writeReq = (key ? obs.put(data, key) : obs.put(data));
|
||||||
writeReq.onsuccess = (evt) => resolve(`Write data Successful`);
|
writeReq.onsuccess = (evt) => resolve(`Write data Successful`);
|
||||||
writeReq.onerror = (evt) => reject(
|
writeReq.onerror = (evt) => reject(
|
||||||
`Write data unsuccessful [${evt.target.error.name}] ${evt.target.error.message}`);
|
`Write data unsuccessful [${evt.target.error.name}] ${evt.target.error.message}`
|
||||||
|
);
|
||||||
db.close();
|
db.close();
|
||||||
}).catch(error => reject(error));
|
}).catch(error => reject(error));
|
||||||
});
|
});
|
||||||
@ -8205,7 +8226,8 @@ Bitcoin.Util = {
|
|||||||
let addReq = (key ? obs.add(data, key) : obs.add(data));
|
let addReq = (key ? obs.add(data, key) : obs.add(data));
|
||||||
addReq.onsuccess = (evt) => resolve(`Add data successful`);
|
addReq.onsuccess = (evt) => resolve(`Add data successful`);
|
||||||
addReq.onerror = (evt) => reject(
|
addReq.onerror = (evt) => reject(
|
||||||
`Add data unsuccessful [${evt.target.error.name}] ${evt.target.error.message}`);
|
`Add data unsuccessful [${evt.target.error.name}] ${evt.target.error.message}`
|
||||||
|
);
|
||||||
db.close();
|
db.close();
|
||||||
}).catch(error => reject(error));
|
}).catch(error => reject(error));
|
||||||
});
|
});
|
||||||
@ -8218,7 +8240,8 @@ Bitcoin.Util = {
|
|||||||
let delReq = obs.delete(key);
|
let delReq = obs.delete(key);
|
||||||
delReq.onsuccess = (evt) => resolve(`Removed Data ${key}`);
|
delReq.onsuccess = (evt) => resolve(`Removed Data ${key}`);
|
||||||
delReq.onerror = (evt) => reject(
|
delReq.onerror = (evt) => reject(
|
||||||
`Remove data unsuccessful [${evt.target.error.name}] ${evt.target.error.message}`);
|
`Remove data unsuccessful [${evt.target.error.name}] ${evt.target.error.message}`
|
||||||
|
);
|
||||||
db.close();
|
db.close();
|
||||||
}).catch(error => reject(error));
|
}).catch(error => reject(error));
|
||||||
});
|
});
|
||||||
@ -8231,7 +8254,8 @@ Bitcoin.Util = {
|
|||||||
let getReq = obs.get(key);
|
let getReq = obs.get(key);
|
||||||
getReq.onsuccess = (evt) => resolve(evt.target.result);
|
getReq.onsuccess = (evt) => resolve(evt.target.result);
|
||||||
getReq.onerror = (evt) => reject(
|
getReq.onerror = (evt) => reject(
|
||||||
`Read data unsuccessful [${evt.target.error.name}] ${evt.target.error.message}`);
|
`Read data unsuccessful [${evt.target.error.name}] ${evt.target.error.message}`
|
||||||
|
);
|
||||||
db.close();
|
db.close();
|
||||||
}).catch(error => reject(error));
|
}).catch(error => reject(error));
|
||||||
});
|
});
|
||||||
@ -8252,7 +8276,8 @@ Bitcoin.Util = {
|
|||||||
resolve(tmpResult);
|
resolve(tmpResult);
|
||||||
}
|
}
|
||||||
curReq.onerror = (evt) => reject(
|
curReq.onerror = (evt) => reject(
|
||||||
`Read-All data unsuccessful [${evt.target.error.name}] ${evt.target.error.message}`);
|
`Read-All data unsuccessful [${evt.target.error.name}] ${evt.target.error.message}`
|
||||||
|
);
|
||||||
db.close();
|
db.close();
|
||||||
}).catch(error => reject(error));
|
}).catch(error => reject(error));
|
||||||
});
|
});
|
||||||
@ -8274,7 +8299,8 @@ Bitcoin.Util = {
|
|||||||
resolve(filteredResult);
|
resolve(filteredResult);
|
||||||
}
|
}
|
||||||
curReq.onerror = (evt) => reject(
|
curReq.onerror = (evt) => reject(
|
||||||
`Search unsuccessful [${evt.target.error.name}] ${evt.target.error.message}`);
|
`Search unsuccessful [${evt.target.error.name}] ${evt.target.error.message}`
|
||||||
|
);
|
||||||
db.close();
|
db.close();
|
||||||
}).catch(error => reject(error));
|
}).catch(error => reject(error));
|
||||||
});
|
});
|
||||||
@ -8298,7 +8324,8 @@ Bitcoin.Util = {
|
|||||||
if (message.reset) {
|
if (message.reset) {
|
||||||
floGlobals.appObjects[message.object] = message.reset
|
floGlobals.appObjects[message.object] = message.reset
|
||||||
floGlobals.vectorClock[message.object] = vc
|
floGlobals.vectorClock[message.object] = vc
|
||||||
compactIDB.writeData("appObjects", floGlobals.appObjects[message.object], message.object)
|
compactIDB.writeData("appObjects", floGlobals.appObjects[message.object], message
|
||||||
|
.object)
|
||||||
compactIDB.writeData("vectorClock", vc, message.object)
|
compactIDB.writeData("vectorClock", vc, message.object)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -8314,8 +8341,10 @@ Bitcoin.Util = {
|
|||||||
for (vc in dataSet) {
|
for (vc in dataSet) {
|
||||||
var message = dataSet[vc].message;
|
var message = dataSet[vc].message;
|
||||||
if (message.diff) {
|
if (message.diff) {
|
||||||
floGlobals.appObjects[message.object] = mergeDifference(floGlobals.appObjects[message.object], message.diff)
|
floGlobals.appObjects[message.object] = mergeDifference(floGlobals.appObjects[
|
||||||
compactIDB.writeData("appObjects",floGlobals.appObjects[message.object], message.object)
|
message.object], message.diff)
|
||||||
|
compactIDB.writeData("appObjects", floGlobals.appObjects[message.object], message
|
||||||
|
.object)
|
||||||
}
|
}
|
||||||
floGlobals.vectorClock[message.object] = vc
|
floGlobals.vectorClock[message.object] = vc
|
||||||
compactIDB.writeData("vectorClock", vc, message.object)
|
compactIDB.writeData("vectorClock", vc, message.object)
|
||||||
@ -8332,7 +8361,11 @@ Bitcoin.Util = {
|
|||||||
if (!Array.isArray(floGlobals.generalData[filterStr]))
|
if (!Array.isArray(floGlobals.generalData[filterStr]))
|
||||||
floGlobals.generalData[filterStr] = []
|
floGlobals.generalData[filterStr] = []
|
||||||
for (vc in dataSet) {
|
for (vc in dataSet) {
|
||||||
floGlobals.generalData[filterStr].push({sender: dataSet[vc].senderID, vectorClock: vc, message: dataSet[vc].message})
|
floGlobals.generalData[filterStr].push({
|
||||||
|
sender: dataSet[vc].senderID,
|
||||||
|
vectorClock: vc,
|
||||||
|
message: dataSet[vc].message
|
||||||
|
})
|
||||||
compactIDB.writeData("generalData", floGlobals.generalData[filterStr], filterStr)
|
compactIDB.writeData("generalData", floGlobals.generalData[filterStr], filterStr)
|
||||||
floGlobals.generalVC[filterStr] = vc
|
floGlobals.generalVC[filterStr] = vc
|
||||||
compactIDB.writeData("generalVC", vc, filterStr)
|
compactIDB.writeData("generalVC", vc, filterStr)
|
||||||
@ -8394,9 +8427,14 @@ Bitcoin.Util = {
|
|||||||
//request General Data
|
//request General Data
|
||||||
requestGeneralData: function (type, options = {}) {
|
requestGeneralData: function (type, options = {}) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
var filterStr = JSON.stringify({application: options.application || floGlobals.application, type: type, comment: options.comment})
|
var filterStr = JSON.stringify({
|
||||||
|
application: options.application || floGlobals.application,
|
||||||
|
type: type,
|
||||||
|
comment: options.comment
|
||||||
|
})
|
||||||
options.type = type
|
options.type = type
|
||||||
options.lowerVectorClock = options.lowerVectorClock || floGlobals.generalVC[filterStr] + 1
|
options.lowerVectorClock = options.lowerVectorClock || floGlobals.generalVC[filterStr] +
|
||||||
|
1
|
||||||
this.requestApplicationData(options).then(dataSet => {
|
this.requestApplicationData(options).then(dataSet => {
|
||||||
this.util.storeGeneralData(filterStr, dataSet)
|
this.util.storeGeneralData(filterStr, dataSet)
|
||||||
resolve('General Data Updated')
|
resolve('General Data Updated')
|
||||||
@ -8409,7 +8447,8 @@ Bitcoin.Util = {
|
|||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
var request = {
|
var request = {
|
||||||
receiverID: options.receiverID || floGlobals.adminID,
|
receiverID: options.receiverID || floGlobals.adminID,
|
||||||
senderIDs: (options.senderIDs === false) ? false: options.senderIDs || floGlobals.subAdmins,
|
senderIDs: (options.senderIDs === false) ? false : options.senderIDs ||
|
||||||
|
floGlobals.subAdmins,
|
||||||
application: options.application || floGlobals.application,
|
application: options.application || floGlobals.application,
|
||||||
comment: options.comment,
|
comment: options.comment,
|
||||||
type: `${objectName}@Reset`,
|
type: `${objectName}@Reset`,
|
||||||
@ -8421,9 +8460,11 @@ Bitcoin.Util = {
|
|||||||
request.type = `${objectName}@Update`
|
request.type = `${objectName}@Update`
|
||||||
request.lowerVectorClock = floGlobals.vectorClock[objectName] + 1
|
request.lowerVectorClock = floGlobals.vectorClock[objectName] + 1
|
||||||
request.mostRecent = false
|
request.mostRecent = false
|
||||||
floSupernode.requestData(JSON.stringify(request), request.receiverID).then(dataSet => {
|
floSupernode.requestData(JSON.stringify(request), request.receiverID).then(
|
||||||
|
dataSet => {
|
||||||
this.util.updateData(dataSet)
|
this.util.updateData(dataSet)
|
||||||
this.util.lastCommit[objectName] = JSON.stringify(floGlobals.appObjects[objectName])
|
this.util.lastCommit[objectName] = JSON.stringify(floGlobals
|
||||||
|
.appObjects[objectName])
|
||||||
resolve('Object Data Updated')
|
resolve('Object Data Updated')
|
||||||
}).catch(error => reject(error))
|
}).catch(error => reject(error))
|
||||||
}).catch(error => reject(error))
|
}).catch(error => reject(error))
|
||||||
@ -8440,7 +8481,8 @@ Bitcoin.Util = {
|
|||||||
reset: floGlobals.appObjects[objectName]
|
reset: floGlobals.appObjects[objectName]
|
||||||
}
|
}
|
||||||
this.sendApplicationData(message, `${objectName}@Reset`, options).then(result => {
|
this.sendApplicationData(message, `${objectName}@Reset`, options).then(result => {
|
||||||
this.util.lastCommit[objectName] = JSON.stringify(floGlobals.appObjects[objectName])
|
this.util.lastCommit[objectName] = JSON.stringify(floGlobals.appObjects[
|
||||||
|
objectName])
|
||||||
resolve(result)
|
resolve(result)
|
||||||
}).catch(error => reject(error))
|
}).catch(error => reject(error))
|
||||||
})
|
})
|
||||||
@ -8453,10 +8495,12 @@ Bitcoin.Util = {
|
|||||||
division: options.division || floGlobals.division,
|
division: options.division || floGlobals.division,
|
||||||
object: objectName,
|
object: objectName,
|
||||||
vectorClock: floGlobals.vectorClock[objectName],
|
vectorClock: floGlobals.vectorClock[objectName],
|
||||||
diff: findDifference(JSON.parse(this.util.lastCommit[objectName]), floGlobals.appObjects[objectName])
|
diff: findDifference(JSON.parse(this.util.lastCommit[objectName]), floGlobals
|
||||||
|
.appObjects[objectName])
|
||||||
}
|
}
|
||||||
this.sendApplicationData(message, `${objectName}@Update`, options).then(result => {
|
this.sendApplicationData(message, `${objectName}@Update`, options).then(result => {
|
||||||
this.util.lastCommit[objectName] = JSON.stringify(floGlobals.appObjects[objectName])
|
this.util.lastCommit[objectName] = JSON.stringify(floGlobals.appObjects[
|
||||||
|
objectName])
|
||||||
resolve(result)
|
resolve(result)
|
||||||
}).catch(error => reject(error))
|
}).catch(error => reject(error))
|
||||||
})
|
})
|
||||||
@ -8478,7 +8522,10 @@ Bitcoin.Util = {
|
|||||||
lastTx: {},
|
lastTx: {},
|
||||||
//supernode (cloud list)
|
//supernode (cloud list)
|
||||||
supernodes: {
|
supernodes: {
|
||||||
indexes:{ uri:null, pubKey:null }
|
indexes: {
|
||||||
|
uri: null,
|
||||||
|
pubKey: null
|
||||||
|
}
|
||||||
},
|
},
|
||||||
//login credentials
|
//login credentials
|
||||||
credentials: {},
|
credentials: {},
|
||||||
@ -8514,20 +8561,31 @@ Bitcoin.Util = {
|
|||||||
readSupernodeListFromAPI: function () {
|
readSupernodeListFromAPI: function () {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
compactIDB.readData("lastTx", floGlobals.SNStorageID).then(lastTx => {
|
compactIDB.readData("lastTx", floGlobals.SNStorageID).then(lastTx => {
|
||||||
floBlockchainAPI.readData(floGlobals.SNStorageID,{ignoreOld:lastTx,sentOnly:true,pattern:"SuperNodeStorage"}).then(result => {
|
floBlockchainAPI.readData(floGlobals.SNStorageID, {
|
||||||
|
ignoreOld: lastTx,
|
||||||
|
sentOnly: true,
|
||||||
|
pattern: "SuperNodeStorage"
|
||||||
|
}).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]).SuperNodeStorage;
|
var content = JSON.parse(result.data[i])
|
||||||
|
.SuperNodeStorage;
|
||||||
for (sn in content.removeNodes)
|
for (sn in content.removeNodes)
|
||||||
compactIDB.removeData("supernodes", sn);
|
compactIDB.removeData("supernodes", sn);
|
||||||
for (sn in content.addNodes)
|
for (sn in content.addNodes)
|
||||||
compactIDB.writeData("supernodes",content.addNodes[sn],sn);
|
compactIDB.writeData("supernodes", content
|
||||||
|
.addNodes[sn], sn);
|
||||||
}
|
}
|
||||||
compactIDB.writeData("lastTx",result.totalTxs,floGlobals.SNStorageID);
|
compactIDB.writeData("lastTx", result.totalTxs,
|
||||||
|
floGlobals.SNStorageID);
|
||||||
compactIDB.readAllData("supernodes").then(result => {
|
compactIDB.readAllData("supernodes").then(result => {
|
||||||
floGlobals.supernodes = result;
|
floGlobals.supernodes = result;
|
||||||
|
|
||||||
floSupernode.kBucket.launch(Object.keys(floGlobals.supernodes),floGlobals.SNStorageID)
|
floSupernode.kBucket.launch(Object.keys(
|
||||||
.then(result => resolve("Loaded Supernode list\n"+result))
|
floGlobals.supernodes),
|
||||||
|
floGlobals.SNStorageID)
|
||||||
|
.then(result => resolve(
|
||||||
|
"Loaded Supernode list\n" +
|
||||||
|
result))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}).catch(error => reject(error))
|
}).catch(error => reject(error))
|
||||||
@ -8537,17 +8595,27 @@ Bitcoin.Util = {
|
|||||||
readSubAdminListFromAPI: function () {
|
readSubAdminListFromAPI: function () {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
compactIDB.readData("lastTx", floGlobals.adminID).then(lastTx => {
|
compactIDB.readData("lastTx", floGlobals.adminID).then(lastTx => {
|
||||||
floBlockchainAPI.readData(floGlobals.adminID,{ignoreOld:lastTx,sentOnly:true,pattern:floGlobals.application}).then(result => {
|
floBlockchainAPI.readData(floGlobals.adminID, {
|
||||||
|
ignoreOld: lastTx,
|
||||||
|
sentOnly: true,
|
||||||
|
pattern: floGlobals.application
|
||||||
|
}).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.application];
|
var content = JSON.parse(result.data[i])[floGlobals
|
||||||
|
.application];
|
||||||
if (Array.isArray(content.removeSubAdmin))
|
if (Array.isArray(content.removeSubAdmin))
|
||||||
for(var j = 0; j < content.removeSubAdmin.length; j++)
|
for (var j = 0; j < content.removeSubAdmin
|
||||||
compactIDB.removeData("subAdmins",content.removeSubAdmin[j]);
|
.length; j++)
|
||||||
|
compactIDB.removeData("subAdmins", content
|
||||||
|
.removeSubAdmin[j]);
|
||||||
if (Array.isArray(content.addSubAdmin))
|
if (Array.isArray(content.addSubAdmin))
|
||||||
for(var k = 0; k < content.addSubAdmin.length; k++)
|
for (var k = 0; k < content.addSubAdmin
|
||||||
compactIDB.writeData("subAdmins",true,content.addSubAdmin[k]);
|
.length; k++)
|
||||||
|
compactIDB.writeData("subAdmins", true,
|
||||||
|
content.addSubAdmin[k]);
|
||||||
}
|
}
|
||||||
compactIDB.writeData("lastTx",result.totalTxs,floGlobals.adminID);
|
compactIDB.writeData("lastTx", result.totalTxs,
|
||||||
|
floGlobals.adminID);
|
||||||
compactIDB.readAllData("subAdmins").then(result => {
|
compactIDB.readAllData("subAdmins").then(result => {
|
||||||
floGlobals.subAdmins = Object.keys(result);
|
floGlobals.subAdmins = Object.keys(result);
|
||||||
resolve("Read subAdmins from blockchain");
|
resolve("Read subAdmins from blockchain");
|
||||||
@ -8617,7 +8685,8 @@ Bitcoin.Util = {
|
|||||||
try {
|
try {
|
||||||
if (!result)
|
if (!result)
|
||||||
return reject("Empty Private Key")
|
return reject("Empty Private Key")
|
||||||
var floID = floCrypto.getFloIDfromPubkeyHex(floCrypto.getPubKeyHex(result))
|
var floID = floCrypto.getFloIDfromPubkeyHex(
|
||||||
|
floCrypto.getPubKeyHex(result))
|
||||||
privKey = result
|
privKey = result
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
@ -8628,13 +8697,22 @@ Bitcoin.Util = {
|
|||||||
privKey = floCrypto.generateNewID().privKey
|
privKey = floCrypto.generateNewID().privKey
|
||||||
}).finally(_ => {
|
}).finally(_ => {
|
||||||
var threshold = floCrypto.randInt(10, 20)
|
var threshold = floCrypto.randInt(10, 20)
|
||||||
writeSharesToIDB(floCrypto.createShamirsSecretShares(privKey, threshold, threshold)).then(resultIndexes =>{
|
writeSharesToIDB(floCrypto.createShamirsSecretShares(
|
||||||
|
privKey, threshold, threshold)).then(
|
||||||
|
resultIndexes => {
|
||||||
//store index keys in localStorage
|
//store index keys in localStorage
|
||||||
localStorage.setItem(`${floGlobals.application}#privKey`, JSON.stringify(resultIndexes))
|
localStorage.setItem(
|
||||||
|
`${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.generateNewID().privKey
|
var randomPrivKey = floCrypto
|
||||||
var randomThreshold = floCrypto.randInt(10,20)
|
.generateNewID().privKey
|
||||||
writeSharesToIDB(floCrypto.createShamirsSecretShares(randomPrivKey, randomThreshold, randomThreshold))
|
var randomThreshold = floCrypto.randInt(10,
|
||||||
|
20)
|
||||||
|
writeSharesToIDB(floCrypto
|
||||||
|
.createShamirsSecretShares(
|
||||||
|
randomPrivKey, randomThreshold,
|
||||||
|
randomThreshold))
|
||||||
//resolve private Key
|
//resolve private Key
|
||||||
resolve(privKey)
|
resolve(privKey)
|
||||||
}).catch(error => reject(error))
|
}).catch(error => reject(error))
|
||||||
@ -8659,18 +8737,26 @@ 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
|
||||||
reactor.dispatchEvent("startUpSuccessLog",`${result}\nCompleted ${this.callStartUpFunction.completed}/${this.callStartUpFunction.total} Startup functions`)
|
reactor.dispatchEvent("startUpSuccessLog",
|
||||||
|
`${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
|
||||||
reactor.dispatchEvent("startUpErrorLog",`${error}\nFailed ${this.callStartUpFunction.failed}/${this.callStartUpFunction.total} Startup functions`)
|
reactor.dispatchEvent("startUpErrorLog",
|
||||||
|
`${error}\nFailed ${this.callStartUpFunction.failed}/${this.callStartUpFunction.total} Startup functions`
|
||||||
|
)
|
||||||
reject(false)
|
reject(false)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
getFilterString: function (type, options = {}) {
|
getFilterString: function (type, options = {}) {
|
||||||
var filterStr = JSON.stringify({application: options.application || floGlobals.application, type: type, comment: options.comment})
|
var filterStr = JSON.stringify({
|
||||||
|
application: options.application || floGlobals.application,
|
||||||
|
type: type,
|
||||||
|
comment: options.comment
|
||||||
|
})
|
||||||
return filterStr
|
return filterStr
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -8679,7 +8765,8 @@ 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.startUpFunctions).length
|
this.util.callStartUpFunction.total = Object.keys(this.util
|
||||||
|
.startUpFunctions).length
|
||||||
this.util.callStartUpFunction.completed = 0
|
this.util.callStartUpFunction.completed = 0
|
||||||
this.util.callStartUpFunction.failed = 0
|
this.util.callStartUpFunction.failed = 0
|
||||||
var promises = []
|
var promises = []
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user