From cd70218cd1801a3fe990651efc7cd8ed903b681b Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 27 Apr 2015 15:06:21 +0200 Subject: [PATCH] Deploy To Network: users choose which state to use for deploying --- mix/ClientModel.cpp | 33 ++ mix/ClientModel.h | 6 + mix/CodeModel.h | 2 +- mix/ContractCallDataEncoder.cpp | 12 +- mix/ContractCallDataEncoder.h | 2 + mix/qml/DeploymentDialog.qml | 26 +- mix/qml/ProjectModel.qml | 1 + mix/qml/StateListModel.qml | 2 +- mix/qml/js/NetworkDeployment.js | 159 +++++++-- test/webthreestubclient.h | 596 ++++++++++++++++++++++++++++++++ 10 files changed, 794 insertions(+), 45 deletions(-) create mode 100644 test/webthreestubclient.h diff --git a/mix/ClientModel.cpp b/mix/ClientModel.cpp index c0ce36ab5..d305287ee 100644 --- a/mix/ClientModel.cpp +++ b/mix/ClientModel.cpp @@ -151,6 +151,39 @@ QString ClientModel::encodeAbiString(QString _string) return QString::fromStdString(toHex(encoder.encodeBytes(_string))); } +QString ClientModel::encodeString(QString const& _param) +{ + ContractCallDataEncoder encoder; + return QString::fromStdString(toHex(encoder.encodeBytesParam(_param, 32))); +} + +QStringList ClientModel::encodeParams(QVariant const& _param, QString const& _contract, QString const& _function) +{ + QStringList ret; + CompiledContract const& compilerRes = m_codeModel->contract(_contract); + QList paramsList; + shared_ptr contractDef = compilerRes.sharedContract(); + if (_contract == _function) + paramsList = contractDef->constructor()->parametersList(); + else + for (QFunctionDefinition* tf: contractDef->functionsList()) + if (tf->name() == _function) + { + paramsList = tf->parametersList(); + break; + } + if (paramsList.length() > 0) + for (QVariableDeclaration* var: paramsList) + { + ContractCallDataEncoder encoder; + QSolidityType const* type = var->type(); + QVariant value = _param.toMap().value(var->name()); + encoder.encode(value, type->type()); + ret.push_back(QString::fromStdString(toHex(encoder.encodedData()))); + } + return ret; +} + QVariantMap ClientModel::contractAddresses() const { QVariantMap res; diff --git a/mix/ClientModel.h b/mix/ClientModel.h index dcb62f55d..78bd60598 100644 --- a/mix/ClientModel.h +++ b/mix/ClientModel.h @@ -26,8 +26,10 @@ #include #include #include +#include #include #include +#include #include "MachineStates.h" namespace dev @@ -153,6 +155,10 @@ public: Q_INVOKABLE void mine(); /// Get/set code model. Should be set from qml Q_PROPERTY(CodeModel* codeModel MEMBER m_codeModel) + /// Encode parameters + Q_INVOKABLE QStringList encodeParams(QVariant const& _param, QString const& _contract, QString const& _function); + /// Encode parameter + Q_INVOKABLE QString encodeString(QString const& _param); public slots: /// Setup state, run transaction sequence, show debugger for the last transaction diff --git a/mix/CodeModel.h b/mix/CodeModel.h index 6fb914118..b9a6f041d 100644 --- a/mix/CodeModel.h +++ b/mix/CodeModel.h @@ -145,7 +145,7 @@ public: CompiledContract const& contract(QString const& _name) const; /// Get contract by name /// @returns nullptr if not found - CompiledContract const* tryGetContract(QString const& _name) const; + Q_INVOKABLE CompiledContract const* tryGetContract(QString const& _name) const; /// Find a contract by document id /// @returns CompiledContract object or null if not found Q_INVOKABLE CompiledContract* contractByDocumentId(QString const& _documentId) const; diff --git a/mix/ContractCallDataEncoder.cpp b/mix/ContractCallDataEncoder.cpp index c561c0017..36089dcae 100644 --- a/mix/ContractCallDataEncoder.cpp +++ b/mix/ContractCallDataEncoder.cpp @@ -121,9 +121,7 @@ unsigned ContractCallDataEncoder::encodeSingleItem(QString const& _data, Solidit catch (std::exception const&) { // manage input as a string. - QByteArray bytesAr = src.toLocal8Bit(); - result = bytes(bytesAr.begin(), bytesAr.end()); - result = paddedRight(result, alignSize); + result = encodeBytesParam(src, alignSize); } } @@ -167,6 +165,14 @@ QString ContractCallDataEncoder::toString(bool _b) return _b ? "true" : "false"; } +dev::bytes ContractCallDataEncoder::encodeBytesParam(QString const& _str, unsigned alignSize) +{ + bytes result; + QByteArray bytesAr = _str.toLocal8Bit(); + result = bytes(bytesAr.begin(), bytesAr.end()); + return paddedRight(result, alignSize); +} + dev::bytes ContractCallDataEncoder::encodeBytes(QString const& _str) { QByteArray bytesAr = _str.toLocal8Bit(); diff --git a/mix/ContractCallDataEncoder.h b/mix/ContractCallDataEncoder.h index 805f26691..44f65d37a 100644 --- a/mix/ContractCallDataEncoder.h +++ b/mix/ContractCallDataEncoder.h @@ -52,6 +52,8 @@ public: QVariant decode(SolidityType const& _type, bytes const& _value); /// Get all encoded data encoded by encode function. bytes encodedData(); + /// Encode a string to bytes (in order to be used as funtion param) + dev::bytes encodeBytesParam(QString const& _str, unsigned _alignSize); /// Encode a string to ABI bytes dev::bytes encodeBytes(QString const& _str); /// Decode bytes from ABI diff --git a/mix/qml/DeploymentDialog.qml b/mix/qml/DeploymentDialog.qml index 9235bfaab..ade97008a 100644 --- a/mix/qml/DeploymentDialog.qml +++ b/mix/qml/DeploymentDialog.qml @@ -26,6 +26,7 @@ Dialog { property string eth: registrarAddr.text property string currentAccount property alias gasToUse: gasToUseInput.text + property variant paramsModel: [] function close() { @@ -54,8 +55,8 @@ Dialog { requests.push({ //accounts jsonrpc: "2.0", - method: "eth_balanceAt", - params: [ids[k]], + method: "eth_getBalance", + params: [ids[k], 'latest'], id: k }); } @@ -135,6 +136,7 @@ Dialog { TransactionHelper.rpcCall(requests, function (httpRequest, response){ response = response.replace(/,0+/, ''); // ==> result:27,00000000 var count = JSON.parse(response)[0].result + console.log("count " + count); if (k < parseInt(count) && k > 0) { stop(); @@ -247,6 +249,25 @@ Dialog { columns: 2 width: parent.width + DefaultLabel + { + text: qsTr("State:") + } + + Rectangle + { + width: 300 + color: "transparent" + height: 25 + id: paramsRect + ComboBox + { + id: statesList + textRole: "title" + model: projectModel.stateListModel + } + } + DefaultLabel { text: qsTr("Root Registrar address:") @@ -364,6 +385,7 @@ Dialog { } if (!stopForInputError(inError)) { + projectModel.deployedState = statesList.currentText; if (contractRedeploy.checked) deployWarningDialog.open(); else diff --git a/mix/qml/ProjectModel.qml b/mix/qml/ProjectModel.qml index b15c996fb..0bf7c0fb2 100644 --- a/mix/qml/ProjectModel.qml +++ b/mix/qml/ProjectModel.qml @@ -48,6 +48,7 @@ Item { property CodeEditorView codeEditor: null property var unsavedFiles: [] property alias newProjectDialog: newProjectDialog + property string deployedState //interface function saveAll() { ProjectModelCode.saveAll(); } diff --git a/mix/qml/StateListModel.qml b/mix/qml/StateListModel.qml index 35d106b5f..cb08790c5 100644 --- a/mix/qml/StateListModel.qml +++ b/mix/qml/StateListModel.qml @@ -246,7 +246,7 @@ Item { function addNewContracts() { //add new contracts for all states var changed = false; - for(var c in codeModel.contracts) { + for (var c in codeModel.contracts) { for (var s = 0; s < stateListModel.count; s++) { var state = stateList[s]; for (var t = 0; t < state.transactions.length; t++) { diff --git a/mix/qml/js/NetworkDeployment.js b/mix/qml/js/NetworkDeployment.js index 627277f20..40963d7c7 100644 --- a/mix/qml/js/NetworkDeployment.js +++ b/mix/qml/js/NetworkDeployment.js @@ -20,6 +20,8 @@ * @date 2015 * Ethereum IDE client. */ +.import org.ethereum.qml.QSolidityType 1.0 as QSolidityType + Qt.include("TransactionHelper.js") @@ -43,40 +45,116 @@ function startDeployProject(erasePrevious) console.log("Deploying " + deploymentId + " to " + jsonRpcUrl); deploymentStarted(); - var ctrNames = Object.keys(codeModel.contracts); var ctrAddresses = {}; - deployContracts(0, ctrAddresses, ctrNames, function (){ + var state = retrieveState(projectModel.deployedState); + if (!state) + { + var txt = qsTr("Unable to find state " + projectModel.deployedState); + deploymentError(txt); + console.log(txt); + return; + } + executeTr(0, state, ctrAddresses, function (){ finalizeDeployment(deploymentId, ctrAddresses); }); } -function deployContracts(ctrIndex, ctrAddresses, ctrNames, callBack) +function retrieveState(state) { - var code = codeModel.contracts[ctrNames[ctrIndex]].codeHex; - var requests = [{ - jsonrpc: "2.0", - method: "eth_sendTransaction", - params: [ { "from": deploymentDialog.currentAccount, "gas": deploymentDialog.gasToUse, "code": code } ], - id: 0 - }]; - rpcCall(requests, function (httpCall, response){ - var txt = qsTr("Please wait while " + ctrNames[ctrIndex] + " is published ...") - deploymentStepChanged(txt); - console.log(txt); - ctrAddresses[ctrNames[ctrIndex]] = JSON.parse(response)[0].result - deploymentDialog.waitForTrCountToIncrement(function(status) { - if (status === -1) + for (var k = 0; k < projectModel.stateListModel.count; k++) + { + if (projectModel.stateListModel.get(k).title === state) + return projectModel.stateListModel.get(k); + } + return null; +} + +function replaceParamToken(paramsDef, params, ctrAddresses) +{ + var retParams = {}; + for (var k in paramsDef) + { + var value = ""; + if (params[paramsDef[k].name] !== undefined) + { + value = params[paramsDef[k].name]; + if (paramsDef[k].type.category === 4 && value.indexOf("<") === 0) { - trCountIncrementTimeOut(); - return; + value = value.replace("<", "").replace(">", ""); + value = ctrAddresses[value]; } - ctrIndex++; - if (ctrIndex < ctrNames.length) - deployContracts(ctrIndex, ctrAddresses, ctrNames, callBack); - else - callBack(); + } + retParams[paramsDef[k].name] = value; + } + return retParams; +} + +function getFunction(ctrName, functionId) +{ + if (codeModel.contracts[ctrName] === undefined) + return null; + if (ctrName === functionId) + return codeModel.contracts[ctrName].contract.constructor; + else + { + for (var j in codeModel.contracts[ctrName].contract.functions) + { + if (codeModel.contracts[ctrName].contract.functions[j].name === functionId) + return codeModel.contracts[ctrName].contract.functions[j]; + } + } +} + +function executeTr(trIndex, state, ctrAddresses, callBack) +{ + var tr = state.transactions.get(trIndex); + var func = getFunction(tr.contractId, tr.functionId); + if (!func) + executeTrNextStep(trIndex, state, ctrAddresses, callBack); + else + { + var rpcParams = { "from": deploymentDialog.currentAccount, "gas": deploymentDialog.gasToUse }; + var params = replaceParamToken(func.parameters, tr.parameters, ctrAddresses); + var encodedParams = clientModel.encodeParams(params, tr.contractId, tr.functionId); + + if (state.contractId === state.functionId) + rpcParams.code = codeModel.contracts[tr.contractId].codeHex + encodedParams.join(""); + else + rpcParams.data = func.hash + encodedParams.join(""); + + var requests = [{ + jsonrpc: "2.0", + method: "eth_sendTransaction", + params: [ rpcParams ], + id: jsonRpcRequestId + }]; + + rpcCall(requests, function (httpCall, response){ + var txt = qsTr(tr.contractId + "." + tr.functionId + "() ...") + deploymentStepChanged(txt); + console.log(txt); + if (tr.contractId === tr.functionId) + { + ctrAddresses[tr.contractId] = JSON.parse(response)[0].result + ctrAddresses[tr.contractId + " - " + trIndex] = JSON.parse(response)[0].result //get right ctr address if deploy more than one contract of same type. + } + deploymentDialog.waitForTrCountToIncrement(function(status) { + if (status === -1) + trCountIncrementTimeOut(); + else + executeTrNextStep(trIndex, state, ctrAddresses, callBack) + }); }); - }); + } +} + +function executeTrNextStep(trIndex, state, ctrAddresses, callBack) +{ + trIndex++; + if (trIndex < state.transactions.count) + executeTr(trIndex, state, ctrAddresses, callBack); + else + callBack(); } function finalizeDeployment(deploymentId, addresses) { @@ -144,14 +222,19 @@ function checkEthPath(dappUrl, callBack) registerContentHash(deploymentDialog.eth, callBack); // we directly create a dapp under the root registrar. else { - // the first owned reigstrar must have been created to follow the path. - var str = createString(dappUrl[0]); + // the first owned registrar must have been created to follow the path. + var str = clientModel.encodeString(dappUrl[0]); + console.log("prarma = " + str + " " + deploymentDialog.eth); + + console.log("0x5a3a05bd" + str); + console.log(deploymentDialog.currentAccount); + console.log(deploymentDialog.eth); var requests = []; requests.push({ - //register() + //subRegistrar() jsonrpc: "2.0", method: "eth_call", - params: [ { "gas": 150000, "from": deploymentDialog.currentAccount, "to": '0x' + deploymentDialog.eth, "data": "0x6be16bed" + str.encodeValueAsString() } ], + params: [ { "gas": 150000, "from": deploymentDialog.currentAccount, "to": '0x' + deploymentDialog.eth, "data": "0x5a3a05bd" + str } ], id: jsonRpcRequestId++ }); rpcCall(requests, function (httpRequest, response) { @@ -183,12 +266,12 @@ function checkRegistration(dappUrl, addr, callBack) console.log(txt); var requests = []; var registrar = {} - var str = createString(dappUrl[0]); + var str = clientModel.encodeString(dappUrl[0]); requests.push({ //getOwner() jsonrpc: "2.0", method: "eth_call", - params: [ { "gas" : 2000, "from": deploymentDialog.currentAccount, "to": '0x' + addr, "data": "0x893d20e8" } ], + params: [ { "gas" : 2000, "from": deploymentDialog.currentAccount, "to": '0x' + addr, "data": "0x02571be3" } ], id: jsonRpcRequestId++ }); @@ -196,7 +279,7 @@ function checkRegistration(dappUrl, addr, callBack) //register() jsonrpc: "2.0", method: "eth_call", - params: [ { "from": deploymentDialog.currentAccount, "to": '0x' + addr, "data": "0x6be16bed" + str.encodeValueAsString() } ], + params: [ { "from": deploymentDialog.currentAccount, "to": '0x' + addr, "data": "0x5a3a05bd" + str } ], id: jsonRpcRequestId++ }); @@ -232,7 +315,7 @@ function checkRegistration(dappUrl, addr, callBack) requests.push({ jsonrpc: "2.0", method: "eth_sendTransaction", - params: [ { "from": deploymentDialog.currentAccount, "gas": 20000, "code": "0x60056013565b61059e8061001d6000396000f35b33600081905550560060003560e060020a90048063019848921461009a578063449c2090146100af5780635d574e32146100cd5780635fd4b08a146100e1578063618242da146100f65780636be16bed1461010b5780636c4489b414610129578063893d20e8146101585780639607730714610173578063c284bc2a14610187578063e50f599a14610198578063e5811b35146101af578063ec7b9200146101cd57005b6100a560043561031b565b8060005260206000f35b6100ba6004356103a0565b80600160a060020a031660005260206000f35b6100db600435602435610537565b60006000f35b6100ec600435610529565b8060005260206000f35b6101016004356103dd565b8060005260206000f35b6101166004356103bd565b80600160a060020a031660005260206000f35b61013460043561034b565b82600160a060020a031660005281600160a060020a03166020528060405260606000f35b610160610341565b80600160a060020a031660005260206000f35b6101816004356024356102b4565b60006000f35b6101926004356103fd565b60006000f35b6101a96004356024356044356101f2565b60006000f35b6101ba6004356101eb565b80600160a060020a031660005260206000f35b6101d8600435610530565b80600160a060020a031660005260206000f35b6000919050565b600054600160a060020a031633600160a060020a031614610212576102af565b8160026000858152602001908152602001600020819055508061023457610287565b81600160a060020a0316837f680ad70765443c2967675ab0fb91a46350c01c6df59bf9a41ff8a8dd097464ec60006000a3826001600084600160a060020a03168152602001908152602001600020819055505b827f18d67da0cd86808336a3aa8912f6ea70c5250f1a98b586d1017ef56fe199d4fc60006000a25b505050565b600054600160a060020a031633600160a060020a0316146102d457610317565b806002600084815260200190815260200160002060010181905550817f18d67da0cd86808336a3aa8912f6ea70c5250f1a98b586d1017ef56fe199d4fc60006000a25b5050565b60006001600083600160a060020a03168152602001908152602001600020549050919050565b6000600054905090565b6000600060006002600085815260200190815260200160002054925060026000858152602001908152602001600020600101549150600260008581526020019081526020016000206002015490509193909250565b600060026000838152602001908152602001600020549050919050565b600060026000838152602001908152602001600020600101549050919050565b600060026000838152602001908152602001600020600201549050919050565b600054600160a060020a031633600160a060020a03161461041d57610526565b80600160006002600085815260200190815260200160002054600160a060020a031681526020019081526020016000205414610458576104d2565b6002600082815260200190815260200160002054600160a060020a0316817f680ad70765443c2967675ab0fb91a46350c01c6df59bf9a41ff8a8dd097464ec60006000a36000600160006002600085815260200190815260200160002054600160a060020a03168152602001908152602001600020819055505b6002600082815260200190815260200160002060008101600090556001810160009055600281016000905550807f18d67da0cd86808336a3aa8912f6ea70c5250f1a98b586d1017ef56fe199d4fc60006000a25b50565b6000919050565b6000919050565b600054600160a060020a031633600160a060020a0316146105575761059a565b806002600084815260200190815260200160002060020181905550817f18d67da0cd86808336a3aa8912f6ea70c5250f1a98b586d1017ef56fe199d4fc60006000a25b505056" } ], + params: [ { "from": deploymentDialog.currentAccount, "gas": 20000, "code": "0x600080547fffffffffffffffffffffffff0000000000000000000000000000000000000000163317815561058990819061003990396000f3007c010000000000000000000000000000000000000000000000000000000060003504630198489281146100a757806302571be3146100d957806321f8a721146100e35780632dff6941146100ed5780633b3b57de1461010d5780635a3a05bd1461013d5780635fd4b08a1461017057806389a69c0e1461017c578063b5c645bd146101b0578063be99a9801461022c578063c3d014d614610264578063d93e75731461029857005b73ffffffffffffffffffffffffffffffffffffffff600435166000908152600160205260409020548060005260206000f35b6000808052602081f35b6000808052602081f35b600435600090815260026020819052604090912001548060005260206000f35b600435600090815260026020908152604082205473ffffffffffffffffffffffffffffffffffffffff1680835291f35b600435600090815260026020908152604082206001015473ffffffffffffffffffffffffffffffffffffffff1680835291f35b60008060005260206000f35b6000546102c89060043590602435903373ffffffffffffffffffffffffffffffffffffffff908116911614610451576104b1565b600435600090815260026020819052604090912080546001820154919092015473ffffffffffffffffffffffffffffffffffffffff9283169291909116908273ffffffffffffffffffffffffffffffffffffffff166000528173ffffffffffffffffffffffffffffffffffffffff166020528060405260606000f35b6000546102ce906004359060243590604435903373ffffffffffffffffffffffffffffffffffffffff9081169116146104b557610584565b6000546102d49060043590602435903373ffffffffffffffffffffffffffffffffffffffff9081169116146102e05761031d565b6000546102da90600435903373ffffffffffffffffffffffffffffffffffffffff9081169116146103215761044e565b60006000f35b60006000f35b60006000f35b60006000f35b600082815260026020819052604080832090910183905583917fa6697e974e6a320f454390be03f74955e8978f1a6971ea6730542e37b66179bc91a25b5050565b60008181526002602090815260408083205473ffffffffffffffffffffffffffffffffffffffff1683526001909152902054811461035e576103de565b6000818152600260205260408082205473ffffffffffffffffffffffffffffffffffffffff169183917ff63780e752c6a54a94fc52715dbc5518a3b4c3c2833d301a204226548a2a85459190a360008181526002602090815260408083205473ffffffffffffffffffffffffffffffffffffffff16835260019091528120555b600081815260026020819052604080832080547fffffffffffffffffffffffff00000000000000000000000000000000000000009081168255600182018054909116905590910182905582917fa6697e974e6a320f454390be03f74955e8978f1a6971ea6730542e37b66179bc91a25b50565b60008281526002602052604080822060010180547fffffffffffffffffffffffff0000000000000000000000000000000000000000168417905583917fa6697e974e6a320f454390be03f74955e8978f1a6971ea6730542e37b66179bc91a25b5050565b600083815260026020526040902080547fffffffffffffffffffffffff000000000000000000000000000000000000000016831790558061051c57827fa6697e974e6a320f454390be03f74955e8978f1a6971ea6730542e37b66179bc60006040a2610583565b73ffffffffffffffffffffffffffffffffffffffff8216837ff63780e752c6a54a94fc52715dbc5518a3b4c3c2833d301a204226548a2a854560006040a373ffffffffffffffffffffffffffffffffffffffff821660009081526001602052604090208390555b5b50505056" } ], id: jsonRpcRequestId++ }); @@ -248,12 +331,12 @@ function checkRegistration(dappUrl, addr, callBack) trCountIncrementTimeOut(); return; } - var crLevel = createString(dappUrl[0]).encodeValueAsString(); + var crLevel = clientModel.encodeString(dappUrl[0]); requests.push({ //setRegister() jsonrpc: "2.0", method: "eth_sendTransaction", - params: [ { "from": deploymentDialog.currentAccount, "gas": 30000, "to": '0x' + addr, "data": "0x96077307" + crLevel + deploymentDialog.pad(newCtrAddress) } ], + params: [ { "from": deploymentDialog.currentAccount, "gas": 30000, "to": '0x' + addr, "data": "0x89a69c0e" + crLevel + deploymentDialog.pad(newCtrAddress) } ], id: jsonRpcRequestId++ }); @@ -286,7 +369,7 @@ function registerContentHash(registrar, callBack) //setContent() jsonrpc: "2.0", method: "eth_sendTransaction", - params: [ { "from": deploymentDialog.currentAccount, "gas": 30000, "gasPrice": "10", "to": '0x' + registrar, "data": "0x5d574e32" + paramTitle + deploymentDialog.packageHash } ], + params: [ { "from": deploymentDialog.currentAccount, "gas": 30000, "gasPrice": "10", "to": '0x' + registrar, "data": "0xc3d014d6" + paramTitle + deploymentDialog.packageHash } ], id: jsonRpcRequestId++ }); rpcCall(requests, function (httpRequest, response) { @@ -298,12 +381,12 @@ function registerToUrlHint() { deploymentStepChanged(qsTr("Registering application Resources (" + deploymentDialog.applicationUrlHttp) + ") ..."); var requests = []; - var paramUrlHttp = createString(deploymentDialog.applicationUrlHttp); + var paramUrlHttp = clientModel.encodeString(deploymentDialog.applicationUrlHttp); requests.push({ //urlHint => suggestUrl jsonrpc: "2.0", method: "eth_sendTransaction", - params: [ { "to": '0x' + deploymentDialog.urlHintContract, "gas": 30000, "data": "0x4983e19c" + deploymentDialog.packageHash + paramUrlHttp.encodeValueAsString() } ], + params: [ { "to": '0x' + deploymentDialog.urlHintContract, "gas": 30000, "data": "0x584e86ad" + deploymentDialog.packageHash + paramUrlHttp } ], id: jsonRpcRequestId++ }); diff --git a/test/webthreestubclient.h b/test/webthreestubclient.h new file mode 100644 index 000000000..fd71bfb5d --- /dev/null +++ b/test/webthreestubclient.h @@ -0,0 +1,596 @@ +/** + * This file is generated by jsonrpcstub, DO NOT CHANGE IT MANUALLY! + */ + +#ifndef JSONRPC_CPP_STUB_WEBTHREESTUBCLIENT_H_ +#define JSONRPC_CPP_STUB_WEBTHREESTUBCLIENT_H_ + +#include + +class WebThreeStubClient : public jsonrpc::Client +{ + public: + WebThreeStubClient(jsonrpc::IClientConnector &conn, jsonrpc::clientVersion_t type = jsonrpc::JSONRPC_CLIENT_V2) : jsonrpc::Client(conn, type) {} + + std::string web3_sha3(const std::string& param1) throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p.append(param1); + Json::Value result = this->CallMethod("web3_sha3",p); + if (result.isString()) + return result.asString(); + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } + std::string web3_clientVersion() throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p = Json::nullValue; + Json::Value result = this->CallMethod("web3_clientVersion",p); + if (result.isString()) + return result.asString(); + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } + std::string net_version() throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p = Json::nullValue; + Json::Value result = this->CallMethod("net_version",p); + if (result.isString()) + return result.asString(); + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } + std::string net_peerCount() throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p = Json::nullValue; + Json::Value result = this->CallMethod("net_peerCount",p); + if (result.isString()) + return result.asString(); + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } + bool net_listening() throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p = Json::nullValue; + Json::Value result = this->CallMethod("net_listening",p); + if (result.isBool()) + return result.asBool(); + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } + std::string eth_protocolVersion() throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p = Json::nullValue; + Json::Value result = this->CallMethod("eth_protocolVersion",p); + if (result.isString()) + return result.asString(); + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } + std::string eth_hashrate() throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p = Json::nullValue; + Json::Value result = this->CallMethod("eth_hashrate",p); + if (result.isString()) + return result.asString(); + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } + std::string eth_coinbase() throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p = Json::nullValue; + Json::Value result = this->CallMethod("eth_coinbase",p); + if (result.isString()) + return result.asString(); + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } + bool eth_mining() throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p = Json::nullValue; + Json::Value result = this->CallMethod("eth_mining",p); + if (result.isBool()) + return result.asBool(); + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } + std::string eth_gasPrice() throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p = Json::nullValue; + Json::Value result = this->CallMethod("eth_gasPrice",p); + if (result.isString()) + return result.asString(); + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } + Json::Value eth_accounts() throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p = Json::nullValue; + Json::Value result = this->CallMethod("eth_accounts",p); + if (result.isArray()) + return result; + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } + std::string eth_blockNumber() throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p = Json::nullValue; + Json::Value result = this->CallMethod("eth_blockNumber",p); + if (result.isString()) + return result.asString(); + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } + std::string eth_getBalance(const std::string& param1, const std::string& param2) throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p.append(param1); + p.append(param2); + Json::Value result = this->CallMethod("eth_getBalance",p); + if (result.isString()) + return result.asString(); + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } + std::string eth_getStorageAt(const std::string& param1, const std::string& param2, const std::string& param3) throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p.append(param1); + p.append(param2); + p.append(param3); + Json::Value result = this->CallMethod("eth_getStorageAt",p); + if (result.isString()) + return result.asString(); + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } + std::string eth_getTransactionCount(const std::string& param1, const std::string& param2) throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p.append(param1); + p.append(param2); + Json::Value result = this->CallMethod("eth_getTransactionCount",p); + if (result.isString()) + return result.asString(); + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } + std::string eth_getBlockTransactionCountByHash(const std::string& param1) throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p.append(param1); + Json::Value result = this->CallMethod("eth_getBlockTransactionCountByHash",p); + if (result.isString()) + return result.asString(); + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } + std::string eth_getBlockTransactionCountByNumber(const std::string& param1) throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p.append(param1); + Json::Value result = this->CallMethod("eth_getBlockTransactionCountByNumber",p); + if (result.isString()) + return result.asString(); + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } + std::string eth_getUncleCountByBlockHash(const std::string& param1) throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p.append(param1); + Json::Value result = this->CallMethod("eth_getUncleCountByBlockHash",p); + if (result.isString()) + return result.asString(); + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } + std::string eth_getUncleCountByBlockNumber(const std::string& param1) throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p.append(param1); + Json::Value result = this->CallMethod("eth_getUncleCountByBlockNumber",p); + if (result.isString()) + return result.asString(); + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } + std::string eth_getCode(const std::string& param1, const std::string& param2) throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p.append(param1); + p.append(param2); + Json::Value result = this->CallMethod("eth_getCode",p); + if (result.isString()) + return result.asString(); + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } + std::string eth_sendTransaction(const Json::Value& param1) throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p.append(param1); + Json::Value result = this->CallMethod("eth_sendTransaction",p); + if (result.isString()) + return result.asString(); + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } + std::string eth_call(const Json::Value& param1, const std::string& param2) throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p.append(param1); + p.append(param2); + Json::Value result = this->CallMethod("eth_call",p); + if (result.isString()) + return result.asString(); + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } + bool eth_flush() throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p = Json::nullValue; + Json::Value result = this->CallMethod("eth_flush",p); + if (result.isBool()) + return result.asBool(); + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } + Json::Value eth_getBlockByHash(const std::string& param1, bool param2) throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p.append(param1); + p.append(param2); + Json::Value result = this->CallMethod("eth_getBlockByHash",p); + if (result.isObject()) + return result; + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } + Json::Value eth_getBlockByNumber(const std::string& param1, bool param2) throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p.append(param1); + p.append(param2); + Json::Value result = this->CallMethod("eth_getBlockByNumber",p); + if (result.isObject()) + return result; + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } + Json::Value eth_getTransactionByHash(const std::string& param1) throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p.append(param1); + Json::Value result = this->CallMethod("eth_getTransactionByHash",p); + if (result.isObject()) + return result; + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } + Json::Value eth_getTransactionByBlockHashAndIndex(const std::string& param1, const std::string& param2) throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p.append(param1); + p.append(param2); + Json::Value result = this->CallMethod("eth_getTransactionByBlockHashAndIndex",p); + if (result.isObject()) + return result; + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } + Json::Value eth_getTransactionByBlockNumberAndIndex(const std::string& param1, const std::string& param2) throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p.append(param1); + p.append(param2); + Json::Value result = this->CallMethod("eth_getTransactionByBlockNumberAndIndex",p); + if (result.isObject()) + return result; + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } + Json::Value eth_getUncleByBlockHashAndIndex(const std::string& param1, const std::string& param2) throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p.append(param1); + p.append(param2); + Json::Value result = this->CallMethod("eth_getUncleByBlockHashAndIndex",p); + if (result.isObject()) + return result; + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } + Json::Value eth_getUncleByBlockNumberAndIndex(const std::string& param1, const std::string& param2) throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p.append(param1); + p.append(param2); + Json::Value result = this->CallMethod("eth_getUncleByBlockNumberAndIndex",p); + if (result.isObject()) + return result; + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } + Json::Value eth_getCompilers() throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p = Json::nullValue; + Json::Value result = this->CallMethod("eth_getCompilers",p); + if (result.isArray()) + return result; + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } + std::string eth_compileLLL(const std::string& param1) throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p.append(param1); + Json::Value result = this->CallMethod("eth_compileLLL",p); + if (result.isString()) + return result.asString(); + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } + std::string eth_compileSerpent(const std::string& param1) throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p.append(param1); + Json::Value result = this->CallMethod("eth_compileSerpent",p); + if (result.isString()) + return result.asString(); + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } + std::string eth_compileSolidity(const std::string& param1) throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p.append(param1); + Json::Value result = this->CallMethod("eth_compileSolidity",p); + if (result.isString()) + return result.asString(); + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } + std::string eth_newFilter(const Json::Value& param1) throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p.append(param1); + Json::Value result = this->CallMethod("eth_newFilter",p); + if (result.isString()) + return result.asString(); + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } + std::string eth_newBlockFilter(const std::string& param1) throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p.append(param1); + Json::Value result = this->CallMethod("eth_newBlockFilter",p); + if (result.isString()) + return result.asString(); + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } + bool eth_uninstallFilter(const std::string& param1) throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p.append(param1); + Json::Value result = this->CallMethod("eth_uninstallFilter",p); + if (result.isBool()) + return result.asBool(); + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } + Json::Value eth_getFilterChanges(const std::string& param1) throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p.append(param1); + Json::Value result = this->CallMethod("eth_getFilterChanges",p); + if (result.isArray()) + return result; + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } + Json::Value eth_getFilterLogs(const std::string& param1) throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p.append(param1); + Json::Value result = this->CallMethod("eth_getFilterLogs",p); + if (result.isArray()) + return result; + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } + Json::Value eth_getLogs(const Json::Value& param1) throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p.append(param1); + Json::Value result = this->CallMethod("eth_getLogs",p); + if (result.isArray()) + return result; + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } + Json::Value eth_getWork() throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p = Json::nullValue; + Json::Value result = this->CallMethod("eth_getWork",p); + if (result.isArray()) + return result; + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } + bool eth_submitWork(const std::string& param1, const std::string& param2, const std::string& param3) throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p.append(param1); + p.append(param2); + p.append(param3); + Json::Value result = this->CallMethod("eth_submitWork",p); + if (result.isBool()) + return result.asBool(); + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } + std::string eth_register(const std::string& param1) throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p.append(param1); + Json::Value result = this->CallMethod("eth_register",p); + if (result.isString()) + return result.asString(); + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } + bool eth_unregister(const std::string& param1) throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p.append(param1); + Json::Value result = this->CallMethod("eth_unregister",p); + if (result.isBool()) + return result.asBool(); + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } + Json::Value eth_fetchQueuedTransactions(const std::string& param1) throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p.append(param1); + Json::Value result = this->CallMethod("eth_fetchQueuedTransactions",p); + if (result.isArray()) + return result; + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } + bool db_put(const std::string& param1, const std::string& param2, const std::string& param3) throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p.append(param1); + p.append(param2); + p.append(param3); + Json::Value result = this->CallMethod("db_put",p); + if (result.isBool()) + return result.asBool(); + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } + std::string db_get(const std::string& param1, const std::string& param2) throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p.append(param1); + p.append(param2); + Json::Value result = this->CallMethod("db_get",p); + if (result.isString()) + return result.asString(); + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } + bool shh_post(const Json::Value& param1) throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p.append(param1); + Json::Value result = this->CallMethod("shh_post",p); + if (result.isBool()) + return result.asBool(); + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } + std::string shh_newIdentity() throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p = Json::nullValue; + Json::Value result = this->CallMethod("shh_newIdentity",p); + if (result.isString()) + return result.asString(); + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } + bool shh_hasIdentity(const std::string& param1) throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p.append(param1); + Json::Value result = this->CallMethod("shh_hasIdentity",p); + if (result.isBool()) + return result.asBool(); + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } + std::string shh_newGroup(const std::string& param1, const std::string& param2) throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p.append(param1); + p.append(param2); + Json::Value result = this->CallMethod("shh_newGroup",p); + if (result.isString()) + return result.asString(); + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } + std::string shh_addToGroup(const std::string& param1, const std::string& param2) throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p.append(param1); + p.append(param2); + Json::Value result = this->CallMethod("shh_addToGroup",p); + if (result.isString()) + return result.asString(); + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } + std::string shh_newFilter(const Json::Value& param1) throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p.append(param1); + Json::Value result = this->CallMethod("shh_newFilter",p); + if (result.isString()) + return result.asString(); + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } + bool shh_uninstallFilter(const std::string& param1) throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p.append(param1); + Json::Value result = this->CallMethod("shh_uninstallFilter",p); + if (result.isBool()) + return result.asBool(); + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } + Json::Value shh_getFilterChanges(const std::string& param1) throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p.append(param1); + Json::Value result = this->CallMethod("shh_getFilterChanges",p); + if (result.isArray()) + return result; + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } + Json::Value shh_getMessages(const std::string& param1) throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p.append(param1); + Json::Value result = this->CallMethod("shh_getMessages",p); + if (result.isArray()) + return result; + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } +}; + +#endif //JSONRPC_CPP_STUB_WEBTHREESTUBCLIENT_H_