diff --git a/mix/FileIo.cpp b/mix/FileIo.cpp index 328b111d5..0a583f2a0 100644 --- a/mix/FileIo.cpp +++ b/mix/FileIo.cpp @@ -77,6 +77,13 @@ void FileIo::makeDir(QString const& _url) dirPath.mkpath(dirPath.path()); } +void FileIo::deleteDir(QString const& _url) +{ + QDir dirPath(pathFromUrl(_url)); + if (dirPath.exists()) + dirPath.removeRecursively(); +} + QString FileIo::readFile(QString const& _url) { QFile file(pathFromUrl(_url)); diff --git a/mix/FileIo.h b/mix/FileIo.h index 90a143120..eb5bc6cad 100644 --- a/mix/FileIo.h +++ b/mix/FileIo.h @@ -68,6 +68,8 @@ public: Q_INVOKABLE void stopWatching(QString const& _path); /// Delete a file Q_INVOKABLE void deleteFile(QString const& _path); + /// delete a directory + Q_INVOKABLE void deleteDir(QString const& _url); private: QString getHomePath() const; diff --git a/mix/qml/DeployContractStep.qml b/mix/qml/DeployContractStep.qml index 678132582..10f879ab7 100644 --- a/mix/qml/DeployContractStep.qml +++ b/mix/qml/DeployContractStep.qml @@ -32,7 +32,7 @@ Rectangle { if (worker.accounts.length > 0) worker.currentAccount = worker.accounts[0].id - if (projectModel.deployBlockNumber) + if (projectModel.deployBlockNumber !== -1) { worker.verifyHashes(projectModel.deploymentTrHashes, function (bn, trLost) { diff --git a/mix/qml/DeploymentDialogSteps.qml b/mix/qml/DeploymentDialogSteps.qml index 062bb5fd0..68abe2a46 100644 --- a/mix/qml/DeploymentDialogSteps.qml +++ b/mix/qml/DeploymentDialogSteps.qml @@ -9,6 +9,11 @@ Rectangle { property variant sel signal selected(string step) + function refreshCurrent() + { + menu.itemAt(sel).select() + } + function init() { menu.itemAt(0).select() @@ -22,14 +27,13 @@ Rectangle { border.color: "#cccccc" border.width: 1 - Column + ColumnLayout { anchors.fill: parent anchors.margins: 1 Repeater { id: menu - height: 150 model: [ { step: 1, @@ -50,8 +54,8 @@ Rectangle { Rectangle { - height: 50 - width: parent.width + Layout.preferredHeight: 50 + Layout.fillWidth: true color: "white" id: itemContainer @@ -130,21 +134,69 @@ Rectangle { } Connections { - target:projectModel + target: projectModel onDeploymentStarted: log.text = log.text + qsTr("Running deployment...") + "\n" onDeploymentError: log.text = log.text + error + "\n" onDeploymentComplete: log.text = log.text + qsTr("Deployment complete") + "\n" onDeploymentStepChanged: log.text = log.text + message + "\n" } + Rectangle + { + Layout.fillWidth: true + Layout.preferredHeight: 1 + color: "#cccccc" + } + + RowLayout + { + anchors.horizontalCenter: parent.horizontalCenter + Layout.preferredHeight: 20 + anchors.left: parent.left + anchors.leftMargin: 2 + Button + { + Layout.preferredHeight: 22 + Layout.preferredWidth: 22 + action: clearAction + iconSource: "qrc:/qml/img/cleariconactive.png" + } + + Action { + id: clearAction + enabled: log.text !== "" + tooltip: qsTr("Clear") + onTriggered: { + log.text = "" + } + } + + Button + { + Layout.preferredHeight: 22 + text: qsTr("Clear Deployment") + action: clearDeployAction + } + + Action { + id: clearDeployAction + onTriggered: { + fileIo.deleteDir(projectModel.deploymentDir) + projectModel.cleanDeploymentStatus() + } + } + } + ScrollView { - width: parent.width - height: parent.height - menu.height - TextField + Layout.fillHeight: true + Layout.fillWidth: true + Text { - anchors.fill: parent - maximumLength: 100000 + anchors.left: parent.left + anchors.leftMargin: 2 + font.pointSize: 9 + font.italic: true id: log } } diff --git a/mix/qml/DeploymentWorker.qml b/mix/qml/DeploymentWorker.qml index c875a662a..07b473822 100644 --- a/mix/qml/DeploymentWorker.qml +++ b/mix/qml/DeploymentWorker.qml @@ -55,8 +55,6 @@ Item for (var k in balanceRet) { var ether = QEtherHelper.createEther(balanceRet[k].result, QEther.Wei); - console.log(accounts[k].id) - console.log(ether.format()) balances[accounts[k].id] = ether } }, function(){}); @@ -144,9 +142,7 @@ Item for (var k in ret) { if (ret[k].result === null) - { - trLost.push(label[ret[k].id]) - } + trLost.push(label[ret[k]]) } callback(parseInt(b, 16), trLost) }); diff --git a/mix/qml/ProjectModel.qml b/mix/qml/ProjectModel.qml index 586bb1f17..5ec833da6 100644 --- a/mix/qml/ProjectModel.qml +++ b/mix/qml/ProjectModel.qml @@ -52,11 +52,11 @@ Item { property string applicationUrlEth property string applicationUrlHttp property string deployBlockNumber - property string deploymentTrHashes + property var deploymentTrHashes property string registerContentHashTrHash property string registerUrlTrHash - property string registerContentHashBlockNumber - property string registerUrlBlockNumber + property int registerContentHashBlockNumber: -1 + property int registerUrlBlockNumber: -1 //interface function saveAll() { ProjectModelCode.saveAll(); } @@ -83,6 +83,27 @@ Item { function registerToUrlHint(url, callback) { NetworkDeploymentCode.registerToUrlHint(url, callback); } function formatAppUrl() { NetworkDeploymentCode.formatAppUrl(url); } + function cleanDeploymentStatus() + { + deployedScenarioIndex = 0 + applicationUrlEth = "" + applicationUrlHttp = "" + deployBlockNumber = "" + deploymentTrHashes = {} + registerContentHashTrHash = "" + registerUrlTrHash = "" + registerContentHashBlockNumber = -1 + registerUrlBlockNumber = -1 + deploymentAddresses = {} + deploymentDir = "" + deploymentDialog.packageStep.packageHash = "" + deploymentDialog.packageStep.packageBase64 = "" + deploymentDialog.packageStep.packageDir = "" + deploymentDialog.packageStep.lastDeployDate = "" + deploymentDialog.packageStep.localPackageUrl = "" + saveProject() + } + Connections { target: mainApplication onLoaded: { diff --git a/mix/qml/RegisteringStep.qml b/mix/qml/RegisteringStep.qml index 9486d8a64..caae97325 100644 --- a/mix/qml/RegisteringStep.qml +++ b/mix/qml/RegisteringStep.qml @@ -27,24 +27,24 @@ Rectangle { applicationUrlHttpCtrl.text = projectModel.applicationUrlHttp visible = true - if (projectModel.registerContentHashTrHash) + if (projectModel.registerContentHashTrHash !== "") { worker.verifyHash("registerHash", projectModel.registerContentHashTrHash, function(bn, trLost) { - updateVerification(bn, trLost, verificationEthUrl) + updateVerification(projectModel.registerContentHashBlockNumber, bn, trLost, verificationEthUrl) }); } - if (projectModel.registerUrlTrHash) + if (projectModel.registerUrlTrHash !== "") { worker.verifyHash("registerUrl", projectModel.registerUrlTrHash, function(bn, trLost) { - updateVerification(bn, trLost, verificationUrl) + updateVerification(projectModel.registerUrlBlockNumber, bn, trLost, verificationUrl) }); } } - function updateVerification(originbn, trLost, ctrl) + function updateVerification(originbn, bn, trLost, ctrl) { if (trLost.length === 0) { @@ -53,7 +53,7 @@ Rectangle { } else { - ctrl.text = tr + qsTr(" invalidated") + ctrl.text = qsTr("invalidated") } } @@ -106,7 +106,7 @@ Rectangle { Layout.preferredWidth: col.width / 2 Label { - text: qsTr("Htpp URL") + text: qsTr("Http URL") anchors.right: parent.right anchors.verticalCenter: parent.verticalCenter } @@ -116,13 +116,12 @@ Rectangle { { id: applicationUrlHttpCtrl Layout.preferredWidth: 235 + } - Label - { - id: verificationUrl - anchors.top: applicationUrlHttpCtrl.bottom - anchors.topMargin: 10 - } + Label + { + id: verificationUrl + anchors.verticalCenter: parent.verticalCenter } } @@ -230,60 +229,78 @@ Rectangle { RowLayout { anchors.bottom: parent.bottom + anchors.bottomMargin: 10 width: parent.width - Button + function registerHash(callback) { - anchors.right: parent.right - anchors.rightMargin: 10 - text: qsTr("Register Dapp") - width: 30 - onClicked: + var inError = []; + var ethUrl = NetworkDeploymentCode.formatAppUrl(applicationUrlEthCtrl.text); + for (var k in ethUrl) { - var inError = []; - var ethUrl = NetworkDeploymentCode.formatAppUrl(applicationUrlEthCtrl.text); - for (var k in ethUrl) - { - if (ethUrl[k].length > 32) - inError.push(qsTr("Member too long: " + ethUrl[k]) + "\n"); - } - if (!worker.stopForInputError(inError)) - { - NetworkDeploymentCode.registerDapp(ethUrl, function(){ - projectModel.applicationUrlEth = applicationUrlEthCtrl.text - projectModel.saveProject() + if (ethUrl[k].length > 32) + inError.push(qsTr("Member too long: " + ethUrl[k]) + "\n"); + } + if (!worker.stopForInputError(inError)) + { + NetworkDeploymentCode.registerDapp(ethUrl, function(){ + projectModel.applicationUrlEth = applicationUrlEthCtrl.text + projectModel.saveProject() + worker.waitForTrReceipt(projectModel.registerContentHashTrHash, function(status, receipt) + { worker.verifyHash("registerHash", projectModel.registerContentHashTrHash, function(bn, trLost) { projectModel.registerContentHashBlockNumber = bn projectModel.saveProject() - root.updateVerification(bn, trLost, verificationEthUrl) + root.updateVerification(bn, bn, trLost, verificationEthUrl) + callback() }); - }) - } + }); + }) + } + } - if (applicationUrlHttp.text === "" || deploymentDialog.packageHash === "") - { - deployDialog.title = text; - deployDialog.text = qsTr("Please provide the link where the resources are stored and ensure the package is aleary built using the deployment step.") - deployDialog.open(); - return; - } - inError = []; - if (applicationUrlHttpCtrl.text.length > 32) - inError.push(qsTr(applicationUrlHttpCtrl.text)); - if (!worker.stopForInputError(inError)) - { - registerToUrlHint(applicationUrlHttpCtrl.text, function(){ - projectModel.applicationUrlHttp = applicationUrlHttpCtrl.text - projectModel.saveProject() + function registerUrl() + { + if (applicationUrlHttp.text === "" || deploymentDialog.packageHash === "") + { + deployDialog.title = text; + deployDialog.text = qsTr("Please provide the link where the resources are stored and ensure the package is aleary built using the deployment step.") + deployDialog.open(); + return; + } + var inError = []; + if (applicationUrlHttpCtrl.text.length > 32) + inError.push(qsTr(applicationUrlHttpCtrl.text)); + if (!worker.stopForInputError(inError)) + { + registerToUrlHint(applicationUrlHttpCtrl.text, function(){ + projectModel.applicationUrlHttp = applicationUrlHttpCtrl.text + projectModel.saveProject() + worker.waitForTrReceipt(projectModel.registerUrlTrHash, function(status, receipt) + { worker.verifyHash("registerUrl", projectModel.registerUrlTrHash, function(bn, trLost) { projectModel.registerUrlBlockNumber = bn projectModel.saveProject() - root.updateVerification(bn, trLost, verificationUrl) + root.updateVerification(bn, bn, trLost, verificationUrl) }); }) - } + }) + } + } + + Button + { + anchors.right: parent.right + anchors.rightMargin: 10 + text: qsTr("Register Dapp") + width: 30 + onClicked: + { + parent.registerHash(function(){ + parent.registerUrl() + }) } } } diff --git a/mix/qml/js/ProjectModel.js b/mix/qml/js/ProjectModel.js index a91237ec7..c482ac427 100644 --- a/mix/qml/js/ProjectModel.js +++ b/mix/qml/js/ProjectModel.js @@ -82,7 +82,7 @@ function saveProjectFile() lastPackageDate: deploymentDialog.packageStep.lastDeployDate, deployBlockNumber: projectModel.deployBlockNumber, localPackageUrl: deploymentDialog.packageStep.localPackageUrl, - deploymentTrHashes: projectModel.deploymentTrHashes, + deploymentTrHashes: JSON.stringify(projectModel.deploymentTrHashes), registerContentHashTrHash: projectModel.registerContentHashTrHash, registerUrlTrHash: projectModel.registerUrlTrHash, registerContentHashBlockNumber: projectModel.registerContentHashBlockNumber, @@ -129,9 +129,9 @@ function loadProject(path) { if (projectData.localPackageUrl) deploymentDialog.packageStep.localPackageUrl = projectData.localPackageUrl if (projectData.deploymentTrHashes) - projectModel.deploymentTrHashes = projectData.deploymentTrHashes + projectModel.deploymentTrHashes = JSON.parse(projectData.deploymentTrHashes) if (projectData.registerUrlTrHash) - projectModel.registerUrlTrHash = projectData.registerUrlHash + projectModel.registerUrlTrHash = projectData.registerUrlTrHash if (projectData.registerContentHashTrHash) projectModel.registerContentHashTrHash = projectData.registerContentHashTrHash if (projectData.registerContentHashBlockNumber)