Browse Source

more advanced verification system

logs
display account balance
cl-refactor
yann300 10 years ago
parent
commit
fe06089705
  1. 35
      mix/qml/DeployContractStep.qml
  2. 20
      mix/qml/DeploymentDialogSteps.qml
  3. 62
      mix/qml/DeploymentWorker.qml
  4. 5
      mix/qml/ProjectModel.qml
  5. 61
      mix/qml/RegisteringStep.qml
  6. 7
      mix/qml/StatusPane.qml
  7. 25
      mix/qml/js/NetworkDeployment.js
  8. 18
      mix/qml/js/ProjectModel.js

35
mix/qml/DeployContractStep.qml

@ -28,18 +28,32 @@ Rectangle {
{ {
accountsModel.append(worker.accounts[k]) accountsModel.append(worker.accounts[k])
} }
if (worker.accounts.length > 0) if (worker.accounts.length > 0)
worker.currentAccount = worker.accounts[0].id worker.currentAccount = worker.accounts[0].id
if (projectModel.deployBlockNumber) if (projectModel.deployBlockNumber)
{ {
worker.blockNumber(function (bn) worker.verifyHashes(projectModel.deploymentTrHashes, function (bn, trLost)
{ {
verificationLabel.text = bn - projectModel.deployBlockNumber root.updateVerification(bn, trLost)
}); });
} }
deployedAddresses.refresh() deployedAddresses.refresh()
worker.renewCtx()
}
function updateVerification(blockNumber, trLost)
{
verificationLabel.text = blockNumber - projectModel.deployBlockNumber
if (trLost.length > 0)
{
verificationLabel.text += "\n" + qsTr("Transactions lost") + "\n"
for (var k in trLost)
{
verificationLabel.text += trLost[k] + "\n"
}
}
} }
RowLayout RowLayout
@ -235,8 +249,15 @@ Rectangle {
onCurrentTextChanged: onCurrentTextChanged:
{ {
worker.currentAccount = currentText worker.currentAccount = currentText
accountBalance.text = worker.balance(currentText).format()
console.log(worker.balance(currentText).format())
} }
} }
Label
{
id: accountBalance
}
} }
RowLayout RowLayout
@ -428,6 +449,7 @@ Rectangle {
Label Label
{ {
id: verificationLabel id: verificationLabel
maximumLineCount: 20
} }
} }
} }
@ -443,13 +465,14 @@ Rectangle {
onClicked: onClicked:
{ {
projectModel.deployedScenarioIndex = contractList.currentIndex projectModel.deployedScenarioIndex = contractList.currentIndex
NetworkDeploymentCode.deployContracts(root.gas, function(addresses) NetworkDeploymentCode.deployContracts(root.gas, function(addresses, trHashes)
{ {
worker.blockNumber(function (nb) projectModel.deploymentTrHashes = trHashes
worker.verifyHashes(trHashes, function (nb, trLost)
{ {
projectModel.deployBlockNumber = nb projectModel.deployBlockNumber = nb
verificationLabel.text = "0"
projectModel.saveProject() projectModel.saveProject()
root.updateVerification(nb, trLost)
}) })
projectModel.deploymentAddresses = addresses projectModel.deploymentAddresses = addresses
projectModel.saveProject() projectModel.saveProject()

20
mix/qml/DeploymentDialogSteps.qml

@ -29,6 +29,7 @@ Rectangle {
Repeater Repeater
{ {
id: menu id: menu
height: 150
model: [ model: [
{ {
step: 1, step: 1,
@ -128,6 +129,25 @@ Rectangle {
} }
} }
Connections {
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"
}
ScrollView
{
width: parent.width
height: parent.height - menu.height
TextField
{
anchors.fill: parent
maximumLength: 100000
id: log
}
}
} }
} }

62
mix/qml/DeploymentWorker.qml

@ -23,6 +23,8 @@ Item
function renewCtx() function renewCtx()
{ {
accounts = []
balances = {}
var requests = [{ var requests = [{
//accounts //accounts
jsonrpc: "2.0", jsonrpc: "2.0",
@ -33,7 +35,7 @@ Item
TransactionHelper.rpcCall(requests, function(arg1, arg2) TransactionHelper.rpcCall(requests, function(arg1, arg2)
{ {
accounts = []
var ids = JSON.parse(arg2)[0].result; var ids = JSON.parse(arg2)[0].result;
requests = []; requests = [];
for (var k in ids) for (var k in ids)
@ -53,7 +55,9 @@ Item
for (var k in balanceRet) for (var k in balanceRet)
{ {
var ether = QEtherHelper.createEther(balanceRet[k].result, QEther.Wei); var ether = QEtherHelper.createEther(balanceRet[k].result, QEther.Wei);
balances[accounts[k]] = ether console.log(accounts[k].id)
console.log(ether.format())
balances[accounts[k].id] = ether
} }
}, function(){}); }, function(){});
}, function(){}); }, function(){});
@ -65,6 +69,16 @@ Item
}, function(){}); }, function(){});
} }
function balance(account)
{
for (var k in accounts)
{
if (accounts[k].id === account)
return balances[account]
}
return null
}
function stopForInputError(inError) function stopForInputError(inError)
{ {
errorDialog.text = ""; errorDialog.text = "";
@ -87,18 +101,54 @@ Item
poolLog.start(); poolLog.start();
} }
function blockNumber(callback) function verifyHash(tr, hash, callBack)
{ {
var h = {}
h[tr] = hash
verifyHashes(h, function (bn, trLost)
{
callBack(bn, trLost)
});
}
function verifyHashes(trHashes, callback)
{
//trHashes : { "trLabel": 'hash' }
var requests = []; var requests = [];
var req = 0
requests.push({ requests.push({
jsonrpc: "2.0", jsonrpc: "2.0",
method: "eth_blockNumber", method: "eth_blockNumber",
params: [], params: [],
id: 0 id: req
}); });
var label = {}
for (var k in trHashes)
{
req++
label[req] = k
requests.push({
jsonrpc: "2.0",
method: "eth_getTransactionReceipt",
params: [trHashes[k]],
id: req
});
}
TransactionHelper.rpcCall(requests, function (httpRequest, response){ TransactionHelper.rpcCall(requests, function (httpRequest, response){
var b = JSON.parse(response)[0].result; console.log(response)
callback(parseInt(b, 16))
var ret = JSON.parse(response)
var b = ret[0].result;
var trLost = []
for (var k in ret)
{
if (ret[k].result === null)
{
trLost.push(label[ret[k].id])
}
}
callback(parseInt(b, 16), trLost)
}); });
} }

5
mix/qml/ProjectModel.qml

@ -52,6 +52,11 @@ Item {
property string applicationUrlEth property string applicationUrlEth
property string applicationUrlHttp property string applicationUrlHttp
property string deployBlockNumber property string deployBlockNumber
property string deploymentTrHashes
property string registerContentHashTrHash
property string registerUrlTrHash
property string registerContentHashBlockNumber
property string registerUrlBlockNumber
//interface //interface
function saveAll() { ProjectModelCode.saveAll(); } function saveAll() { ProjectModelCode.saveAll(); }

61
mix/qml/RegisteringStep.qml

@ -16,7 +16,7 @@ Rectangle {
property int ownedRegistrarSetSubRegistrarGas: 50000 property int ownedRegistrarSetSubRegistrarGas: 50000
property int ownedRegistrarSetContentHashGas: 50000 property int ownedRegistrarSetContentHashGas: 50000
property int urlHintSuggestUrlGas: 70000 property int urlHintSuggestUrlGas: 70000
id: root
color: "#E3E3E3E3" color: "#E3E3E3E3"
anchors.fill: parent anchors.fill: parent
@ -26,6 +26,35 @@ Rectangle {
applicationUrlEthCtrl.text = projectModel.applicationUrlEth applicationUrlEthCtrl.text = projectModel.applicationUrlEth
applicationUrlHttpCtrl.text = projectModel.applicationUrlHttp applicationUrlHttpCtrl.text = projectModel.applicationUrlHttp
visible = true visible = true
if (projectModel.registerContentHashTrHash)
{
worker.verifyHash("registerHash", projectModel.registerContentHashTrHash, function(bn, trLost)
{
updateVerification(bn, trLost, verificationEthUrl)
});
}
if (projectModel.registerUrlTrHash)
{
worker.verifyHash("registerUrl", projectModel.registerUrlTrHash, function(bn, trLost)
{
updateVerification(bn, trLost, verificationUrl)
});
}
}
function updateVerification(originbn, trLost, ctrl)
{
if (trLost.length === 0)
{
ctrl.text = bn - originbn
ctrl.text += qsTr(" verifications")
}
else
{
ctrl.text = tr + qsTr(" invalidated")
}
} }
ColumnLayout ColumnLayout
@ -87,6 +116,13 @@ Rectangle {
{ {
id: applicationUrlHttpCtrl id: applicationUrlHttpCtrl
Layout.preferredWidth: 235 Layout.preferredWidth: 235
Label
{
id: verificationUrl
anchors.top: applicationUrlHttpCtrl.bottom
anchors.topMargin: 10
}
} }
} }
@ -141,7 +177,7 @@ Rectangle {
text: qsTr("Ethereum URL") text: qsTr("Ethereum URL")
anchors.right: parent.right anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
} }
} }
Rectangle Rectangle
@ -183,14 +219,19 @@ Rectangle {
font.italic: true font.italic: true
font.pointSize: appStyle.absoluteSize(-1) font.pointSize: appStyle.absoluteSize(-1)
} }
Label
{
id: verificationEthUrl
}
} }
} }
RowLayout RowLayout
{ {
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
width: parent.width width: parent.width
anchors.bottomMargin: 8
Button Button
{ {
anchors.right: parent.right anchors.right: parent.right
@ -211,6 +252,12 @@ Rectangle {
NetworkDeploymentCode.registerDapp(ethUrl, function(){ NetworkDeploymentCode.registerDapp(ethUrl, function(){
projectModel.applicationUrlEth = applicationUrlEthCtrl.text projectModel.applicationUrlEth = applicationUrlEthCtrl.text
projectModel.saveProject() projectModel.saveProject()
worker.verifyHash("registerHash", projectModel.registerContentHashTrHash, function(bn, trLost)
{
projectModel.registerContentHashBlockNumber = bn
projectModel.saveProject()
root.updateVerification(bn, trLost, verificationEthUrl)
});
}) })
} }
@ -229,6 +276,12 @@ Rectangle {
registerToUrlHint(applicationUrlHttpCtrl.text, function(){ registerToUrlHint(applicationUrlHttpCtrl.text, function(){
projectModel.applicationUrlHttp = applicationUrlHttpCtrl.text projectModel.applicationUrlHttp = applicationUrlHttpCtrl.text
projectModel.saveProject() projectModel.saveProject()
worker.verifyHash("registerUrl", projectModel.registerUrlTrHash, function(bn, trLost)
{
projectModel.registerUrlBlockNumber = bn
projectModel.saveProject()
root.updateVerification(bn, trLost, verificationUrl)
});
}) })
} }
} }

