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])
}
if (worker.accounts.length > 0)
worker.currentAccount = worker.accounts[0].id
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()
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
@ -235,8 +249,15 @@ Rectangle {
onCurrentTextChanged:
{
worker.currentAccount = currentText
accountBalance.text = worker.balance(currentText).format()
console.log(worker.balance(currentText).format())
}
}
Label
{
id: accountBalance
}
}
RowLayout
@ -428,6 +449,7 @@ Rectangle {
Label
{
id: verificationLabel
maximumLineCount: 20
}
}
}
@ -443,13 +465,14 @@ Rectangle {
onClicked:
{
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
verificationLabel.text = "0"
projectModel.saveProject()
root.updateVerification(nb, trLost)
})
projectModel.deploymentAddresses = addresses
projectModel.saveProject()

20
mix/qml/DeploymentDialogSteps.qml

@ -29,6 +29,7 @@ Rectangle {
Repeater
{
id: menu
height: 150
model: [
{
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()
{
accounts = []
balances = {}
var requests = [{
//accounts
jsonrpc: "2.0",
@ -33,7 +35,7 @@ Item
TransactionHelper.rpcCall(requests, function(arg1, arg2)
{
accounts = []
var ids = JSON.parse(arg2)[0].result;
requests = [];
for (var k in ids)
@ -53,7 +55,9 @@ Item
for (var k in balanceRet)
{
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(){});
@ -65,6 +69,16 @@ Item
}, function(){});
}
function balance(account)
{
for (var k in accounts)
{
if (accounts[k].id === account)
return balances[account]
}
return null
}
function stopForInputError(inError)
{
errorDialog.text = "";
@ -87,18 +101,54 @@ Item
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 req = 0
requests.push({
jsonrpc: "2.0",
method: "eth_blockNumber",
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){
var b = JSON.parse(response)[0].result;
callback(parseInt(b, 16))
console.log(response)
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 applicationUrlHttp
property string deployBlockNumber
property string deploymentTrHashes
property string registerContentHashTrHash
property string registerUrlTrHash
property string registerContentHashBlockNumber
property string registerUrlBlockNumber
//interface
function saveAll() { ProjectModelCode.saveAll(); }

61
mix/qml/RegisteringStep.qml

@ -16,7 +16,7 @@ Rectangle {
property int ownedRegistrarSetSubRegistrarGas: 50000
property int ownedRegistrarSetContentHashGas: 50000
property int urlHintSuggestUrlGas: 70000
id: root
color: "#E3E3E3E3"
anchors.fill: parent
@ -26,6 +26,35 @@ Rectangle {
applicationUrlEthCtrl.text = projectModel.applicationUrlEth
applicationUrlHttpCtrl.text = projectModel.applicationUrlHttp
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
@ -87,6 +116,13 @@ Rectangle {
{
id: applicationUrlHttpCtrl
Layout.preferredWidth: 235
Label
{
id: verificationUrl
anchors.top: applicationUrlHttpCtrl.bottom
anchors.topMargin: 10
}
}
}
@ -141,7 +177,7 @@ Rectangle {
text: qsTr("Ethereum URL")
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
}
}
}
Rectangle
@ -183,14 +219,19 @@ Rectangle {
font.italic: true
font.pointSize: appStyle.absoluteSize(-1)
}
Label
{
id: verificationEthUrl
}
}
}
RowLayout
{
anchors.bottom: parent.bottom
width: parent.width
anchors.bottomMargin: 8
width: parent.width
Button
{
anchors.right: parent.right
@ -211,6 +252,12 @@ Rectangle {
NetworkDeploymentCode.registerDapp(ethUrl, function(){
projectModel.applicationUrlEth = applicationUrlEthCtrl.text
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(){
projectModel.applicationUrlHttp = applicationUrlHttpCtrl.text
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 {
target: codeModel
onCompilationComplete:

25
mix/qml/js/NetworkDeployment.js

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

18
mix/qml/js/ProjectModel.js

@ -81,7 +81,12 @@ function saveProjectFile()
deploymentDir: deploymentDialog.packageStep.packageDir,
lastPackageDate: deploymentDialog.packageStep.lastDeployDate,
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++)
projectData.files.push({
@ -123,6 +128,16 @@ function loadProject(path) {
projectModel.deployBlockNumber = projectData.deployBlockNumber
if (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) {
var parts = path.split("/");
projectData.title = parts[parts.length - 2];
@ -369,3 +384,4 @@ function generateFileName(name, extension) {
} while (fileIo.fileExists(filePath));
return fileName
}

Loading…
Cancel
Save