Updating ethoFS Login System

This commit is contained in:
Dev-JamesR
2019-10-14 20:41:27 -07:00
parent 85592070a0
commit 6887481b2a
2 changed files with 1139 additions and 1082 deletions

View File

@@ -50,6 +50,7 @@ var GlobalControllerABI = JSON.parse('[ { "constant": true, "inputs": [], "name"
const $miningMessage = document.querySelector('.mining-message')
/*START OF MISC GLOBAL VARIABLES*/
var web3;
var privateKeyLogin = false;
var GlobalPrivateKey;
var minimumContractCost = 10000000000000000;
@@ -74,9 +75,9 @@ var GlobalHostingContractDetailArray = new Array();
var GlobalExtensionDuration;
/*END OF MISC GLOBAL VARIABLES*/
var elem = document.querySelector('.modal');
var instance = M.Modal.init(elem);
instance.open();
//var elem = document.querySelector('.modal');
//var instance = M.Modal.init(elem);
//instance.open();
function isWindows() {
return navigator.platform.indexOf('Win') > -1
@@ -94,25 +95,47 @@ fetch('https://api.coinmarketcap.com/v2/ticker/3452/').then(response => {
document.getElementById("ethoprice").textContent = round(ethoPriceUSD, 4);
}).catch(err => {});
if (typeof web3 == 'undefined') {
var web3 = new Web3()
function beforeLoginState() {
var statsRow = document.getElementById("stats-row");
statsRow.style.display = "none";
var uploadButton = document.getElementById("main-upload-button");
uploadButton.style.display = "none";
}
function afterLoginState() {
var statsRow = document.getElementById("stats-row");
statsRow.style.display = "block";
var uploadButton = document.getElementById("main-upload-button");
uploadButton.style.display = "block";
var loginButton = document.getElementById("main-login-button");
loginButton.style.display = "none";
}
function checkLogin() {
if (web3 == null) {
beforeLoginState();
web3 = new Web3()
web3.setProvider(new Web3.providers.WebsocketProvider("ws://localhost:8546"));
$('#ethofsLoginModal').modal({dismissible: true});
$('#ethofsLoginModal').modal('open');
} else {
ethofsLogin("");
//$('#ethofsLoginModal').modal({dismissible: true});
//$('#ethofsLoginModal').modal('show');
} else {
ethofsLogin(GlobalPrivateKey);
}
}
function ethofsLogin(privateKey) {
afterLoginState();
$('#ethofsLoginModal').modal('close');
$('#ethofsRegistrationModal').modal({dismissible: true});
$('#ethofsRegistrationModal').modal({
dismissible: true
});
$('#ethofsRegistrationModal').modal('close');
//CREATE ETHER-1 CHAIN CONNECTION AND LOOK FOR EXISTING USER ACCOUNT
if (privateKey != "") {
GlobalPrivateKey = privateKey;
privateKeyLogin = true;
web3.eth.net.isListening()
.then(function() {
.then(function () {
console.log('ethoFS is connected')
let account = web3.eth.accounts.privateKeyToAccount('0x' + privateKey);
console.log(account);
@@ -123,7 +146,7 @@ function ethofsLogin(privateKey) {
} else {
privateKeyLogin = false;
web3 = new Web3(web3.currentProvider);
web3.eth.getAccounts(function(err, accounts) {
web3.eth.getAccounts(function (err, accounts) {
if (err != null) {
console.error("An error occurred: " + err);
outputNoAddressContractTable();
@@ -147,11 +170,11 @@ function startEthofs() {
console.log("Starting ethoFS");
GlobalUserAddress = web3.eth.defaultAccount;
var ethoFSAccounts = new web3.eth.Contract(GlobalControllerABI, GlobalControllerContractAddress);
ethoFSAccounts.methods.CheckAccountExistence(GlobalUserAddress).call(function(error, result) {
ethoFSAccounts.methods.CheckAccountExistence(GlobalUserAddress).call(function (error, result) {
if (!error) {
if (result) {
document.getElementById("accountaddress").textContent = web3.eth.defaultAccount;
ethoFSAccounts.methods.GetUserAccountName(GlobalUserAddress).call(function(error, result) {
ethoFSAccounts.methods.GetUserAccountName(GlobalUserAddress).call(function (error, result) {
if (!error) {
if (result) {
getBlockHeight(web3);
@@ -192,13 +215,15 @@ function AddNewUser(userName) {
};
var privateKey = '0x' + GlobalPrivateKey;
web3.eth.accounts.signTransaction(tx, privateKey)
.then(function(signedTransactionData) {
web3.eth.sendSignedTransaction(signedTransactionData.rawTransaction, function(error, result) {
.then(function (signedTransactionData) {
web3.eth.sendSignedTransaction(signedTransactionData.rawTransaction, function (error, result) {
if (!error) {
if (result) {
$('#minedBlockTrackerModal').modal({dismissible: true});
$('#minedBlockTrackerModal').modal({
dismissible: true
});
$('#minedBlockTrackerModal').modal('open');
waitForReceipt(result, function(receipt) {
waitForReceipt(result, function (receipt) {
console.log("Transaction Has Been Mined: " + receipt);
$('#minedBlockTrackerModal').modal('close');
ethofsLogin(GlobalPrivateKey);
@@ -212,12 +237,12 @@ function AddNewUser(userName) {
});
});
} else {
controller.methods.AddNewUserPublic(userName).send(function(error, result) {
controller.methods.AddNewUserPublic(userName).send(function (error, result) {
if (!error) {
if (result) {
document.getElementById("wait").innerHTML = 'Waiting For Add User Confirmation.';
$('#minedBlockTrackerModal').modal('open');
waitForReceipt(result, function(receipt) {
waitForReceipt(result, function (receipt) {
console.log("Transaction Has Been Mined: " + receipt);
$('#minedBlockTrackerModal').modal('close');
ethofsLogin("");
@@ -236,7 +261,7 @@ function AddNewUser(userName) {
/*************************************************************************************************************/
function getBlockHeight(web3) {
console.log("Starting Block Height Detection..");
web3.eth.getBlockNumber(function(err, data) {
web3.eth.getBlockNumber(function (err, data) {
document.getElementById("blocknumber").textContent = data;
console.log("ETHO Block Number: " + data);
});
@@ -244,7 +269,7 @@ function getBlockHeight(web3) {
/*************************************************************************************************************/
function getBalance(web3) {
console.log("Starting Balance Detection..");
web3.eth.getBalance(web3.eth.defaultAccount, function(err, data) {
web3.eth.getBalance(web3.eth.defaultAccount, function (err, data) {
var balance = "ETHO Balance: " + Number(web3.utils.fromWei(data, "ether")).toFixed(2);
document.getElementById("ethobalance").textContent = balance;
console.log("ETHO Balance: " + data);
@@ -262,10 +287,10 @@ function calculateCost(contractSize, contractDuration, hostingCost) {
/*************************************************************************************************************/
//CHECK FOR TX - BLOCK TO BE MINED
function waitForReceipt(hash, cb) {
web3.eth.getTransactionReceipt(hash, function(err, receipt) {
web3.eth.getTransactionReceipt(hash, function (err, receipt) {
document.getElementById("mining-status-message").textContent = "In Progress";
$miningMessage.innerText = "Waiting For Transaction Confirmation";
web3.eth.getBlock('latest', function(e, res) {
web3.eth.getBlock('latest', function (e, res) {
if (!e) {
document.getElementById("block-height").textContent = res.number;
}
@@ -281,7 +306,7 @@ function waitForReceipt(hash, cb) {
cb(receipt);
}
} else {
setTimeout(function() {
setTimeout(function () {
waitForReceipt(hash, cb);
}, 10000);
}
@@ -301,14 +326,16 @@ function RemoveContract(hostingAddress, contentHash) {
var privateKey = '0x' + GlobalPrivateKey;
console.log("Private Key: " + privateKey);
web3.eth.accounts.signTransaction(tx, privateKey)
.then(function(signedTransactionData) {
.then(function (signedTransactionData) {
console.log("Signed TX Data: " + signedTransactionData.rawTransaction);
web3.eth.sendSignedTransaction(signedTransactionData.rawTransaction, function(error, result) {
web3.eth.sendSignedTransaction(signedTransactionData.rawTransaction, function (error, result) {
if (!error) {
if (result) {
$('#minedBlockTrackerModal').modal({dismissible: true});
$('#minedBlockTrackerModal').modal({
dismissible: true
});
$('#minedBlockTrackerModal').modal('open');
waitForReceipt(result, function(receipt) {
waitForReceipt(result, function (receipt) {
console.log("Transaction Has Been Mined: " + receipt);
$('#minedBlockTrackerModal').modal('close');
updateContractTable();
@@ -326,12 +353,14 @@ function RemoveContract(hostingAddress, contentHash) {
to: GlobalControllerContractAddress,
from: GlobalUserAddress,
};
pinRemoving.methods.RemoveHostingContract(hostingAddress, contentHash).send(tx, function(error, result) {
pinRemoving.methods.RemoveHostingContract(hostingAddress, contentHash).send(tx, function (error, result) {
if (!error) {
if (result) {
$('#minedBlockTrackerModal').modal({dismissible: true});
$('#minedBlockTrackerModal').modal({
dismissible: true
});
$('#minedBlockTrackerModal').modal('open');
waitForReceipt(result, function(receipt) {
waitForReceipt(result, function (receipt) {
console.log("Transaction Has Been Mined: " + receipt);
$('#minedBlockTrackerModal').modal('close');
updateContractTable();
@@ -353,14 +382,14 @@ function updateContractTable() {
var hostingContracts = "";
var TotalContractCount = 0;
var blockHeight = 0;
web3.eth.getBlockNumber(function(error, result) {
web3.eth.getBlockNumber(function (error, result) {
if (!error) {
blockHeight = result;
} else
console.error(error);
});
var ethoFSAccounts = new web3.eth.Contract(GlobalControllerABI, GlobalControllerContractAddress);
ethoFSAccounts.methods.GetUserAccountTotalContractCount(web3.eth.defaultAccount).call(function(error, result) {
ethoFSAccounts.methods.GetUserAccountTotalContractCount(web3.eth.defaultAccount).call(function (error, result) {
TotalContractCount = result;
GlobalTotalContractCount = result;
const getContractData = async (ethoFSAccounts, account, TotalContractCount) => {
@@ -477,7 +506,9 @@ function round(value, decimals) {
}
/*************************************************************************************************************/
function finishUploadModal() {
$('#uploadTrackerModal').modal({dismissible: true});
$('#uploadTrackerModal').modal({
dismissible: true
});
$('#uploadTrackerModal').modal('close');
stopApplication();
resetUploadSystem();
@@ -497,7 +528,9 @@ function resetUploadModal() {
//CHECK FOR PROPAGATED & AVAILABLE DATA ON NETWORK - FINAL VERIFICATION FOR UPLOADED CONTENT
function checkForUploadedContentAvailability(HostingContractName) {
document.getElementById("upload-check-button").style.visibility = "hidden";
$('#uploadTrackerModal').modal({dismissible: true});
$('#uploadTrackerModal').modal({
dismissible: true
});
$('#uploadTrackerModal').modal('open');
document.getElementById("upload-hash").innerHTML = HostingContractName;
return false;
@@ -608,7 +641,9 @@ function showHostingContractDetails(counter) {
resetContractExtensionChange();
GlobalHostingContractDetailArray = GlobalHostingContractArray[counter];
$('#contractDetailModal').modal({dismissible: true});
$('#contractDetailModal').modal({
dismissible: true
});
$('#contractDetailModal').modal('open');
document.getElementById("contract-detail-name").innerHTML = GlobalHostingContractDetailArray['name'];
var hashOutputString = "";
@@ -688,16 +723,20 @@ function contractExtensionConfirmation() {
var privateKey = '0x' + GlobalPrivateKey;
console.log("Private Key: " + privateKey);
web3.eth.accounts.signTransaction(tx, privateKey)
.then(function(signedTransactionData) {
.then(function (signedTransactionData) {
console.log("Signed TX Data: " + signedTransactionData.rawTransaction);
web3.eth.sendSignedTransaction(signedTransactionData.rawTransaction, function(error, result) {
web3.eth.sendSignedTransaction(signedTransactionData.rawTransaction, function (error, result) {
if (!error) {
if (result) {
$('#contractDetailModal').modal({dismissible: true});
$('#contractDetailModal').modal({
dismissible: true
});
$('#contractDetailModal').modal('close');
$('#minedBlockTrackerModal').modal({dismissible: true});
$('#minedBlockTrackerModal').modal({
dismissible: true
});
$('#minedBlockTrackerModal').modal('open');
waitForReceipt(result, function(receipt) {
waitForReceipt(result, function (receipt) {
console.log("Transaction Has Been Mined: " + receipt);
$('#minedBlockTrackerModal').modal('close');
updateContractTable();
@@ -712,12 +751,12 @@ function contractExtensionConfirmation() {
});
} else {
ethoFSController.methods.ExtendContract(GlobalHostingContractDetailArray['address'], extensionDuration).send(transactionObject, function(error, result) {
ethoFSController.methods.ExtendContract(GlobalHostingContractDetailArray['address'], extensionDuration).send(transactionObject, function (error, result) {
if (!error) {
if (result) {
$('#contractDetailModal').modal('close');
$('#minedBlockTrackerModal').modal('open');
waitForReceipt(result, function(receipt) {
waitForReceipt(result, function (receipt) {
console.log("Transaction Has Been Mined: " + receipt);
$('#minedBlockTrackerModal').modal('close');
updateContractTable();
@@ -752,7 +791,7 @@ function UpdateHealthCheckInfo(healthMessage) {
var availableStorageTotal = 0;
var activeHistory = 0;
var nodeCounter = 0;
splitMessage.forEach(function(nodeMessage, index) {
splitMessage.forEach(function (nodeMessage, index) {
var nodeSplitMessage = nodeMessage.split(":");
activeHistory = Number(nodeSplitMessage[5]);
if (activeHistory >= 5) {
@@ -787,7 +826,7 @@ function UpdateHealthCheckInfo(healthMessage) {
function calculateStorageAverages(usedStorageArray, availableStorageArray, nodeCountArray) {
var sumAvailableStorage = 0;
availableStorageArray.forEach(function(value, index) {
availableStorageArray.forEach(function (value, index) {
sumAvailableStorage += value;
if (index == (availableStorageArray.length - 1)) {
averageAvailableStorageTotal = (sumAvailableStorage / availableStorageArray.length);
@@ -795,7 +834,7 @@ function UpdateHealthCheckInfo(healthMessage) {
}
});
var sumNodeCount = 0;
nodeCountArray.forEach(function(value, index) {
nodeCountArray.forEach(function (value, index) {
sumNodeCount += value;
if (index == (nodeCountArray.length - 1)) {
var averageNodeCount = (sumNodeCount / nodeCountArray.length) + 19;
@@ -886,13 +925,15 @@ const onDragLeave = () => $dragContainer.classList.remove('dragging')
function startUploadProcess() {
console.log("Starting Upload Process..");
$('#preparingUploadModal').modal({dismissible: true});
$('#preparingUploadModal').modal({
dismissible: true
});
$('#preparingUploadModal').modal('open');
var streamFinishCount = 0;
for (var i = 0; i < MainFileArray.length; i++) {
const streamFiles = (files) => {
const stream = node.addReadableStream()
stream.on('data', function(data) {
stream.on('data', function (data) {
//console.log("Data...");
//console.log(data);
GlobalHashArray.push(`${data.hash}`);
@@ -935,8 +976,8 @@ function startUploadProcess() {
console.log("Sending Immediate Pin Request: " + MainHashArray[i]);
publishImmediatePin(MainHashArray[i]);
}
setTimeout(function() {
hashVerificationArray.forEach(function(hash) {
setTimeout(function () {
hashVerificationArray.forEach(function (hash) {
verifyDataUpload(hash);
});
}, 5000);
@@ -966,7 +1007,7 @@ function startUploadProcess() {
} else {
var confirmationPercentage = Math.ceil((hashConfirmationCount / hashVerificationArray.length) * 100);
if (confirmationPercentage < 99) {
setTimeout(function() {
setTimeout(function () {
verifyDataUpload(hash)
}, 2000);
} else {
@@ -978,7 +1019,7 @@ function startUploadProcess() {
console.log("Data Confirmation Error: " + error.status);
var confirmationPercentage = Math.ceil((hashConfirmationCount / hashVerificationArray.length) * 100);
if (confirmationPercentage < 99) {
setTimeout(function() {
setTimeout(function () {
verifyDataUpload(hash)
}, 2000);
} else {
@@ -1034,21 +1075,29 @@ function startUploadProcess() {
var privateKey = '0x' + GlobalPrivateKey;
console.log("Private Key: " + privateKey);
web3.eth.accounts.signTransaction(tx, privateKey)
.then(function(signedTransactionData) {
.then(function (signedTransactionData) {
console.log("Signed TX Data: " + signedTransactionData.rawTransaction);
web3.eth.sendSignedTransaction(signedTransactionData.rawTransaction, function(error, result) {
web3.eth.sendSignedTransaction(signedTransactionData.rawTransaction, function (error, result) {
if (!error) {
if (result) {
console.log("Result: " + result);
$('#minedBlockTrackerModal').modal({dismissible: true});
$('#minedBlockTrackerModal').modal({
dismissible: true
});
$('#minedBlockTrackerModal').modal('open');
$('#preparingUploadModal').modal({dismissible: true});
$('#preparingUploadModal').modal({
dismissible: true
});
$('#preparingUploadModal').modal('close');
waitForReceipt(result, function(receipt) {
waitForReceipt(result, function (receipt) {
console.log("Transaction Has Been Mined: " + receipt);
$('#minedBlockTrackerModal').modal({dismissible: true});
$('#minedBlockTrackerModal').modal({
dismissible: true
});
$('#minedBlockTrackerModal').modal('close');
$('#nodeModal').modal({dismissible: true});
$('#nodeModal').modal({
dismissible: true
});
$('#nodeModal').modal('close');
var filesForStream = MainFileArray;
streamFilesExternally(filesForStream, MainHashArray);
@@ -1063,12 +1112,12 @@ function startUploadProcess() {
});
});
} else {
pinAdding.methods.AddNewContract(GlobalMainContentHash, HostingContractName, HostingContractDuration, pinSize, pinSize, contentHashString, contentPathString).send(transactionObject, function(error, result) {
pinAdding.methods.AddNewContract(GlobalMainContentHash, HostingContractName, HostingContractDuration, pinSize, pinSize, contentHashString, contentPathString).send(transactionObject, function (error, result) {
if (!error) {
if (result) {
$('#minedBlockTrackerModal').modal('open');
$('#preparingUploadModal').modal('close');
waitForReceipt(result, function(receipt) {
waitForReceipt(result, function (receipt) {
console.log("Transaction Has Been Mined: " + receipt);
$('#minedBlockTrackerModal').modal('close');
$('#nodeModal').modal('close');
@@ -1135,7 +1184,7 @@ function onFileUpload(event) {
function readDirectoryContents(directory) {
console.log("Directory Path: " + directory);
fs.readdir(directory, function(err, filesUploaded) {
fs.readdir(directory, function (err, filesUploaded) {
if (!err) {
for (let i = 0; filesUploaded.length > i; i++) {
handleItem(filesUploaded[i], directory);
@@ -1148,7 +1197,7 @@ function onFileUpload(event) {
function handleItem(filename, relativePath) {
var filepath = relativePath.concat(pathSymbol, filename);
fs.stat(filepath, function(err, stats) {
fs.stat(filepath, function (err, stats) {
if (!err) {
if (stats.isDirectory()) {
readDirectoryContents(filepath)
@@ -1156,7 +1205,7 @@ function onFileUpload(event) {
streamCompareCount++;
totalUploadItems++;
console.log("File Path: " + filepath);
fs.readFile(filepath, function(err, file) {
fs.readFile(filepath, function (err, file) {
var updatedPath = filepath.replace(dirPath, dirName);
var filetowrite = {
path: updatedPath,
@@ -1225,7 +1274,7 @@ function onDrop(event) {
getFile(entry);
function getFile(entry) {
entry.file(function(file) {
entry.file(function (file) {
readFileContents(file)
.then((buffer) => {
var filePath = entry.fullPath;
@@ -1252,10 +1301,10 @@ function onDrop(event) {
} else if (entry.isDirectory) {
let directoryReader = entry.createReader();
directoryReader.readEntries(function(entries) {
directoryReader.readEntries(function (entries) {
streamCompareCount += entries.length - 1;
totalItemCount += entries.length - 1;
entries.forEach(function(newEntry) {
entries.forEach(function (newEntry) {
handleEntry(newEntry);
});
});

View File

@@ -27,14 +27,15 @@
<section class="content">
<div class="container-fluid">
<div class="block-header">
<h2>DASHBOARD -
<span id="accountaddress" style="word-break: break-word;"></span> -
<span id="welcome-name"></span>
<h2>
<span id="accountaddress" style="word-break: break-word;"></span>
<span id="welcome-name">
</span>
<span id="ethobalance"></span>
</h2>
</div>
<!-- Widgets -->
<div class="row clearfix">
<div class="row clearfix" id="stats-row">
<div class="col-lg-3 col-md-3 col-sm-6 col-xs-12">
<div class="info-box bg-pink hover-expand-effect">
<div class="icon">
@@ -127,9 +128,13 @@
</div>
<center>
<button type="button" class="btn bg-indigo waves-effect" data-toggle="modal" data-target="#defaultModal" onclick="resetUploadProcess();">
<button type="button" class="btn bg-indigo waves-effect" id="main-upload-button" data-toggle="modal" data-target="#defaultModal" onclick="resetUploadProcess();">
<i class="material-icons">cloud_upload</i>
<span>Upload to ethoFS now</span>
<span>Upload to ethoFS</span>
</button>
<button type="button" class="btn bg-indigo waves-effect" id="main-login-button" data-toggle="modal" data-target="#ethofsLoginModal" onclick="checkLogin();">
<i class="material-icons">fingerprint</i>
<span>Login To ethoFS</span>
</button>
</center>
<h1></h1>
@@ -386,7 +391,7 @@
<div class="modal-footer">
<button type="button" class="btn btn-link waves-effect" data-dismiss="modal">CLOSE</button>
<button type="button" class="btn btn-link waves-effect" data-dismiss="modal" id="upload-confirm-button" onclick="startUploadProcess();">CONFIRM</button>
<button type="button" class="btn btn-link waves-effect" data-dismiss="modal" id="upload-confirm-button" data-target="#preparingUploadModal" onclick="startUploadProcess();">CONFIRM</button>
</div>
</main>
</div>
@@ -692,11 +697,14 @@
<script src="assets/dashboard/plugins/jquery-countto/jquery.countTo.js"></script>
<!-- Custom Js -->
<script src="assets/dashboard/js/admin.js"></script>
<script src="assets/dashboard/js/bundle.js"></script>
<script src="assets/dashboard/js/app.js"></script>
<script src="assets/dashboard/js/bundle.js"></script>
<!-- Demo Js -->
<script src="assets/dashboard/js/demo.js"></script>
<script src="assets/dashboard/js/medium.js"></script>
<script type="text/javascript">
checkLogin();
</script>
<script>
MediumWidget.Init({
renderTo: '#medium-widget',