7
mix/qml/StatusPane.qml

@ -110,13 +110,6 @@ Rectangle {
} }
} }
Connections {
target:projectModel
onDeploymentStarted: infoMessage(qsTr("Running deployment..."), "Deployment");
onDeploymentError: errorMessage(error, "Deployment");
onDeploymentComplete: infoMessage(qsTr("Deployment complete"), "Deployment");
onDeploymentStepChanged: infoMessage(message, "Deployment");
}
Connections { Connections {
target: codeModel target: codeModel
onCompilationComplete: onCompilationComplete:

25
mix/qml/js/NetworkDeployment.js

@ -48,11 +48,12 @@ function deployContracts(gas, callback)
console.log(txt); console.log(txt);
return; return;
} }
executeTr(0, 0, state, ctrAddresses, function(){ var trHashes = {}
executeTr(0, 0, state, ctrAddresses, trHashes, function(){
projectModel.deploymentAddresses = ctrAddresses; projectModel.deploymentAddresses = ctrAddresses;
deploymentStepChanged(qsTr("Scenario deployed. Please wait for verifications")) deploymentStepChanged(qsTr("Scenario deployed. Please wait for verifications"))
if (callback) if (callback)
callback(ctrAddresses) callback(ctrAddresses, trHashes)
}); });
} }
@ -140,7 +141,7 @@ function getFunction(ctrName, functionId)
var deploymentGas var deploymentGas
var trRealIndex = -1 var trRealIndex = -1
function executeTr(blockIndex, trIndex, state, ctrAddresses, callBack) function executeTr(blockIndex, trIndex, state, ctrAddresses, trHashes, callBack)
{ {
trRealIndex++; trRealIndex++;
var tr = state.blocks.get(blockIndex).transactions.get(trIndex); var tr = state.blocks.get(blockIndex).transactions.get(trIndex);
@ -148,7 +149,7 @@ function executeTr(blockIndex, trIndex, state, ctrAddresses, callBack)
callBack() callBack()
var func = getFunction(tr.contractId, tr.functionId); var func = getFunction(tr.contractId, tr.functionId);
if (!func) if (!func)
executeTrNextStep(blockIndex, trIndex, state, ctrAddresses, callBack); executeTrNextStep(blockIndex, trIndex, state, ctrAddresses, trHashes, callBack);
else else
{ {
var gasCost = clientModel.toHex(deploymentGas[trRealIndex]); var gasCost = clientModel.toHex(deploymentGas[trRealIndex]);
@ -172,8 +173,9 @@ function executeTr(blockIndex, trIndex, state, ctrAddresses, callBack)
var txt = qsTr(tr.contractId + "." + tr.functionId + "() ...") var txt = qsTr(tr.contractId + "." + tr.functionId + "() ...")
deploymentStepChanged(txt); deploymentStepChanged(txt);
console.log(txt); console.log(txt);
var hash = JSON.parse(response)[0].result
deploymentDialog.worker.waitForTrReceipt(JSON.parse(response)[0].result, function(status, receipt){ trHashes[tr.contractId + "." + tr.functionId + "()"] = hash
deploymentDialog.worker.waitForTrReceipt(hash, function(status, receipt){
if (status === -1) if (status === -1)
trCountIncrementTimeOut(); trCountIncrementTimeOut();
else else
@ -183,7 +185,7 @@ function executeTr(blockIndex, trIndex, state, ctrAddresses, callBack)
ctrAddresses[tr.contractId] = receipt.contractAddress ctrAddresses[tr.contractId] = receipt.contractAddress
ctrAddresses[tr.contractId + " - " + trIndex] = receipt.contractAddress //get right ctr address if deploy more than one contract of same type. ctrAddresses[tr.contractId + " - " + trIndex] = receipt.contractAddress //get right ctr address if deploy more than one contract of same type.
} }
executeTrNextStep(blockIndex, trIndex, state, ctrAddresses, callBack) executeTrNextStep(blockIndex, trIndex, state, ctrAddresses, trHashes, callBack)
} }
}) })
}); });
@ -203,17 +205,17 @@ function retrieveContractAddress(trHash, callback)
}) })
} }
function executeTrNextStep(blockIndex, trIndex, state, ctrAddresses, callBack) function executeTrNextStep(blockIndex, trIndex, state, ctrAddresses, trHashes, callBack)
{ {
trIndex++; trIndex++;
if (trIndex < state.blocks.get(blockIndex).transactions.count) if (trIndex < state.blocks.get(blockIndex).transactions.count)
executeTr(blockIndex, trIndex, state, ctrAddresses, callBack); executeTr(blockIndex, trIndex, state, ctrAddresses, trHashes, callBack);
else else
{ {
blockIndex++ blockIndex++
if (blockIndex < state.blocks.count) if (blockIndex < state.blocks.count)
{ {
executeTr(blockIndex, 0, state, ctrAddresses, callBack); executeTr(blockIndex, 0, state, ctrAddresses, trHashes, callBack);
} }
else else
{ {
@ -514,6 +516,7 @@ function registerContentHash(registrar, callBack)
deploymentStepChanged(txt); deploymentStepChanged(txt);
console.log(txt); console.log(txt);
console.log("register url " + deploymentDialog.packageStep.packageHash + " " + projectModel.projectTitle) console.log("register url " + deploymentDialog.packageStep.packageHash + " " + projectModel.projectTitle)
projectModel.registerContentHashTrHash = ""
var requests = []; var requests = [];
var paramTitle = clientModel.encodeStringParam(projectModel.projectTitle); var paramTitle = clientModel.encodeStringParam(projectModel.projectTitle);
var gasCost = clientModel.toHex(deploymentDialog.registerStep.ownedRegistrarSetContentHashGas); var gasCost = clientModel.toHex(deploymentDialog.registerStep.ownedRegistrarSetContentHashGas);
@ -525,6 +528,7 @@ function registerContentHash(registrar, callBack)
id: jsonRpcRequestId++ id: jsonRpcRequestId++
}); });
rpcCall(requests, function (httpRequest, response) { rpcCall(requests, function (httpRequest, response) {
projectModel.registerContentHashTrHash = JSON.parse(response)[0].result
callBack(true); callBack(true);
}); });
} }
@ -546,6 +550,7 @@ function registerToUrlHint(url, callback)
}); });
rpcCall(requests, function (httpRequest, response) { rpcCall(requests, function (httpRequest, response) {
projectModel.registerUrlTrHash = JSON.parse(response)[0].result
deploymentComplete(); deploymentComplete();
if (callback) if (callback)
callback() callback()

18
mix/qml/js/ProjectModel.js

@ -81,7 +81,12 @@ function saveProjectFile()
deploymentDir: deploymentDialog.packageStep.packageDir, deploymentDir: deploymentDialog.packageStep.packageDir,
lastPackageDate: deploymentDialog.packageStep.lastDeployDate, lastPackageDate: deploymentDialog.packageStep.lastDeployDate,
deployBlockNumber: projectModel.deployBlockNumber, deployBlockNumber: projectModel.deployBlockNumber,
localPackageUrl: deploymentDialog.packageStep.localPackageUrl localPackageUrl: deploymentDialog.packageStep.localPackageUrl,
deploymentTrHashes: projectModel.deploymentTrHashes,
registerContentHashTrHash: projectModel.registerContentHashTrHash,
registerUrlTrHash: projectModel.registerUrlTrHash,
registerContentHashBlockNumber: projectModel.registerContentHashBlockNumber,
registerUrlBlockNumber: projectModel.registerUrlBlockNumber
}; };
for (var i = 0; i < projectListModel.count; i++) for (var i = 0; i < projectListModel.count; i++)
projectData.files.push({ projectData.files.push({
@ -123,6 +128,16 @@ function loadProject(path) {
projectModel.deployBlockNumber = projectData.deployBlockNumber projectModel.deployBlockNumber = projectData.deployBlockNumber
if (projectData.localPackageUrl) if (projectData.localPackageUrl)
deploymentDialog.packageStep.localPackageUrl = projectData.localPackageUrl deploymentDialog.packageStep.localPackageUrl = projectData.localPackageUrl
if (projectData.deploymentTrHashes)
projectModel.deploymentTrHashes = projectData.deploymentTrHashes
if (projectData.registerUrlTrHash)
projectModel.registerUrlTrHash = projectData.registerUrlHash
if (projectData.registerContentHashTrHash)
projectModel.registerContentHashTrHash = projectData.registerContentHashTrHash
if (projectData.registerContentHashBlockNumber)
projectModel.registerContentHashBlockNumber = projectData.registerContentHashBlockNumber
if (projectData.registerUrlBlockNumber)
projectModel.registerUrlBlockNumber = projectData.registerUrlBlockNumber
if (!projectData.title) { if (!projectData.title) {
var parts = path.split("/"); var parts = path.split("/");
projectData.title = parts[parts.length - 2]; projectData.title = parts[parts.length - 2];
@ -369,3 +384,4 @@ function generateFileName(name, extension) {
} while (fileIo.fileExists(filePath)); } while (fileIo.fileExists(filePath));
return fileName return fileName
} }

Loading…
Cancel
Save