|
|
@ -39,7 +39,11 @@ function closeProject() { |
|
|
|
|
|
|
|
function saveProject() { |
|
|
|
if (!isEmpty) { |
|
|
|
var projectData = { files: [] }; |
|
|
|
var projectData = { |
|
|
|
files: [], |
|
|
|
title: projectTitle, |
|
|
|
deploymentAddress: deploymentAddress |
|
|
|
}; |
|
|
|
for (var i = 0; i < projectListModel.count; i++) |
|
|
|
projectData.files.push(projectListModel.get(i).fileName) |
|
|
|
projectSaving(projectData); |
|
|
@ -60,6 +64,7 @@ function loadProject(path) { |
|
|
|
var parts = path.split("/"); |
|
|
|
projectData.title = parts[parts.length - 2]; |
|
|
|
} |
|
|
|
deploymentAddress = projectData.deploymentAddress ? projectData.deploymentAddress : ""; |
|
|
|
projectTitle = projectData.title; |
|
|
|
projectPath = path; |
|
|
|
if (!projectData.files) |
|
|
@ -246,3 +251,96 @@ function generateFileName(name, extension) { |
|
|
|
return fileName |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var jsonRpcRequestId = 1; |
|
|
|
function deployProject(force) { |
|
|
|
|
|
|
|
saveAll(); //TODO: ask user
|
|
|
|
|
|
|
|
if (!force && deploymentAddress !== "") { |
|
|
|
deployWarningDialog.visible = true; |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
var date = new Date(); |
|
|
|
var deploymentId = date.toLocaleString(Qt.locale(), "ddMMyyHHmmsszzz"); |
|
|
|
var jsonRpcUrl = "http://localhost:8080"; |
|
|
|
console.log("Deploying " + deploymentId + " to " + jsonRpcUrl); |
|
|
|
deploymentStarted(); |
|
|
|
var code = codeModel.codeHex |
|
|
|
var rpcRequest = JSON.stringify({ |
|
|
|
jsonrpc: "2.0", |
|
|
|
method: "eth_transact", |
|
|
|
params: [ { |
|
|
|
"code": code |
|
|
|
} ], |
|
|
|
id: jsonRpcRequestId++ |
|
|
|
}); |
|
|
|
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); |
|
|
|
var address = rpcResponse.result; |
|
|
|
console.log("Created contract, address: " + address); |
|
|
|
finalizeDeployment(deploymentId, address); |
|
|
|
} else { |
|
|
|
var errorText = qsTr("Deployment error: RPC server HTTP status ") + httpRequest.status; |
|
|
|
console.log(errorText); |
|
|
|
deploymentError(errorText); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
httpRequest.send(rpcRequest); |
|
|
|
} |
|
|
|
|
|
|
|
function finalizeDeployment(deploymentId, address) { |
|
|
|
//create a dir for frontend files and copy them
|
|
|
|
var deploymentDir = projectPath + deploymentId + "/"; |
|
|
|
fileIo.makeDir(deploymentDir); |
|
|
|
for (var i = 0; i < projectListModel.count; i++) { |
|
|
|
var doc = projectListModel.get(i); |
|
|
|
if (doc.isContract) |
|
|
|
continue; |
|
|
|
if (doc.isHtml) { |
|
|
|
//inject the script to access contract API
|
|
|
|
//TODO: use a template
|
|
|
|
var html = fileIo.readFile(doc.path); |
|
|
|
var insertAt = html.indexOf("<head>") |
|
|
|
if (insertAt < 0) |
|
|
|
insertAt = 0; |
|
|
|
else |
|
|
|
insertAt += 6; |
|
|
|
html = html.substr(0, insertAt) + |
|
|
|
"<script src=\"bignumber.min.js\"></script>" + |
|
|
|
"<script src=\"ethereum.js\"></script>" + |
|
|
|
"<script src=\"deployment.js\"></script>" + |
|
|
|
html.substr(insertAt); |
|
|
|
fileIo.writeFile(deploymentDir + doc.fileName, html); |
|
|
|
} |
|
|
|
else |
|
|
|
fileIo.copyFile(doc.path, deploymentDir + doc.fileName); |
|
|
|
} |
|
|
|
//write deployment js
|
|
|
|
var deploymentJs = |
|
|
|
"// Autogenerated by Mix\n" + |
|
|
|
"var web3 = require(\"web3\");\n" + |
|
|
|
"var contractInterface = " + codeModel.code.contractInterface + ";\n" + |
|
|
|
"deploy = {\n" + |
|
|
|
"\tweb3: web3,\n" + |
|
|
|
"\tcontractAddress: \"" + address + "\",\n" + |
|
|
|
"\tcontractInterface: contractInterface,\n" + |
|
|
|
"};\n" + |
|
|
|
"deploy.contract = web3.eth.contract(deploy.contractAddress, deploy.contractInterface);\n"; |
|
|
|
fileIo.writeFile(deploymentDir + "deployment.js", deploymentJs); |
|
|
|
//copy scripts
|
|
|
|
fileIo.copyFile("qrc:///js/bignumber.min.js", deploymentDir + "bignumber.min.js"); |
|
|
|
fileIo.copyFile("qrc:///js/webthree.js", deploymentDir + "ethereum.js"); |
|
|
|
deploymentAddress = address; |
|
|
|
saveProject(); |
|
|
|
deploymentComplete(); |
|
|
|
} |
|
|
|