#18 Upload Completion Bug Fix

This commit is contained in:
Dev-JamesR
2019-10-13 21:44:25 -07:00
parent 30f0c8c544
commit cbd296ab35
3 changed files with 132 additions and 124 deletions

View File

@@ -98,7 +98,7 @@ function ethofsLogin(privateKey) {
GlobalPrivateKey = privateKey; GlobalPrivateKey = privateKey;
privateKeyLogin = true; privateKeyLogin = true;
web3.eth.net.isListening() web3.eth.net.isListening()
.then(function() { .then(function () {
console.log('ethoFS is connected') console.log('ethoFS is connected')
let account = web3.eth.accounts.privateKeyToAccount('0x' + privateKey); let account = web3.eth.accounts.privateKeyToAccount('0x' + privateKey);
console.log(account); console.log(account);
@@ -109,7 +109,7 @@ function ethofsLogin(privateKey) {
} else { } else {
privateKeyLogin = false; privateKeyLogin = false;
web3 = new Web3(web3.currentProvider); web3 = new Web3(web3.currentProvider);
web3.eth.getAccounts(function(err, accounts) { web3.eth.getAccounts(function (err, accounts) {
if (err != null) { if (err != null) {
console.error("An error occurred: " + err); console.error("An error occurred: " + err);
outputNoAddressContractTable(); outputNoAddressContractTable();
@@ -132,11 +132,11 @@ function startEthofs() {
console.log("Starting ethoFS"); console.log("Starting ethoFS");
GlobalUserAddress = web3.eth.defaultAccount; GlobalUserAddress = web3.eth.defaultAccount;
var ethoFSAccounts = new web3.eth.Contract(GlobalControllerABI, GlobalControllerContractAddress); 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 (!error) {
if (result) { if (result) {
document.getElementById("accountaddress").textContent = web3.eth.defaultAccount; 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 (!error) {
if (result) { if (result) {
getBlockHeight(web3); getBlockHeight(web3);
@@ -177,12 +177,12 @@ function AddNewUser(userName) {
}; };
var privateKey = '0x' + GlobalPrivateKey; var privateKey = '0x' + GlobalPrivateKey;
web3.eth.accounts.signTransaction(tx, privateKey) web3.eth.accounts.signTransaction(tx, privateKey)
.then(function(signedTransactionData) { .then(function (signedTransactionData) {
web3.eth.sendSignedTransaction(signedTransactionData.rawTransaction, function(error, result) { web3.eth.sendSignedTransaction(signedTransactionData.rawTransaction, function (error, result) {
if (!error) { if (!error) {
if (result) { if (result) {
$('#minedBlockTrackerModal').modal('show'); $('#minedBlockTrackerModal').modal('show');
waitForReceipt(result, function(receipt) { waitForReceipt(result, function (receipt) {
console.log("Transaction Has Been Mined: " + receipt); console.log("Transaction Has Been Mined: " + receipt);
$('#minedBlockTrackerModal').modal('hide'); $('#minedBlockTrackerModal').modal('hide');
ethofsLogin(GlobalPrivateKey); ethofsLogin(GlobalPrivateKey);
@@ -196,12 +196,12 @@ function AddNewUser(userName) {
}); });
}); });
} else { } else {
controller.methods.AddNewUserPublic(userName).send(function(error, result) { controller.methods.AddNewUserPublic(userName).send(function (error, result) {
if (!error) { if (!error) {
if (result) { if (result) {
document.getElementById("wait").innerHTML = 'Waiting For Add User Confirmation.'; document.getElementById("wait").innerHTML = 'Waiting For Add User Confirmation.';
$('#minedBlockTrackerModal').modal('show'); $('#minedBlockTrackerModal').modal('show');
waitForReceipt(result, function(receipt) { waitForReceipt(result, function (receipt) {
console.log("Transaction Has Been Mined: " + receipt); console.log("Transaction Has Been Mined: " + receipt);
$('#minedBlockTrackerModal').modal('hide'); $('#minedBlockTrackerModal').modal('hide');
ethofsLogin(""); ethofsLogin("");
@@ -220,7 +220,7 @@ function AddNewUser(userName) {
/*************************************************************************************************************/ /*************************************************************************************************************/
function getBlockHeight(web3) { function getBlockHeight(web3) {
console.log("Starting Block Height Detection.."); console.log("Starting Block Height Detection..");
web3.eth.getBlockNumber(function(err, data) { web3.eth.getBlockNumber(function (err, data) {
document.getElementById("blocknumber").textContent = data; document.getElementById("blocknumber").textContent = data;
console.log("ETHO Block Number: " + data); console.log("ETHO Block Number: " + data);
}); });
@@ -228,7 +228,7 @@ function getBlockHeight(web3) {
/*************************************************************************************************************/ /*************************************************************************************************************/
function getBalance(web3) { function getBalance(web3) {
console.log("Starting Balance Detection.."); 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); var balance = "ETHO Balance: " + Number(web3.utils.fromWei(data, "ether")).toFixed(2);
document.getElementById("ethobalance").textContent = balance; document.getElementById("ethobalance").textContent = balance;
console.log("ETHO Balance: " + data); console.log("ETHO Balance: " + data);
@@ -246,10 +246,10 @@ function calculateCost(contractSize, contractDuration, hostingCost) {
/*************************************************************************************************************/ /*************************************************************************************************************/
//CHECK FOR TX - BLOCK TO BE MINED //CHECK FOR TX - BLOCK TO BE MINED
function waitForReceipt(hash, cb) { 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"; document.getElementById("mining-status-message").textContent = "In Progress";
$miningMessage.innerText = "Waiting For Transaction Confirmation"; $miningMessage.innerText = "Waiting For Transaction Confirmation";
web3.eth.getBlock('latest', function(e, res) { web3.eth.getBlock('latest', function (e, res) {
if (!e) { if (!e) {
document.getElementById("block-height").textContent = res.number; document.getElementById("block-height").textContent = res.number;
} }
@@ -265,7 +265,7 @@ function waitForReceipt(hash, cb) {
cb(receipt); cb(receipt);
} }
} else { } else {
setTimeout(function() { setTimeout(function () {
waitForReceipt(hash, cb); waitForReceipt(hash, cb);
}, 10000); }, 10000);
} }
@@ -285,13 +285,13 @@ function RemoveContract(hostingAddress, contentHash) {
var privateKey = '0x' + GlobalPrivateKey; var privateKey = '0x' + GlobalPrivateKey;
console.log("Private Key: " + privateKey); console.log("Private Key: " + privateKey);
web3.eth.accounts.signTransaction(tx, privateKey) web3.eth.accounts.signTransaction(tx, privateKey)
.then(function(signedTransactionData) { .then(function (signedTransactionData) {
console.log("Signed TX Data: " + signedTransactionData.rawTransaction); 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 (!error) {
if (result) { if (result) {
$('#minedBlockTrackerModal').modal('show'); $('#minedBlockTrackerModal').modal('show');
waitForReceipt(result, function(receipt) { waitForReceipt(result, function (receipt) {
console.log("Transaction Has Been Mined: " + receipt); console.log("Transaction Has Been Mined: " + receipt);
$('#minedBlockTrackerModal').modal('hide'); $('#minedBlockTrackerModal').modal('hide');
updateContractTable(); updateContractTable();
@@ -309,11 +309,11 @@ function RemoveContract(hostingAddress, contentHash) {
to: GlobalControllerContractAddress, to: GlobalControllerContractAddress,
from: GlobalUserAddress, 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 (!error) {
if (result) { if (result) {
$('#minedBlockTrackerModal').modal('show'); $('#minedBlockTrackerModal').modal('show');
waitForReceipt(result, function(receipt) { waitForReceipt(result, function (receipt) {
console.log("Transaction Has Been Mined: " + receipt); console.log("Transaction Has Been Mined: " + receipt);
$('#minedBlockTrackerModal').modal('hide'); $('#minedBlockTrackerModal').modal('hide');
updateContractTable(); updateContractTable();
@@ -335,14 +335,14 @@ function updateContractTable() {
var hostingContracts = ""; var hostingContracts = "";
var TotalContractCount = 0; var TotalContractCount = 0;
var blockHeight = 0; var blockHeight = 0;
web3.eth.getBlockNumber(function(error, result) { web3.eth.getBlockNumber(function (error, result) {
if (!error) { if (!error) {
blockHeight = result; blockHeight = result;
} else } else
console.error(error); console.error(error);
}); });
var ethoFSAccounts = new web3.eth.Contract(GlobalControllerABI, GlobalControllerContractAddress); 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; TotalContractCount = result;
GlobalTotalContractCount = result; GlobalTotalContractCount = result;
const getContractData = async (ethoFSAccounts, account, TotalContractCount) => { const getContractData = async (ethoFSAccounts, account, TotalContractCount) => {
@@ -454,15 +454,13 @@ function finishUploadModal() {
$('#uploadTrackerModal').modal('hide'); $('#uploadTrackerModal').modal('hide');
stopApplication(); stopApplication();
resetUploadSystem(); resetUploadSystem();
updateContractTable(); return;
return false;
} }
function resetUploadModal() { function resetUploadModal() {
stopApplication(); stopApplication();
resetUploadSystem(); resetUploadSystem();
updateContractTable(); return;
return false;
} }
/*************************************************************************************************************/ /*************************************************************************************************************/
//CHECK FOR PROPAGATED & AVAILABLE DATA ON NETWORK - FINAL VERIFICATION FOR UPLOADED CONTENT //CHECK FOR PROPAGATED & AVAILABLE DATA ON NETWORK - FINAL VERIFICATION FOR UPLOADED CONTENT
@@ -657,14 +655,14 @@ function contractExtensionConfirmation() {
var privateKey = '0x' + GlobalPrivateKey; var privateKey = '0x' + GlobalPrivateKey;
console.log("Private Key: " + privateKey); console.log("Private Key: " + privateKey);
web3.eth.accounts.signTransaction(tx, privateKey) web3.eth.accounts.signTransaction(tx, privateKey)
.then(function(signedTransactionData) { .then(function (signedTransactionData) {
console.log("Signed TX Data: " + signedTransactionData.rawTransaction); 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 (!error) {
if (result) { if (result) {
$('#contractDetailModal').modal('hide'); $('#contractDetailModal').modal('hide');
$('#minedBlockTrackerModal').modal('show'); $('#minedBlockTrackerModal').modal('show');
waitForReceipt(result, function(receipt) { waitForReceipt(result, function (receipt) {
console.log("Transaction Has Been Mined: " + receipt); console.log("Transaction Has Been Mined: " + receipt);
$('#minedBlockTrackerModal').modal('hide'); $('#minedBlockTrackerModal').modal('hide');
updateContractTable(); updateContractTable();
@@ -679,12 +677,12 @@ function contractExtensionConfirmation() {
}); });
} else { } 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 (!error) {
if (result) { if (result) {
$('#contractDetailModal').modal('hide'); $('#contractDetailModal').modal('hide');
$('#minedBlockTrackerModal').modal('show'); $('#minedBlockTrackerModal').modal('show');
waitForReceipt(result, function(receipt) { waitForReceipt(result, function (receipt) {
console.log("Transaction Has Been Mined: " + receipt); console.log("Transaction Has Been Mined: " + receipt);
$('#minedBlockTrackerModal').modal('hide'); $('#minedBlockTrackerModal').modal('hide');
updateContractTable(); updateContractTable();
@@ -704,13 +702,14 @@ function contractExtensionConfirmation() {
=========================================================================== */ =========================================================================== */
const subscribeToHealthChannel = () => { const subscribeToHealthChannel = () => {
window.node.pubsub.subscribe(info.id + "_alpha11", healthMessageHandler) window.node.pubsub.subscribe(info.id + "_alpha11", healthMessageHandler)
.catch(() => onError('An error occurred when subscribing to the health check workspace.')) .catch(() => onError('An error occurred when subscribing to the health check workspace.'))
} }
const healthMessageHandler = (message) => { const healthMessageHandler = (message) => {
healthMessage = message.data.toString(); healthMessage = message.data.toString();
UpdateHealthCheckInfo(healthMessage); UpdateHealthCheckInfo(healthMessage);
} }
function UpdateHealthCheckInfo(healthMessage) { function UpdateHealthCheckInfo(healthMessage) {
var mainMessage = healthMessage.split(";")[1]; var mainMessage = healthMessage.split(";")[1];
var splitMessage = mainMessage.split(","); var splitMessage = mainMessage.split(",");
@@ -718,52 +717,54 @@ function UpdateHealthCheckInfo(healthMessage) {
var availableStorageTotal = 0; var availableStorageTotal = 0;
var activeHistory = 0; var activeHistory = 0;
var nodeCounter = 0; var nodeCounter = 0;
splitMessage.forEach(function(nodeMessage, index) { splitMessage.forEach(function (nodeMessage, index) {
var nodeSplitMessage = nodeMessage.split(":"); var nodeSplitMessage = nodeMessage.split(":");
activeHistory = Number(nodeSplitMessage[5]); activeHistory = Number(nodeSplitMessage[5]);
if(activeHistory >= 5){ if (activeHistory >= 5) {
nodeCounter++; nodeCounter++;
usedStorageTotal += Number(nodeSplitMessage[8]); usedStorageTotal += Number(nodeSplitMessage[8]);
availableStorageTotal += Number(nodeSplitMessage[7]); availableStorageTotal += Number(nodeSplitMessage[7]);
} }
if(index == (splitMessage.length - 1)){ if (index == (splitMessage.length - 1)) {
updateStorageArrays(usedStorageTotal, availableStorageTotal, nodeCounter); updateStorageArrays(usedStorageTotal, availableStorageTotal, nodeCounter);
} }
}); });
function updateStorageArrays(usedStorageTotal, availableStorageTotal, nodecount){
if(availableStorageArray.length >= 50){ function updateStorageArrays(usedStorageTotal, availableStorageTotal, nodecount) {
if(availableStorageTotal > 0.75 * averageAvailableStorageTotal && availableStorageTotal < 1.25 * averageAvailableStorageTotal){
if (availableStorageArray.length >= 50) {
if (availableStorageTotal > 0.75 * averageAvailableStorageTotal && availableStorageTotal < 1.25 * averageAvailableStorageTotal) {
availableStorageArray.push(availableStorageTotal); availableStorageArray.push(availableStorageTotal);
availableStorageArray.shift(); availableStorageArray.shift();
} }
}else{ } else {
availableStorageArray.push(availableStorageTotal); availableStorageArray.push(availableStorageTotal);
} }
if(nodeCountArray.length >= 50){ if (nodeCountArray.length >= 50) {
nodeCountArray.push(nodecount); nodeCountArray.push(nodecount);
nodeCountArray.shift(); nodeCountArray.shift();
}else{ } else {
nodeCountArray.push(nodecount); nodeCountArray.push(nodecount);
} }
calculateStorageAverages(usedStorageArray, availableStorageArray, nodeCountArray); calculateStorageAverages(usedStorageArray, availableStorageArray, nodeCountArray);
} }
function calculateStorageAverages(usedStorageArray, availableStorageArray, nodeCountArray){
function calculateStorageAverages(usedStorageArray, availableStorageArray, nodeCountArray) {
var sumAvailableStorage = 0; var sumAvailableStorage = 0;
availableStorageArray.forEach(function(value, index) { availableStorageArray.forEach(function (value, index) {
sumAvailableStorage += value; sumAvailableStorage += value;
if(index == (availableStorageArray.length - 1)){ if (index == (availableStorageArray.length - 1)) {
averageAvailableStorageTotal = (sumAvailableStorage/availableStorageArray.length); averageAvailableStorageTotal = (sumAvailableStorage / availableStorageArray.length);
document.getElementById("nodestorage").textContent=(round(2+((averageAvailableStorageTotal)/1000000), 1)) + "TB"; document.getElementById("nodestorage").textContent = (round(2 + ((averageAvailableStorageTotal) / 1000000), 1)) + "TB";
} }
}); });
var sumNodeCount = 0; var sumNodeCount = 0;
nodeCountArray.forEach(function(value, index) { nodeCountArray.forEach(function (value, index) {
sumNodeCount += value; sumNodeCount += value;
if(index == (nodeCountArray.length - 1)){ if (index == (nodeCountArray.length - 1)) {
var averageNodeCount = (sumNodeCount/nodeCountArray.length) + 19; var averageNodeCount = (sumNodeCount / nodeCountArray.length) + 19;
document.getElementById("nodecount").textContent=(round(averageNodeCount, 0)); document.getElementById("nodecount").textContent = (round(averageNodeCount, 0));
} }
}); });
} }
@@ -779,16 +780,16 @@ const exitMessageHandler = (message) => {
} }
const subscribeToMessaging = () => { const subscribeToMessaging = () => {
for(var i = 4; i < PeersForChannel.length; i++){ for (var i = 4; i < PeersForChannel.length; i++) {
window.node.pubsub.subscribe(PeersForChannel[i] + "PinningChannel_alpha11", messageHandler) window.node.pubsub.subscribe(PeersForChannel[i] + "PinningChannel_alpha11", messageHandler)
.catch(() => onError('An error occurred when subscribing to the workspace.')) .catch(() => onError('An error occurred when subscribing to the workspace.'))
} }
} }
const unsubscribeToMessaging = () => { const unsubscribeToMessaging = () => {
for(var i = 4; i < PeersForChannel.length; i++){ for (var i = 4; i < PeersForChannel.length; i++) {
window.node.pubsub.unsubscribe(PeersForChannel[i] + "PinningChannel_alpha11", exitMessageHandler) window.node.pubsub.unsubscribe(PeersForChannel[i] + "PinningChannel_alpha11", exitMessageHandler)
.catch(() => onError('An error occurred when unsubscribing to the workspace.')) .catch(() => onError('An error occurred when unsubscribing to the workspace.'))
} }
} }
const publishImmediatePin = (hash) => { const publishImmediatePin = (hash) => {
const data = Buffer.from(hash) const data = Buffer.from(hash)
@@ -802,16 +803,6 @@ const publishImmediatePin = (hash) => {
/* =========================================================================== /* ===========================================================================
Files handling Files handling
=========================================================================== */ =========================================================================== */
const sendFileList = () => FILES.forEach((hash) => publishHash(hash))
/*const updateProgress = (bytesLoaded) => {
let percent = 100 - ((bytesLoaded / fileSize) * 100)
if (percent <= 5) {
document.getElementById("upload-confirm-button").style.visibility = "visible";
}
$progressBar.style.transform = `translateX(${-percent}%)`
}*/
const resetProgress = () => { const resetProgress = () => {
$progressBar.style.transform = 'translateX(-100%)' $progressBar.style.transform = 'translateX(-100%)'
} }
@@ -865,7 +856,7 @@ function startUploadProcess() {
for (var i = 0; i < MainFileArray.length; i++) { for (var i = 0; i < MainFileArray.length; i++) {
const streamFiles = (files) => { const streamFiles = (files) => {
const stream = node.addReadableStream() const stream = node.addReadableStream()
stream.on('data', function(data) { stream.on('data', function (data) {
console.log("Data..."); console.log("Data...");
console.log(data); console.log(data);
GlobalHashArray.push(`${data.hash}`); GlobalHashArray.push(`${data.hash}`);
@@ -878,7 +869,7 @@ function startUploadProcess() {
streamFinishCount++; streamFinishCount++;
GlobalMainHashArray.push(`${data.hash}`); GlobalMainHashArray.push(`${data.hash}`);
GlobalMainPathArray.push(`${data.path}`); GlobalMainPathArray.push(`${data.path}`);
if(streamFinishCount == MainFileArray.length) { if (streamFinishCount == MainFileArray.length) {
createMainHash(); createMainHash();
} }
} }
@@ -896,14 +887,14 @@ function startUploadProcess() {
let hashVerificationArray = [...GlobalHashArray, ...GlobalMainHashArray]; let hashVerificationArray = [...GlobalHashArray, ...GlobalMainHashArray];
hashVerificationArray.push(GlobalMainContentHash); hashVerificationArray.push(GlobalMainContentHash);
var hashConfirmationCount = 0; var hashConfirmationCount = 0;
var uploadCompleteFlag = false;
for (var i = 0; i < MainHashArray.length; i++) { for (var i = 0; i < MainHashArray.length; i++) {
console.log("Sending Immediate Pin Request: " + MainHashArray[i]); console.log("Sending Immediate Pin Request: " + MainHashArray[i]);
publishImmediatePin(MainHashArray[i]); publishImmediatePin(MainHashArray[i]);
} }
setTimeout(function() { setTimeout(function () {
hashVerificationArray.forEach(function(hash) { hashVerificationArray.forEach(function (hash) {
verifyDataUpload(hash); verifyDataUpload(hash);
}); });
}, 5000); }, 5000);
@@ -923,19 +914,34 @@ function startUploadProcess() {
if (confirmationPercentage >= 99) { if (confirmationPercentage >= 99) {
$uploadMessage.innerText = "Upload Complete"; $uploadMessage.innerText = "Upload Complete";
document.getElementById("upload-status-message").textContent = "Complete"; document.getElementById("upload-status-message").textContent = "Complete";
finishUploadModal(); if(!uploadCompleteFlag) {
uploadCompleteFlag = true;
updateContractTable();
finishUploadModal();
}
return;
} }
} else { } else {
setTimeout(function() { var confirmationPercentage = Math.ceil((hashConfirmationCount / hashVerificationArray.length) * 100);
verifyDataUpload(hash) if (confirmationPercentage < 99) {
}, 2000); setTimeout(function () {
verifyDataUpload(hash)
}, 2000);
} else {
return;
}
} }
} catch (error) { } catch (error) {
console.log(error); console.log(error);
console.log("Data Confirmation Error: " + error.status); console.log("Data Confirmation Error: " + error.status);
setTimeout(function() { var confirmationPercentage = Math.ceil((hashConfirmationCount / hashVerificationArray.length) * 100);
verifyDataUpload(hash) if (confirmationPercentage < 99) {
}, 2000); setTimeout(function () {
verifyDataUpload(hash)
}, 2000);
} else {
return;
}
} }
}; };
} }
@@ -998,15 +1004,15 @@ function startUploadProcess() {
var privateKey = '0x' + GlobalPrivateKey; var privateKey = '0x' + GlobalPrivateKey;
console.log("Private Key: " + privateKey); console.log("Private Key: " + privateKey);
web3.eth.accounts.signTransaction(tx, privateKey) web3.eth.accounts.signTransaction(tx, privateKey)
.then(function(signedTransactionData) { .then(function (signedTransactionData) {
console.log("Signed TX Data: " + signedTransactionData.rawTransaction); 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 (!error) {
if (result) { if (result) {
console.log("Result: " + result); console.log("Result: " + result);
$('#minedBlockTrackerModal').modal('show'); $('#minedBlockTrackerModal').modal('show');
$('#preparingUploadModal').modal('hide'); $('#preparingUploadModal').modal('hide');
waitForReceipt(result, function(receipt) { waitForReceipt(result, function (receipt) {
console.log("Transaction Has Been Mined: " + receipt); console.log("Transaction Has Been Mined: " + receipt);
$('#minedBlockTrackerModal').modal('hide'); $('#minedBlockTrackerModal').modal('hide');
$('#nodeModal').modal('hide'); $('#nodeModal').modal('hide');
@@ -1023,12 +1029,12 @@ function startUploadProcess() {
}); });
}); });
} else { } 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 (!error) {
if (result) { if (result) {
$('#minedBlockTrackerModal').modal('show'); $('#minedBlockTrackerModal').modal('show');
$('#preparingUploadModal').modal('hide'); $('#preparingUploadModal').modal('hide');
waitForReceipt(result, function(receipt) { waitForReceipt(result, function (receipt) {
console.log("Transaction Has Been Mined: " + receipt); console.log("Transaction Has Been Mined: " + receipt);
$('#minedBlockTrackerModal').modal('hide'); $('#minedBlockTrackerModal').modal('hide');
$('#nodeModal').modal('hide'); $('#nodeModal').modal('hide');
@@ -1049,6 +1055,9 @@ function startUploadProcess() {
} }
function resetUploadProcess() { function resetUploadProcess() {
updateUploadProgress(0);
$uploadMessage.innerText = "Preparing Upload";
document.getElementById("upload-status-message").textContent = "";
MainFileArray = new Array(); MainFileArray = new Array();
GlobalUploadSize = 0; GlobalUploadSize = 0;
} }
@@ -1078,8 +1087,8 @@ function onFileUpload(event) {
function readDirectoryContents(directory) { function readDirectoryContents(directory) {
console.log("Directory Path: " + directory); console.log("Directory Path: " + directory);
fs.readdir(directory, function(err, filesUploaded) { fs.readdir(directory, function (err, filesUploaded) {
if(!err) { if (!err) {
for (let i = 0; filesUploaded.length > i; i++) { for (let i = 0; filesUploaded.length > i; i++) {
handleItem(filesUploaded[i], directory); handleItem(filesUploaded[i], directory);
} }
@@ -1091,39 +1100,39 @@ function onFileUpload(event) {
function handleItem(filename, relativePath) { function handleItem(filename, relativePath) {
var filepath = relativePath.concat('\\', filename); var filepath = relativePath.concat('\\', filename);
fs.stat(filepath, function(err, stats) { fs.stat(filepath, function (err, stats) {
if(!err) { if (!err) {
if(stats.isDirectory()) { if (stats.isDirectory()) {
readDirectoryContents(filepath) readDirectoryContents(filepath)
} else {
streamCompareCount++;
totalUploadItems++;
console.log("File Path: " + filepath);
fs.readFile(filepath, function (err, file) {
var filetowrite = {
path: filepath,
content: file
};
var filename = filepath;
MainFileArray[MainFileArray.length - 1].push(filetowrite);
GlobalUploadSize += Number(stats.size);
fileSize += Number(stats.size);
var totalUploadSizeMB = GlobalUploadSize / 1000000;
appendFile(filepath, filename, stats.size, null);
console.log("Path: " + filepath + " Size: " + stats.size + " Total Size: " + GlobalUploadSize);
document.getElementById("upload-size").textContent = totalUploadSizeMB;
contractDurationChange(document.getElementById('contract-duration').value);
streamCompareCount--;
updateAnalyzeProgress(((totalUploadItems - streamCompareCount) / totalUploadItems));
if (streamCompareCount == 0) {
document.getElementById("upload-hash").textContent = "READY FOR UPLOAD";
document.getElementById("upload-confirm-button").style.visibility = "visible";
}
});
}
} else { } else {
streamCompareCount ++; console.log("File Stats Error: " + err);
totalUploadItems ++;
console.log("File Path: " + filepath);
fs.readFile(filepath, function(err, file) {
var filetowrite = {
path: filepath,
content: file
};
var filename = filepath;
MainFileArray[MainFileArray.length - 1].push(filetowrite);
GlobalUploadSize += Number(stats.size);
fileSize += Number(stats.size);
var totalUploadSizeMB = GlobalUploadSize / 1000000;
appendFile(filepath, filename, stats.size, null);
console.log("Path: " + filepath + " Size: " + stats.size + " Total Size: " + GlobalUploadSize);
document.getElementById("upload-size").textContent = totalUploadSizeMB;
contractDurationChange(document.getElementById('contract-duration').value);
streamCompareCount--;
updateAnalyzeProgress(((totalUploadItems - streamCompareCount) / totalUploadItems));
if (streamCompareCount == 0) {
document.getElementById("upload-hash").textContent = "READY FOR UPLOAD";
document.getElementById("upload-confirm-button").style.visibility = "visible";
}
});
} }
} else {
console.log("File Stats Error: " + err);
}
}); });
} }
} }
@@ -1167,7 +1176,7 @@ function onDrop(event) {
getFile(entry); getFile(entry);
function getFile(entry) { function getFile(entry) {
entry.file(function(file) { entry.file(function (file) {
readFileContents(file) readFileContents(file)
.then((buffer) => { .then((buffer) => {
var filePath = entry.fullPath; var filePath = entry.fullPath;
@@ -1194,10 +1203,10 @@ function onDrop(event) {
} else if (entry.isDirectory) { } else if (entry.isDirectory) {
let directoryReader = entry.createReader(); let directoryReader = entry.createReader();
directoryReader.readEntries(function(entries) { directoryReader.readEntries(function (entries) {
streamCompareCount += entries.length - 1; streamCompareCount += entries.length - 1;
totalItemCount += entries.length - 1; totalItemCount += entries.length - 1;
entries.forEach(function(newEntry) { entries.forEach(function (newEntry) {
handleEntry(newEntry); handleEntry(newEntry);
}); });
}); });
@@ -1346,7 +1355,8 @@ function startApplication() {
function extendedStartApplication() { function extendedStartApplication() {
$ethomessage.innerText = GlobalUserAddress; $ethomessage.innerText = GlobalUserAddress;
} }
function stopApplication() { function stopApplication() {
resetUploadProcess(); resetUploadProcess();
resetFileTable(); resetFileTable();
} }

View File

@@ -74,7 +74,6 @@ function start() {
updateView('ready', window.node) updateView('ready', window.node)
onSuccess('Node is ready.') onSuccess('Node is ready.')
setInterval(refreshPeerList, 10000) setInterval(refreshPeerList, 10000)
setInterval(sendFileList, 10000)
}) })
.catch((error) => onError(error)) .catch((error) => onError(error))
}) })

View File

@@ -72,7 +72,6 @@ function start() {
updateView('ready', window.node) updateView('ready', window.node)
onSuccess('Node is ready.') onSuccess('Node is ready.')
setInterval(refreshPeerList, 10000) setInterval(refreshPeerList, 10000)
setInterval(sendFileList, 10000)
}) })
.catch((error) => onError(error)) .catch((error) => onError(error))
}) })