Browse Source

- Display balance.

- Deploy contracts in a sync way.
 - Timeout for contract creation.
cl-refactor
yann300 10 years ago
parent
commit
22d322f40e
  1. 114
      mix/qml/DeploymentDialog.qml
  2. 11
      mix/qml/StatusPane.qml
  3. 114
      mix/qml/js/ProjectModel.js
  4. 1
      mix/qml/js/TransactionHelper.js

114
mix/qml/DeploymentDialog.qml

@ -15,7 +15,7 @@ Window {
id: modalDeploymentDialog id: modalDeploymentDialog
modality: Qt.ApplicationModal modality: Qt.ApplicationModal
width: 800 width: 930
height: 350 height: 350
visible: false visible: false
property alias applicationUrlEth: applicationUrlEth.text property alias applicationUrlEth: applicationUrlEth.text
@ -26,6 +26,7 @@ Window {
property string eth: "4c3f7330690ed3657d3fa20fe5717b84010528ae"; property string eth: "4c3f7330690ed3657d3fa20fe5717b84010528ae";
property string yanndappRegistrar: "29a2e6d3c56ef7713a4e7229c3d1a23406f0161a"; property string yanndappRegistrar: "29a2e6d3c56ef7713a4e7229c3d1a23406f0161a";
property string currentAccount property string currentAccount
property alias gasToUse: gasToUseInput.text
color: Style.generic.layout.backgroundColor color: Style.generic.layout.backgroundColor
@ -36,26 +37,48 @@ Window {
function open() function open()
{ {
var requests = []; modalDeploymentDialog.setX((Screen.width - width) / 2);
requests.push({ modalDeploymentDialog.setY((Screen.height - height) / 2);
visible = true;
var requests = [{
//accounts //accounts
jsonrpc: "2.0", jsonrpc: "2.0",
method: "eth_accounts", method: "eth_accounts",
params: null, params: null,
id: 0 id: 0
}); }];
TransactionHelper.rpcCall(requests, function(arg1, arg2) TransactionHelper.rpcCall(requests, function(arg1, arg2)
{ {
modelAccounts.clear(); modelAccounts.clear();
modelAccounts.append({ "id": JSON.parse(arg2)[0].result[0] }) var ids = JSON.parse(arg2)[0].result;
modelAccounts.append({ "id": JSON.parse(arg2)[0].result[1] }) requests = [];
currentAccount = modelAccounts.get(0).id; for (var k in ids)
{
modelAccounts.append({ "id": ids[k] })
requests.push({
//accounts
jsonrpc: "2.0",
method: "eth_balanceAt",
params: [ids[k]],
id: k
}); });
}
modalDeploymentDialog.setX((Screen.width - width) / 2); if (ids.length > 0)
modalDeploymentDialog.setY((Screen.height - height) / 2); currentAccount = modelAccounts.get(0).id;
visible = true;
TransactionHelper.rpcCall(requests, function (request, response){
var balanceRet = JSON.parse(response);
for (var k in balanceRet)
{
var ether = QEtherHelper.createEther(balanceRet[k].result, QEther.Wei);
comboAccounts.balances.push(ether.format());
}
balance.text = comboAccounts.balances[0];
});
});
} }
function pad(h) function pad(h)
@ -71,7 +94,8 @@ Window {
function waitForTrCountToIncrement(callBack) function waitForTrCountToIncrement(callBack)
{ {
poolLog.callBack = callBack; poolLog.callBack = callBack;
poolLog.k = 0; poolLog.k = -1;
poolLog.elapsed = 0;
poolLog.start(); poolLog.start();
} }
@ -79,11 +103,13 @@ Window {
{ {
id: poolLog id: poolLog
property var callBack property var callBack
property var k: -1 property int k: -1
property int elapsed
interval: 500 interval: 500
running: false running: false
repeat: true repeat: true
onTriggered: { onTriggered: {
elapsed += interval;
var requests = []; var requests = [];
var jsonRpcRequestId = 0; var jsonRpcRequestId = 0;
requests.push({ requests.push({
@ -93,14 +119,17 @@ Window {
id: jsonRpcRequestId++ id: jsonRpcRequestId++
}); });
TransactionHelper.rpcCall(requests, function (httpRequest, response){ TransactionHelper.rpcCall(requests, function (httpRequest, response){
console.log(response); response = response.replace(/,0+/, ''); // ==> result:27,00000000
response = response.replace(/,0+/, '');
console.log(response);
var count = JSON.parse(response)[0].result var count = JSON.parse(response)[0].result
if (k < parseInt(count) && k > 0) if (k < parseInt(count) && k > 0)
{ {
stop(); stop();
callBack(); callBack(1);
}
else if (elapsed > 25000)
{
stop();
callBack(-1);
} }
else else
k = parseInt(JSON.parse(response)[0].result); k = parseInt(JSON.parse(response)[0].result);
@ -124,17 +153,36 @@ Window {
text: qsTr("Account used to deploy:") text: qsTr("Account used to deploy:")
} }
Rectangle
{
width: 300
height: 25
color: "transparent"
ComboBox { ComboBox {
id: comboAccounts id: comboAccounts
property var balances: []
onCurrentIndexChanged : { onCurrentIndexChanged : {
if (modelAccounts.count > 0) if (modelAccounts.count > 0)
{
currentAccount = modelAccounts.get(currentIndex).id; currentAccount = modelAccounts.get(currentIndex).id;
balance.text = balances[currentIndex];
}
} }
model: ListModel { model: ListModel {
id: modelAccounts id: modelAccounts
} }
} }
DefaultLabel
{
anchors.verticalCenter: parent.verticalCenter
anchors.left: comboAccounts.right
anchors.leftMargin: 20
id: balance;
}
}
DefaultLabel DefaultLabel
{ {
text: qsTr("Ethereum Application URL: ") text: qsTr("Ethereum Application URL: ")
@ -157,6 +205,18 @@ Window {
id: applicationUrlHttp id: applicationUrlHttp
} }
DefaultLabel
{
text: qsTr("Amount of gas to use for each contract deployment: ")
}
DefaultTextField
{
text: "20000"
Layout.fillWidth: true
id: gasToUseInput
}
DefaultLabel DefaultLabel
{ {
text: qsTr("Package (Base64): ") text: qsTr("Package (Base64): ")
@ -170,20 +230,6 @@ Window {
height: 60 height: 60
enabled: base64Value.text != "" enabled: base64Value.text != ""
} }
DefaultLabel
{
text: qsTr("open package directory");
visible: projectModel.deploymentDir !== ""
MouseArea
{
anchors.fill: parent;
onClicked:
{
fileIo.openFileBrowser(projectModel.deploymentDir);
}
}
}
} }
MessageDialog { MessageDialog {
@ -214,6 +260,14 @@ Window {
} }
} }
Button {
text: qsTr("Open Package Directory");
enabled: projectModel.deploymentDir !== ""
onClicked: {
fileIo.openFileBrowser(projectModel.deploymentDir);
}
}
Button { Button {
text: qsTr("Register Web Application"); text: qsTr("Register Web Application");
tooltip: qsTr("Register hosted Web Application.") tooltip: qsTr("Register hosted Web Application.")

11
mix/qml/StatusPane.qml

@ -35,17 +35,24 @@ Rectangle {
logslink.visible = false; logslink.visible = false;
} }
function errorMessage(text)
{
status.state = "error";
status.text = text
logslink.visible = false;
}
Connections { Connections {
target:clientModel target:clientModel
onRunStarted: infoMessage(qsTr("Running transactions...")); onRunStarted: infoMessage(qsTr("Running transactions..."));
onRunFailed: infoMessage(qsTr("Error running transactions")); onRunFailed: errorMessage(qsTr("Error running transactions"));
onRunComplete: infoMessage(qsTr("Run complete")); onRunComplete: infoMessage(qsTr("Run complete"));
onNewBlock: infoMessage(qsTr("New block created")); onNewBlock: infoMessage(qsTr("New block created"));
} }
Connections { Connections {
target:projectModel target:projectModel
onDeploymentStarted: infoMessage(qsTr("Running deployment...")); onDeploymentStarted: infoMessage(qsTr("Running deployment..."));
onDeploymentError: infoMessage(error); onDeploymentError: errorMessage(error);
onDeploymentComplete: infoMessage(qsTr("Deployment complete")); onDeploymentComplete: infoMessage(qsTr("Deployment complete"));
onDeploymentStepChanged: infoMessage(message); onDeploymentStepChanged: infoMessage(message);
} }

114
mix/qml/js/ProjectModel.js

@ -293,7 +293,6 @@ function deployProject(force) {
deploymentDialog.open(); deploymentDialog.open();
} }
var codeTest = "";
function startDeployProject(erasePrevious) function startDeployProject(erasePrevious)
{ {
var date = new Date(); var date = new Date();
@ -308,52 +307,54 @@ function startDeployProject(erasePrevious)
console.log("Deploying " + deploymentId + " to " + jsonRpcUrl); console.log("Deploying " + deploymentId + " to " + jsonRpcUrl);
deploymentStarted(); deploymentStarted();
var requests = []; var ctrNames = Object.keys(codeModel.contracts);
var requestNames = []; var ctrAddresses = {};
deployContracts(0, ctrAddresses, ctrNames, function (){
finalizeDeployment(deploymentId, ctrAddresses);
});
}
for (var c in codeModel.contracts) { //TODO: order based on dependencies function deployContracts(ctrIndex, ctrAddresses, ctrNames, callBack)
var code = codeModel.contracts[c].codeHex; {
requests.push({ var code = codeModel.contracts[ctrNames[ctrIndex]].codeHex;
var requests = [{
jsonrpc: "2.0", jsonrpc: "2.0",
method: "eth_transact", method: "eth_transact",
params: [ { "from": deploymentDialog.currentAccount, "gas": 20000, "code": code /* "0x60056013565b61059e8061001d6000396000f35b33600081905550560060003560e060020a90048063019848921461009a578063449c2090146100af5780635d574e32146100cd5780635fd4b08a146100e1578063618242da146100f65780636be16bed1461010b5780636c4489b414610129578063893d20e8146101585780639607730714610173578063c284bc2a14610187578063e50f599a14610198578063e5811b35146101af578063ec7b9200146101cd57005b6100a560043561031b565b8060005260206000f35b6100ba6004356103a0565b80600160a060020a031660005260206000f35b6100db600435602435610537565b60006000f35b6100ec600435610529565b8060005260206000f35b6101016004356103dd565b8060005260206000f35b6101166004356103bd565b80600160a060020a031660005260206000f35b61013460043561034b565b82600160a060020a031660005281600160a060020a03166020528060405260606000f35b610160610341565b80600160a060020a031660005260206000f35b6101816004356024356102b4565b60006000f35b6101926004356103fd565b60006000f35b6101a96004356024356044356101f2565b60006000f35b6101ba6004356101eb565b80600160a060020a031660005260206000f35b6101d8600435610530565b80600160a060020a031660005260206000f35b6000919050565b600054600160a060020a031633600160a060020a031614610212576102af565b8160026000858152602001908152602001600020819055508061023457610287565b81600160a060020a0316837f680ad70765443c2967675ab0fb91a46350c01c6df59bf9a41ff8a8dd097464ec60006000a3826001600084600160a060020a03168152602001908152602001600020819055505b827f18d67da0cd86808336a3aa8912f6ea70c5250f1a98b586d1017ef56fe199d4fc60006000a25b505050565b600054600160a060020a031633600160a060020a0316146102d457610317565b806002600084815260200190815260200160002060010181905550817f18d67da0cd86808336a3aa8912f6ea70c5250f1a98b586d1017ef56fe199d4fc60006000a25b5050565b60006001600083600160a060020a03168152602001908152602001600020549050919050565b6000600054905090565b6000600060006002600085815260200190815260200160002054925060026000858152602001908152602001600020600101549150600260008581526020019081526020016000206002015490509193909250565b600060026000838152602001908152602001600020549050919050565b600060026000838152602001908152602001600020600101549050919050565b600060026000838152602001908152602001600020600201549050919050565b600054600160a060020a031633600160a060020a03161461041d57610526565b80600160006002600085815260200190815260200160002054600160a060020a031681526020019081526020016000205414610458576104d2565b6002600082815260200190815260200160002054600160a060020a0316817f680ad70765443c2967675ab0fb91a46350c01c6df59bf9a41ff8a8dd097464ec60006000a36000600160006002600085815260200190815260200160002054600160a060020a03168152602001908152602001600020819055505b6002600082815260200190815260200160002060008101600090556001810160009055600281016000905550807f18d67da0cd86808336a3aa8912f6ea70c5250f1a98b586d1017ef56fe199d4fc60006000a25b50565b6000919050565b6000919050565b600054600160a060020a031633600160a060020a0316146105575761059a565b806002600084815260200190815260200160002060020181905550817f18d67da0cd86808336a3aa8912f6ea70c5250f1a98b586d1017ef56fe199d4fc60006000a25b505056" */ } ], params: [ { "from": deploymentDialog.currentAccount, "gas": deploymentDialog.gasToUse, "code": code } ],
id: jsonRpcRequestId++ id: 0
}); }];
requestNames.push(c); rpcCall(requests, function (httpCall, response){
codeTest = code; var txt = qsTr("Please wait while " + ctrNames[ctrIndex] + " is published ...")
}
var rpcRequest = JSON.stringify(requests);
var httpRequest = new XMLHttpRequest();
httpRequest.open("POST", jsonRpcUrl, true);
httpRequest.setRequestHeader("Content-type", "application/json");
httpRequest.setRequestHeader("Content-length", rpcRequest.length);
httpRequest.setRequestHeader("Connection", "close");
httpRequest.onreadystatechange = function() {
if (httpRequest.readyState === XMLHttpRequest.DONE) {
if (httpRequest.status === 200) {
var rpcResponse = JSON.parse(httpRequest.responseText);
console.log("crea" + httpRequest.responseText);
if (rpcResponse.length === requestNames.length) {
var contractAddresses = {};
for (var r = 0; r < rpcResponse.length; r++)
contractAddresses[requestNames[r]] = rpcResponse[r].result;
var txt = qsTr("Please wait while the contract is published ...")
deploymentStepChanged(txt); deploymentStepChanged(txt);
console.log(txt); console.log(txt);
deploymentDialog.waitForTrCountToIncrement(function() { ctrAddresses[ctrNames[ctrIndex]] = JSON.parse(response)[0].result
finalizeDeployment(deploymentId, contractAddresses); deploymentDialog.waitForTrCountToIncrement(function(status) {
}); if (status === -1)
} {
} else { trCountIncrementTimeOut();
var errorText = qsTr("Deployment error: RPC server HTTP status ") + httpRequest.status; return;
console.log(errorText);
deploymentError(errorText);
}
} }
ctrIndex++;
if (ctrIndex < ctrNames.length)
deployContracts(ctrIndex, ctrAddresses, ctrNames, callBack);
else
callBack();
});
});
} }
httpRequest.send(rpcRequest);
function checkNewLog()
{
var requests = [];
requests.push({
jsonrpc: "2.0",
method: "eth_changed",
params: [0],
id: 0
});
rpcCall(requests, function (httpRequest, response) {
console.log("eth log: " + response);
});
} }
function finalizeDeployment(deploymentId, addresses) { function finalizeDeployment(deploymentId, addresses) {
@ -480,7 +481,7 @@ function checkRegistration(dappUrl, addr, callBack)
var errorTxt; var errorTxt;
if (res[1].result === "0x") if (res[1].result === "0x")
{ {
errorTxt = qsTr("Error when creating new owned path. Please use the regsitration Dapp. Aborting"); errorTxt = qsTr("Error when creating new owned regsitrar. Please use the regsitration Dapp. Aborting");
deploymentError(errorTxt); deploymentError(errorTxt);
console.log(errorTxt); console.log(errorTxt);
} }
@ -500,7 +501,7 @@ function checkRegistration(dappUrl, addr, callBack)
} }
else else
{ {
var txt = qsTr("Creating sub domain " + dappUrl[0] + " ..."); var txt = qsTr("Registering sub domain " + dappUrl[0] + " ...");
console.log(txt); console.log(txt);
deploymentStepChanged(txt); deploymentStepChanged(txt);
//current registrar is owned => ownedregistrar creation and continue. //current registrar is owned => ownedregistrar creation and continue.
@ -519,12 +520,16 @@ function checkRegistration(dappUrl, addr, callBack)
requests = []; requests = [];
console.log('new created addr ' + newCtrAddress); console.log('new created addr ' + newCtrAddress);
var txt = qsTr("Please wait while " + dappUrl[0] + " is creating ..."); var txt = qsTr("Please wait " + dappUrl[0] + " is registering ...");
deploymentStepChanged(txt); deploymentStepChanged(txt);
console.log(txt); console.log(txt);
deploymentDialog.waitForTrCountToIncrement(function() { deploymentDialog.waitForTrCountToIncrement(function(status) {
if (status === -1)
{
trCountIncrementTimeOut();
return;
}
var crLevel = createString(dappUrl[0]).encodeValueAsString(); var crLevel = createString(dappUrl[0]).encodeValueAsString();
requests.push({ requests.push({
//setRegister() //setRegister()
@ -547,22 +552,11 @@ function checkRegistration(dappUrl, addr, callBack)
}); });
} }
var filterId; function trCountIncrementTimeOut()
function createFilter(callBack)
{ {
var requests = []; var error = qsTr("Something went wrong during the deployment. Please verify the amount of gas for this transaction and check your balance.")
var jsonRpcRequestId = 0; console.log(error);
requests.push({ deploymentError(error);
jsonrpc: "2.0",
method: "eth_newFilterString",
params: [ "pending" ],
id: jsonRpcRequestId++
});
rpcCall(requests, function (httpRequest, response){
console.log(response);
filterId = JSON.parse(response)[0].result;
callBack(filterId);
})
} }
function registerContentHash(registrar, callBack) function registerContentHash(registrar, callBack)

1
mix/qml/js/TransactionHelper.js

@ -27,7 +27,6 @@ function rpcCall(requests, callBack)
var errorText = qsTr("Deployment error: Error while registering Dapp ") + httpRequest.status; var errorText = qsTr("Deployment error: Error while registering Dapp ") + httpRequest.status;
console.log(errorText); console.log(errorText);
deploymentError(errorText); deploymentError(errorText);
return;
} }
callBack(httpRequest.status, httpRequest.responseText) callBack(httpRequest.status, httpRequest.responseText)
} }

Loading…
Cancel
Save