Browse Source

- Account Selection in DeploymentDialog.qml

- Mime type in swarm.json
 - Use of ownedregistrar
cl-refactor
yann300 10 years ago
parent
commit
b10c5daad2
  1. 11
      mix/FileIo.cpp
  2. 2
      mix/FileIo.h
  3. 199
      mix/qml/DeploymentDialog.qml
  4. 18
      mix/qml/ProjectModel.qml
  5. 209
      mix/qml/js/ProjectModel.js
  6. 25
      mix/qml/js/TransactionHelper.js

11
mix/FileIo.cpp

@ -20,6 +20,9 @@
* Ethereum IDE client. * Ethereum IDE client.
*/ */
#include <QDebug>
#include <QDesktopServices>
#include <QMimeDatabase>
#include <QDirIterator> #include <QDirIterator>
#include <QDir> #include <QDir>
#include <QFile> #include <QFile>
@ -37,6 +40,11 @@ using namespace dev;
using namespace dev::crypto; using namespace dev::crypto;
using namespace dev::mix; using namespace dev::mix;
void FileIo::openFileBrowser(QString _dir)
{
QDesktopServices::openUrl(QUrl(_dir));
}
void FileIo::makeDir(QString const& _url) void FileIo::makeDir(QString const& _url)
{ {
QUrl url(_url); QUrl url(_url);
@ -123,6 +131,7 @@ QStringList FileIo::makePackage(QString const& _deploymentFolder)
dev::RLPStream rlpStr; dev::RLPStream rlpStr;
int k = 1; int k = 1;
std::vector<bytes> files; std::vector<bytes> files;
QMimeDatabase mimeDb;
for (auto item: deployDir.entryInfoList(QDir::Files)) for (auto item: deployDir.entryInfoList(QDir::Files))
{ {
QFile qFile(item.filePath()); QFile qFile(item.filePath());
@ -134,7 +143,7 @@ QStringList FileIo::makePackage(QString const& _deploymentFolder)
std::string path = fileInfo.fileName() == "index.html" ? "/" : fileInfo.fileName().toStdString(); std::string path = fileInfo.fileName() == "index.html" ? "/" : fileInfo.fileName().toStdString();
jsonValue["path"] = path; //TODO: Manage relative sub folder jsonValue["path"] = path; //TODO: Manage relative sub folder
jsonValue["file"] = "/" + fileInfo.fileName().toStdString(); jsonValue["file"] = "/" + fileInfo.fileName().toStdString();
jsonValue["contentType"] = "text/html"; //TODO: manage multiple content type jsonValue["contentType"] = mimeDb.mimeTypeForFile(qFile.fileName()).name().toStdString();
QByteArray a = qFile.readAll(); QByteArray a = qFile.readAll();
bytes data = bytes(a.begin(), a.end()); bytes data = bytes(a.begin(), a.end());
files.push_back(data); files.push_back(data);

2
mix/FileIo.h

@ -55,6 +55,8 @@ public:
Q_INVOKABLE bool fileExists(QString const& _url); Q_INVOKABLE bool fileExists(QString const& _url);
/// Compress a folder, @returns sha3 of the compressed file. /// Compress a folder, @returns sha3 of the compressed file.
Q_INVOKABLE QStringList makePackage(QString const& _deploymentFolder); Q_INVOKABLE QStringList makePackage(QString const& _deploymentFolder);
/// Open a file browser
Q_INVOKABLE void openFileBrowser(QString _dir);
private: private:
QString getHomePath() const; QString getHomePath() const;

199
mix/qml/DeploymentDialog.qml

@ -12,9 +12,10 @@ import "."
Window { Window {
id: modalDeploymentDialog id: modalDeploymentDialog
modality: Qt.ApplicationModal modality: Qt.ApplicationModal
width: 600 width: 800
height: 350 height: 350
visible: false visible: false
property alias applicationUrlEth: applicationUrlEth.text property alias applicationUrlEth: applicationUrlEth.text
@ -22,8 +23,9 @@ Window {
property string urlHintContract: "c83d3e22645fb015d02043a744921cc2f828c64d" property string urlHintContract: "c83d3e22645fb015d02043a744921cc2f828c64d"
property string packageHash property string packageHash
property alias packageBase64: base64Value.text property alias packageBase64: base64Value.text
property string eth: "afb7cdbd076674fd2c67f8a66518e3145b184ae4"; property string eth: "4c3f7330690ed3657d3fa20fe5717b84010528ae";
property string wallet: "c83d3e22645fb015d02043a744921cc2f828c64d"; property string yanndappRegistrar: "29a2e6d3c56ef7713a4e7229c3d1a23406f0161a";
property string currentAccount
color: Style.generic.layout.backgroundColor color: Style.generic.layout.backgroundColor
@ -34,6 +36,23 @@ Window {
function open() function open()
{ {
var requests = [];
requests.push({
//accounts
jsonrpc: "2.0",
method: "eth_accounts",
params: null,
id: 0
});
TransactionHelper.rpcCall(requests, function(arg1, arg2)
{
modelAccounts.clear();
modelAccounts.append({ "id": JSON.parse(arg2)[0].result[0] })
modelAccounts.append({ "id": JSON.parse(arg2)[0].result[1] })
currentAccount = modelAccounts.get(0).id;
});
modalDeploymentDialog.setX((Screen.width - width) / 2); modalDeploymentDialog.setX((Screen.width - width) / 2);
modalDeploymentDialog.setY((Screen.height - height) / 2); modalDeploymentDialog.setY((Screen.height - height) / 2);
visible = true; visible = true;
@ -49,6 +68,46 @@ Window {
return h; return h;
} }
function waitForTrCountToIncrement(callBack)
{
poolLog.callBack = callBack;
poolLog.k = 0;
poolLog.start();
}
Timer
{
id: poolLog
property var callBack
property var k: -1
interval: 500
running: false
repeat: true
onTriggered: {
var requests = [];
var jsonRpcRequestId = 0;
requests.push({
jsonrpc: "2.0",
method: "eth_countAt",
params: [ currentAccount ],
id: jsonRpcRequestId++
});
TransactionHelper.rpcCall(requests, function (httpRequest, response){
console.log(response);
response = response.replace(/,0+/, '');
console.log(response);
var count = JSON.parse(response)[0].result
if (k < parseInt(count) && k > 0)
{
stop();
callBack();
}
else
k = parseInt(JSON.parse(response)[0].result);
})
}
}
Rectangle Rectangle
{ {
anchors.fill : parent anchors.fill : parent
@ -60,6 +119,22 @@ Window {
anchors.top: parent.top anchors.top: parent.top
anchors.left: parent.left anchors.left: parent.left
width: parent.width width: parent.width
DefaultLabel
{
text: qsTr("Account used to deploy:")
}
ComboBox {
id: comboAccounts
onCurrentIndexChanged : {
if (modelAccounts.count > 0)
currentAccount = modelAccounts.get(currentIndex).id;
}
model: ListModel {
id: modelAccounts
}
}
DefaultLabel DefaultLabel
{ {
text: qsTr("Ethereum Application URL: ") text: qsTr("Ethereum Application URL: ")
@ -95,6 +170,20 @@ 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 {
@ -109,13 +198,22 @@ Window {
anchors.right: parent.right; anchors.right: parent.right;
anchors.bottomMargin: 10 anchors.bottomMargin: 10
Button { Button {
text: qsTr("Deploy to Ethereum"); text: qsTr("Deploy contract / Package resources");
tooltip: qsTr("Deploy contract and package resources files.") tooltip: qsTr("Deploy contract and package resources files.")
onClicked: { onClicked: {
deployWarningDialog.open(); deployWarningDialog.open();
} }
} }
Button {
text: qsTr("Package resources only");
tooltip: qsTr("Package resources files.")
enabled: Object.keys(projectModel.deploymentAddresses).length > 0
onClicked: {
ProjectModelCode.startDeployProject(false);
}
}
Button { Button {
text: qsTr("Register Web Application"); text: qsTr("Register Web Application");
tooltip: qsTr("Register hosted Web Application.") tooltip: qsTr("Register hosted Web Application.")
@ -137,28 +235,43 @@ Window {
} }
Button { Button {
text: qsTr("Check Ownership"); text: qsTr("Checking eth/yanndapp");
visible : false visible : false
onClicked: { onClicked: {
var requests = []; var requests = [];
var ethStr = QEtherHelper.createString("wallet"); var ethStr = QEtherHelper.createString("yanndapp");
var ethHash = QEtherHelper.createHash(eth);
requests.push({ //owner requests.push({ //owner
jsonrpc: "2.0", jsonrpc: "2.0",
method: "eth_call", method: "eth_call",
params: [ { "to": '0x' + modalDeploymentDialog.eth, "data": "0xec7b9200" + ethStr.encodeValueAsString() } ], params: [ { "to": '0x' + modalDeploymentDialog.eth, "data": "0xec7b9200" + ethStr.encodeValueAsString() } ], //check for yanndappRegistrar in eth
id: 3 id: 1
}); });
requests.push({ //register requests.push({ //register
jsonrpc: "2.0", jsonrpc: "2.0",
method: "eth_call", method: "eth_call",
params: [ { "to": '0x' + modalDeploymentDialog.eth, "data": "0x6be16bed" + ethStr.encodeValueAsString() } ], params: [ { "to": '0x' + modalDeploymentDialog.eth, "data": "0x6be16bed" + ethStr.encodeValueAsString() } ], //getregister yanndappRegistrar in eth
id: 4 id: 2
});
requests.push({ //getOwner
jsonrpc: "2.0",
method: "eth_call",
params: [ { "to": '0x' + modalDeploymentDialog.yanndappRegistrar, "data": "0x893d20e8" } ], //check owner of this registrar
id: 3
}); });
/*requests.push({ //register
jsonrpc: "2.0",
method: "eth_call",
params: [ { "to": '0x' + modalDeploymentDialog.yanndappRegistrar, "data": "0x6be16bed" + ethStr.encodeValueAsString() } ],
id: 2
});*/
var jsonRpcUrl = "http://localhost:8080"; var jsonRpcUrl = "http://localhost:8080";
var rpcRequest = JSON.stringify(requests); var rpcRequest = JSON.stringify(requests);
var httpRequest = new XMLHttpRequest(); var httpRequest = new XMLHttpRequest();
@ -180,30 +293,76 @@ Window {
} }
} }
Button { Button {
text: qsTr("Generate registrar init"); text: qsTr("add contracts");
visible: false visible : false
onClicked: { onClicked: {
console.log("registering eth/wallet")
var jsonRpcRequestId = 0; var jsonRpcRequestId = 0;
var requests = [];
requests.push({
jsonrpc: "2.0",
method: "eth_transact",
params: [ { "gas": 20000, "code": "0x60056011565b600180601c6000396000f35b6008600081905550560000" } ],
id: jsonRpcRequestId++
});
var jsonRpcUrl = "http://localhost:8080";
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) {
console.log(httpRequest.responseText);
var requests = []; var requests = [];
var walletStr = QEtherHelper.createString("wallet"); requests.push({
jsonrpc: "2.0",
method: "eth_transact",
params: [ { "gas": 20000, "code": "0x60056011565b600180601c6000396000f35b6009600081905550560000" } ],
id: jsonRpcRequestId++
});
rpcRequest = JSON.stringify(requests);
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) {
console.log(httpRequest.responseText);
}
}
httpRequest.send(rpcRequest);
}
}
httpRequest.send(rpcRequest);
}
}
Button {
text: qsTr("Registering eth/yanndapp");
visible: false
onClicked: {
console.log("registering eth/yanndapp")
var jsonRpcRequestId = 0;
var requests = [];
var ydapp = QEtherHelper.createString("yanndapp");
requests.push({ //reserve requests.push({ //reserve
jsonrpc: "2.0", jsonrpc: "2.0",
method: "eth_transact", method: "eth_transact",
params: [ { "to": '0x' + modalDeploymentDialog.eth, "data": "0x1c83171b" + walletStr.encodeValueAsString() } ], params: [ { "gas": 2000, "to": '0x' + modalDeploymentDialog.eth, "data": "0x1c83171b" + ydapp.encodeValueAsString() } ],
id: jsonRpcRequestId++ id: jsonRpcRequestId++
}); });
requests.push({ //setRegister requests.push({ //setRegister
jsonrpc: "2.0", jsonrpc: "2.0",
method: "eth_transact", method: "eth_transact",
params: [ { "to": '0x' + modalDeploymentDialog.eth, "data": "0x96077307" + walletStr.encodeValueAsString() + pad(wallet) } ], params: [ { "gas": 2000, "to": '0x' + modalDeploymentDialog.eth, "data": "0x96077307" + ydapp.encodeValueAsString() + modalDeploymentDialog.pad(modalDeploymentDialog.yanndappRegistrar) } ],
id: jsonRpcRequestId++ id: jsonRpcRequestId++
}); });

18
mix/qml/ProjectModel.qml

@ -7,6 +7,7 @@ import Qt.labs.settings 1.0
import "js/ProjectModel.js" as ProjectModelCode import "js/ProjectModel.js" as ProjectModelCode
Item { Item {
id: projectModel id: projectModel
signal projectClosed signal projectClosed
@ -33,6 +34,7 @@ Item {
property string projectTitle: "" property string projectTitle: ""
property string currentDocumentId: "" property string currentDocumentId: ""
property var deploymentAddresses: [] property var deploymentAddresses: []
property string deploymentDir
property var listModel: projectListModel property var listModel: projectListModel
property var stateListModel: projectStateListModel.model property var stateListModel: projectStateListModel.model
property CodeEditorView codeEditor: null property CodeEditorView codeEditor: null
@ -93,28 +95,17 @@ Item {
MessageDialog { MessageDialog {
id: deployWarningDialog id: deployWarningDialog
property bool redeploy
title: qsTr("Project") title: qsTr("Project")
text: text:
{ {
if (Object.keys(projectModel.deploymentAddresses).length > 0) if (Object.keys(projectModel.deploymentAddresses).length > 0)
{ return qsTr("This project has been already deployed to the network. Do you want to redeploy it? (Contract state will be reseted)")
redeploy = true
standardButtons = StandardButton.Ok | StandardButton.Reset | StandardButton.Abort;
return qsTr("This project has been already deployed to the network. Do you want to repackage the resources only, or also reset the deployed contract to its initial state?")
}
else else
{
redeploy = false;
standardButtons = StandardButton.Ok | StandardButton.Abort;
return qsTr("This action will deploy to the network. Do you want to deploy it?") return qsTr("This action will deploy to the network. Do you want to deploy it?")
} }
}
icon: StandardIcon.Question icon: StandardIcon.Question
standardButtons: StandardButton.Ok | StandardButton.Abort
onAccepted: { onAccepted: {
ProjectModelCode.startDeployProject(!redeploy);
}
onReset: {
ProjectModelCode.startDeployProject(true); ProjectModelCode.startDeployProject(true);
} }
} }
@ -123,7 +114,6 @@ Item {
id: deployRessourcesDialog id: deployRessourcesDialog
title: qsTr("Project") title: qsTr("Project")
standardButtons: StandardButton.Ok standardButtons: StandardButton.Ok
icon: StandardIcon.Info
} }
DeploymentDialog DeploymentDialog

209
mix/qml/js/ProjectModel.js

@ -20,6 +20,7 @@
* Ethereum IDE client. * Ethereum IDE client.
*/ */
Qt.include("QEtherHelper.js") Qt.include("QEtherHelper.js")
Qt.include("TransactionHelper.js")
var htmlTemplate = "<html>\n<head>\n<script>\n</script>\n</head>\n<body>\n<script>\n</script>\n</body>\n</html>"; var htmlTemplate = "<html>\n<head>\n<script>\n</script>\n</head>\n<body>\n<script>\n</script>\n</body>\n</html>";
var contractTemplate = "contract Contract {\n}\n"; var contractTemplate = "contract Contract {\n}\n";
@ -50,7 +51,8 @@ function saveProject() {
applicationUrlEth: deploymentDialog.applicationUrlEth, applicationUrlEth: deploymentDialog.applicationUrlEth,
applicationUrlHttp: deploymentDialog.applicationUrlHttp, applicationUrlHttp: deploymentDialog.applicationUrlHttp,
packageHash: deploymentDialog.packageHash, packageHash: deploymentDialog.packageHash,
packageBase64: deploymentDialog.packageBase64 packageBase64: deploymentDialog.packageBase64,
deploymentDir: projectModel.deploymentDir
}; };
for (var i = 0; i < projectListModel.count; i++) for (var i = 0; i < projectListModel.count; i++)
projectData.files.push(projectListModel.get(i).fileName) projectData.files.push(projectListModel.get(i).fileName)
@ -68,6 +70,8 @@ function loadProject(path) {
var projectFile = path + projectFileName; var projectFile = path + projectFileName;
var json = fileIo.readFile(projectFile); var json = fileIo.readFile(projectFile);
var projectData = JSON.parse(json); var projectData = JSON.parse(json);
if (projectData.deploymentDir)
projectModel.deploymentDir = projectData.deploymentDir
if (projectData.packageHash) if (projectData.packageHash)
deploymentDialog.packageHash = projectData.packageHash deploymentDialog.packageHash = projectData.packageHash
if (projectData.packageBase64) if (projectData.packageBase64)
@ -289,6 +293,7 @@ function deployProject(force) {
deploymentDialog.open(); deploymentDialog.open();
} }
var codeTest = "";
function startDeployProject(erasePrevious) function startDeployProject(erasePrevious)
{ {
var date = new Date(); var date = new Date();
@ -311,10 +316,11 @@ function startDeployProject(erasePrevious)
requests.push({ requests.push({
jsonrpc: "2.0", jsonrpc: "2.0",
method: "eth_transact", method: "eth_transact",
params: [ { "code": code } ], params: [ { "from": deploymentDialog.currentAccount, "gas": 20000, "code": code /* "0x60056013565b61059e8061001d6000396000f35b33600081905550560060003560e060020a90048063019848921461009a578063449c2090146100af5780635d574e32146100cd5780635fd4b08a146100e1578063618242da146100f65780636be16bed1461010b5780636c4489b414610129578063893d20e8146101585780639607730714610173578063c284bc2a14610187578063e50f599a14610198578063e5811b35146101af578063ec7b9200146101cd57005b6100a560043561031b565b8060005260206000f35b6100ba6004356103a0565b80600160a060020a031660005260206000f35b6100db600435602435610537565b60006000f35b6100ec600435610529565b8060005260206000f35b6101016004356103dd565b8060005260206000f35b6101166004356103bd565b80600160a060020a031660005260206000f35b61013460043561034b565b82600160a060020a031660005281600160a060020a03166020528060405260606000f35b610160610341565b80600160a060020a031660005260206000f35b6101816004356024356102b4565b60006000f35b6101926004356103fd565b60006000f35b6101a96004356024356044356101f2565b60006000f35b6101ba6004356101eb565b80600160a060020a031660005260206000f35b6101d8600435610530565b80600160a060020a031660005260206000f35b6000919050565b600054600160a060020a031633600160a060020a031614610212576102af565b8160026000858152602001908152602001600020819055508061023457610287565b81600160a060020a0316837f680ad70765443c2967675ab0fb91a46350c01c6df59bf9a41ff8a8dd097464ec60006000a3826001600084600160a060020a03168152602001908152602001600020819055505b827f18d67da0cd86808336a3aa8912f6ea70c5250f1a98b586d1017ef56fe199d4fc60006000a25b505050565b600054600160a060020a031633600160a060020a0316146102d457610317565b806002600084815260200190815260200160002060010181905550817f18d67da0cd86808336a3aa8912f6ea70c5250f1a98b586d1017ef56fe199d4fc60006000a25b5050565b60006001600083600160a060020a03168152602001908152602001600020549050919050565b6000600054905090565b6000600060006002600085815260200190815260200160002054925060026000858152602001908152602001600020600101549150600260008581526020019081526020016000206002015490509193909250565b600060026000838152602001908152602001600020549050919050565b600060026000838152602001908152602001600020600101549050919050565b600060026000838152602001908152602001600020600201549050919050565b600054600160a060020a031633600160a060020a03161461041d57610526565b80600160006002600085815260200190815260200160002054600160a060020a031681526020019081526020016000205414610458576104d2565b6002600082815260200190815260200160002054600160a060020a0316817f680ad70765443c2967675ab0fb91a46350c01c6df59bf9a41ff8a8dd097464ec60006000a36000600160006002600085815260200190815260200160002054600160a060020a03168152602001908152602001600020819055505b6002600082815260200190815260200160002060008101600090556001810160009055600281016000905550807f18d67da0cd86808336a3aa8912f6ea70c5250f1a98b586d1017ef56fe199d4fc60006000a25b50565b6000919050565b6000919050565b600054600160a060020a031633600160a060020a0316146105575761059a565b806002600084815260200190815260200160002060020181905550817f18d67da0cd86808336a3aa8912f6ea70c5250f1a98b586d1017ef56fe199d4fc60006000a25b505056" */ } ],
id: jsonRpcRequestId++ id: jsonRpcRequestId++
}); });
requestNames.push(c); requestNames.push(c);
codeTest = code;
} }
var rpcRequest = JSON.stringify(requests); var rpcRequest = JSON.stringify(requests);
@ -327,11 +333,18 @@ function startDeployProject(erasePrevious)
if (httpRequest.readyState === XMLHttpRequest.DONE) { if (httpRequest.readyState === XMLHttpRequest.DONE) {
if (httpRequest.status === 200) { if (httpRequest.status === 200) {
var rpcResponse = JSON.parse(httpRequest.responseText); var rpcResponse = JSON.parse(httpRequest.responseText);
console.log("crea" + httpRequest.responseText);
if (rpcResponse.length === requestNames.length) { if (rpcResponse.length === requestNames.length) {
var contractAddresses = {}; var contractAddresses = {};
for (var r = 0; r < rpcResponse.length; r++) for (var r = 0; r < rpcResponse.length; r++)
contractAddresses[requestNames[r]] = rpcResponse[r].result; contractAddresses[requestNames[r]] = rpcResponse[r].result;
var txt = qsTr("Please wait while the contract is published ...")
deploymentStepChanged(txt);
console.log(txt);
deploymentDialog.waitForTrCountToIncrement(function() {
finalizeDeployment(deploymentId, contractAddresses); finalizeDeployment(deploymentId, contractAddresses);
});
} }
} else { } else {
var errorText = qsTr("Deployment error: RPC server HTTP status ") + httpRequest.status; var errorText = qsTr("Deployment error: RPC server HTTP status ") + httpRequest.status;
@ -346,6 +359,7 @@ function startDeployProject(erasePrevious)
function finalizeDeployment(deploymentId, addresses) { function finalizeDeployment(deploymentId, addresses) {
deploymentStepChanged(qsTr("Packaging application ...")); deploymentStepChanged(qsTr("Packaging application ..."));
var deploymentDir = projectPath + deploymentId + "/"; var deploymentDir = projectPath + deploymentId + "/";
projectModel.deploymentDir = deploymentDir;
fileIo.makeDir(deploymentDir); fileIo.makeDir(deploymentDir);
for (var i = 0; i < projectListModel.count; i++) { for (var i = 0; i < projectListModel.count; i++) {
var doc = projectListModel.get(i); var doc = projectListModel.get(i);
@ -398,135 +412,181 @@ function finalizeDeployment(deploymentId, addresses) {
applicationUrlEth = formatAppUrl(applicationUrlEth); applicationUrlEth = formatAppUrl(applicationUrlEth);
deploymentStepChanged(qsTr("Registering application on the Ethereum network ...")); deploymentStepChanged(qsTr("Registering application on the Ethereum network ..."));
checkRegistration(applicationUrlEth, deploymentDialog.eth, function () { applicationUrlEth.splice(0, 1); //Remove eth (already exists).
applicationUrlEth.push(projectModel.projectTitle);
checkEthPath(applicationUrlEth, function () {
deploymentComplete(); deploymentComplete();
deployRessourcesDialog.text = qsTr("Register Web Application to finalize deployment."); deployRessourcesDialog.text = qsTr("Register Web Application to finalize deployment.");
deployRessourcesDialog.open(); deployRessourcesDialog.open();
}); });
} }
function rpcCall(requests, callBack) function checkEthPath(dappUrl, callBack)
{ {
var jsonRpcUrl = "http://localhost:8080"; var str = createString(dappUrl[0]);
var rpcRequest = JSON.stringify(requests); var requests = [];
var httpRequest = new XMLHttpRequest(); console.log(" ggg " + deploymentDialog.currentAccount);
httpRequest.open("POST", jsonRpcUrl, true); console.log(" ggg " + deploymentDialog.eth);
httpRequest.setRequestHeader("Content-type", "application/json"); requests.push({
httpRequest.setRequestHeader("Content-length", rpcRequest.length); //register()
httpRequest.setRequestHeader("Connection", "close"); jsonrpc: "2.0",
httpRequest.onreadystatechange = function() { method: "eth_call",
if (httpRequest.readyState === XMLHttpRequest.DONE) { params: [ { "from": deploymentDialog.currentAccount, "to": '0x' + deploymentDialog.eth, "data": "0x6be16bed" + str.encodeValueAsString() } ],
if (httpRequest.status !== 200) id: jsonRpcRequestId++
});
rpcCall(requests, function (httpRequest, response) {
console.log("checking in path eth: found " + response);
var res = JSON.parse(response);
var addr = normalizeAddress(res[0].result);
if (addr === "")
{ {
var errorText = qsTr("Deployment error: Error while registering Dapp ") + httpRequest.status; var errorTxt = qsTr("Path does not exists " + JSON.stringify(dappUrl) + ". Please register using Registration Dapp. Aborting.");
console.log(errorText); deploymentError(errorTxt);
deploymentError(errorText); console.log(errorTxt);
return;
}
callBack(httpRequest.status, httpRequest.responseText)
} }
else
{
dappUrl.splice(0, 1);
checkRegistration(dappUrl, addr, callBack);
} }
httpRequest.send(rpcRequest); });
} }
function checkRegistration(dappUrl, addr, callBack) function checkRegistration(dappUrl, addr, callBack)
{ {
var txt = qsTr("Checking " + JSON.stringify(dappUrl) + " ... in registrar " + addr);
deploymentStepChanged(txt);
console.log(txt);
var requests = []; var requests = [];
var data = ""; var registrar = {}
if (dappUrl.length > 0)
{
//checking path (register).
var str = createString(dappUrl[0]); var str = createString(dappUrl[0]);
data = "0x6be16bed" + str.encodeValueAsString();
console.log("checking if path exists (register) => " + JSON.stringify(dappUrl));
requests.push({ requests.push({
//getOwner()
jsonrpc: "2.0", jsonrpc: "2.0",
method: "eth_call", method: "eth_call",
params: [ { "to": '0x' + addr, "data": data } ], params: [ { "from": deploymentDialog.currentAccount, "to": '0x' + addr, "data": "0x893d20e8" } ],
id: jsonRpcRequestId++
});
requests.push({
//register()
jsonrpc: "2.0",
method: "eth_call",
params: [ { "from": deploymentDialog.currentAccount, "to": '0x' + addr, "data": "0x6be16bed" + str.encodeValueAsString() } ],
id: jsonRpcRequestId++ id: jsonRpcRequestId++
}); });
rpcCall(requests, function (httpRequest, response) { rpcCall(requests, function (httpRequest, response) {
var address = JSON.parse(response)[0].result.replace('0x', ''); console.log(" >> " +response);
if (address === "") var res = JSON.parse(response);
var nextAddr = normalizeAddress(res[1].result);
var errorTxt;
if (res[1].result === "0x")
{ {
var errorTxt = qsTr("Path does not exists " + JSON.stringify(dappUrl) + " cannot continue"); errorTxt = qsTr("Error when creating new owned path. Please use the regsitration Dapp. Aborting");
deploymentError(errorTxt); deploymentError(errorTxt);
console.log(errorTxt); console.log(errorTxt);
return;
} }
else if (normalizeAddress(deploymentDialog.currentAccount) !== normalizeAddress(res[0].result))
{
errorTxt = qsTr("You are not the owner of " + dappUrl[0] + ". Aborting");
deploymentError(errorTxt);
console.log(errorTxt);
}
else if (nextAddr !== "")
{
dappUrl.splice(0, 1); dappUrl.splice(0, 1);
checkRegistration(dappUrl, address, callBack); if (dappUrl.length > 0)
}); checkRegistration(dappUrl, nextAddr, callBack);
else
registerContentHash(addr, callBack);
} }
else else
{ {
var paramTitle = createString(projectModel.projectTitle); var txt = qsTr("Creating sub domain " + dappUrl[0] + " ...");
requests.push({ console.log(txt);
//owner() deploymentStepChanged(txt);
jsonrpc: "2.0", //current registrar is owned => ownedregistrar creation and continue.
method: "eth_call", requests = [];
params: [ { "to": '0x' + addr, "data": "0xec7b9200" + paramTitle.encodeValueAsString() } ],
id: jsonRpcRequestId++
});
requests.push({ requests.push({
//accounts
jsonrpc: "2.0", jsonrpc: "2.0",
method: "eth_accounts", method: "eth_transact",
params: null, params: [ { "from": deploymentDialog.currentAccount, "gas": 20000, "code": "0x60056013565b61059e8061001d6000396000f35b33600081905550560060003560e060020a90048063019848921461009a578063449c2090146100af5780635d574e32146100cd5780635fd4b08a146100e1578063618242da146100f65780636be16bed1461010b5780636c4489b414610129578063893d20e8146101585780639607730714610173578063c284bc2a14610187578063e50f599a14610198578063e5811b35146101af578063ec7b9200146101cd57005b6100a560043561031b565b8060005260206000f35b6100ba6004356103a0565b80600160a060020a031660005260206000f35b6100db600435602435610537565b60006000f35b6100ec600435610529565b8060005260206000f35b6101016004356103dd565b8060005260206000f35b6101166004356103bd565b80600160a060020a031660005260206000f35b61013460043561034b565b82600160a060020a031660005281600160a060020a03166020528060405260606000f35b610160610341565b80600160a060020a031660005260206000f35b6101816004356024356102b4565b60006000f35b6101926004356103fd565b60006000f35b6101a96004356024356044356101f2565b60006000f35b6101ba6004356101eb565b80600160a060020a031660005260206000f35b6101d8600435610530565b80600160a060020a031660005260206000f35b6000919050565b600054600160a060020a031633600160a060020a031614610212576102af565b8160026000858152602001908152602001600020819055508061023457610287565b81600160a060020a0316837f680ad70765443c2967675ab0fb91a46350c01c6df59bf9a41ff8a8dd097464ec60006000a3826001600084600160a060020a03168152602001908152602001600020819055505b827f18d67da0cd86808336a3aa8912f6ea70c5250f1a98b586d1017ef56fe199d4fc60006000a25b505050565b600054600160a060020a031633600160a060020a0316146102d457610317565b806002600084815260200190815260200160002060010181905550817f18d67da0cd86808336a3aa8912f6ea70c5250f1a98b586d1017ef56fe199d4fc60006000a25b5050565b60006001600083600160a060020a03168152602001908152602001600020549050919050565b6000600054905090565b6000600060006002600085815260200190815260200160002054925060026000858152602001908152602001600020600101549150600260008581526020019081526020016000206002015490509193909250565b600060026000838152602001908152602001600020549050919050565b600060026000838152602001908152602001600020600101549050919050565b600060026000838152602001908152602001600020600201549050919050565b600054600160a060020a031633600160a060020a03161461041d57610526565b80600160006002600085815260200190815260200160002054600160a060020a031681526020019081526020016000205414610458576104d2565b6002600082815260200190815260200160002054600160a060020a0316817f680ad70765443c2967675ab0fb91a46350c01c6df59bf9a41ff8a8dd097464ec60006000a36000600160006002600085815260200190815260200160002054600160a060020a03168152602001908152602001600020819055505b6002600082815260200190815260200160002060008101600090556001810160009055600281016000905550807f18d67da0cd86808336a3aa8912f6ea70c5250f1a98b586d1017ef56fe199d4fc60006000a25b50565b6000919050565b6000919050565b600054600160a060020a031633600160a060020a0316146105575761059a565b806002600084815260200190815260200160002060020181905550817f18d67da0cd86808336a3aa8912f6ea70c5250f1a98b586d1017ef56fe199d4fc60006000a25b505056" } ],
id: jsonRpcRequestId++ id: jsonRpcRequestId++
}); });
rpcCall(requests, function (httpRequest, response) { rpcCall(requests, function(httpRequest, response) {
console.log("crea2" + response);
var newCtrAddress = normalizeAddress(JSON.parse(response)[0].result);
requests = []; requests = [];
var res = JSON.parse(response); console.log('new created addr ' + newCtrAddress);
var currentOwner = res[0].result;
var noOwner = currentOwner.replace('0x', '').replace(/0/g, '') === '';
if (noOwner) var txt = qsTr("Please wait while " + dappUrl[0] + " is creating ...");
{ deploymentStepChanged(txt);
console.log(txt);
deploymentDialog.waitForTrCountToIncrement(function() {
var crLevel = createString(dappUrl[0]).encodeValueAsString();
console.log("registering " + dappUrl[0]);
requests.push({ requests.push({
//reserve() //setRegister()
jsonrpc: "2.0", jsonrpc: "2.0",
method: "eth_transact", method: "eth_transact",
params: [ { "to": '0x' + addr, "data": "0x1c83171b" + paramTitle.encodeValueAsString() } ], params: [ { "from": deploymentDialog.currentAccount, "gas": 2000, "to": '0x' + addr, "data": "0x96077307" + crLevel + deploymentDialog.pad(newCtrAddress) } ],
id: jsonRpcRequestId++ id: jsonRpcRequestId++
}); });
}
rpcCall(requests, function(){
dappUrl.splice(0, 1);
if (dappUrl.length > 0)
checkRegistration(dappUrl, newCtrAddress, callBack);
else else
{ registerContentHash(addr, callBack);
var bOwner = false; });
currentOwner = normalizeAddress(currentOwner); });
for (var u in res[1].result) });
{
if (normalizeAddress(res[1].result[u]) === currentOwner)
bOwner = true;
} }
});
}
if (!bOwner) var filterId;
{ function createFilter(callBack)
var errorTxt = qsTr("Current user is not the owner of this path. Cannot continue") {
deploymentError(errorTxt); var requests = [];
console.log(errorTxt); var jsonRpcRequestId = 0;
return; requests.push({
} jsonrpc: "2.0",
} method: "eth_newFilterString",
console.log("setContentHash"); params: [ "pending" ],
id: jsonRpcRequestId++
});
rpcCall(requests, function (httpRequest, response){
console.log(response);
filterId = JSON.parse(response)[0].result;
callBack(filterId);
})
}
function registerContentHash(registrar, callBack)
{
var txt = qsTr("Finalizing Dapp registration ...");
deploymentStepChanged(txt);
console.log(txt);
var requests = [];
var paramTitle = createString(projectModel.projectTitle);
requests.push({ requests.push({
//setContent() //setContent()
jsonrpc: "2.0", jsonrpc: "2.0",
method: "eth_transact", method: "eth_transact",
params: [ { "to": '0x' + addr, "data": "0x5d574e32" + paramTitle.encodeValueAsString() + deploymentDialog.packageHash } ], params: [ { "from": deploymentDialog.currentAccount, "gas": "2000", "gasPrice": "10", "to": '0x' + registrar, "data": "0x5d574e32" + paramTitle.encodeValueAsString() + deploymentDialog.packageHash } ],
id: jsonRpcRequestId++ id: jsonRpcRequestId++
}); });
rpcCall(requests, function (httpRequest, response) { rpcCall(requests, function (httpRequest, response) {
callBack(); callBack();
}); });
});
}
} }
function registerToUrlHint() function registerToUrlHint()
@ -586,4 +646,3 @@ function formatAppUrl(url)
return ret; return ret;
} }
} }

25
mix/qml/js/TransactionHelper.js

@ -10,3 +10,28 @@ function defaultTransaction()
parameters: {} parameters: {}
}; };
} }
function rpcCall(requests, callBack)
{
var jsonRpcUrl = "http://localhost:8080";
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 errorText = qsTr("Deployment error: Error while registering Dapp ") + httpRequest.status;
console.log(errorText);
deploymentError(errorText);
return;
}
callBack(httpRequest.status, httpRequest.responseText)
}
}
httpRequest.send(rpcRequest);
}

Loading…
Cancel
Save