Browse Source

use tr hash for verification

clear deploy action
cl-refactor
yann300 10 years ago
parent
commit
9f0a10b518
  1. 7
      mix/FileIo.cpp
  2. 2
      mix/FileIo.h
  3. 2
      mix/qml/DeployContractStep.qml
  4. 72
      mix/qml/DeploymentDialogSteps.qml
  5. 6
      mix/qml/DeploymentWorker.qml
  6. 27
      mix/qml/ProjectModel.qml
  7. 119
      mix/qml/RegisteringStep.qml
  8. 6
      mix/qml/js/ProjectModel.js

7
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));

2
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;

2
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)
{

72
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
}
}

6
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)
});

27
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: {

119
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()
})
}
}
}

6
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)

Loading…
Cancel
Save