From a8d84b0d86261b01ef5fc5f6282b68dd6be6d07a Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Sat, 14 Mar 2015 19:00:41 +0100 Subject: [PATCH 1/5] getData -> getCode. --- libjsqrc/CMakeLists.txt | 6 ++++++ libjsqrc/ethereumjs/lib/web3/eth.js | 2 +- libweb3jsonrpc/WebThreeStubServerBase.cpp | 2 +- libweb3jsonrpc/WebThreeStubServerBase.h | 2 +- libweb3jsonrpc/abstractwebthreestubserver.h | 6 +++--- test/webthreestubclient.h | 4 ++-- 6 files changed, 14 insertions(+), 8 deletions(-) diff --git a/libjsqrc/CMakeLists.txt b/libjsqrc/CMakeLists.txt index 6554e523d..e5da5c4ee 100644 --- a/libjsqrc/CMakeLists.txt +++ b/libjsqrc/CMakeLists.txt @@ -23,3 +23,9 @@ if (USENPM) endif() install( TARGETS jsqrc RUNTIME DESTINATION bin ARCHIVE DESTINATION lib LIBRARY DESTINATION lib ) + +file(GLOB_RECURSE SOLFILES "ethereumjs/lib/solidity/*.js") +file(GLOB_RECURSE UTILSFILES "ethereumjs/lib/utils/*.js") +file(GLOB_RECURSE WEB3FILES "ethereumjs/lib/web3/*.js") +add_custom_target(aux_js SOURCES ${SOLFILES} ${UTILSFILES} ${WEB3FILES}) + diff --git a/libjsqrc/ethereumjs/lib/web3/eth.js b/libjsqrc/ethereumjs/lib/web3/eth.js index cdf245198..9b13eccdb 100644 --- a/libjsqrc/ethereumjs/lib/web3/eth.js +++ b/libjsqrc/ethereumjs/lib/web3/eth.js @@ -77,7 +77,7 @@ var methods = [ { name: 'getStorage', call: 'eth_getStorage', addDefaultblock: 2}, { name: 'getStorageAt', call: 'eth_getStorageAt', addDefaultblock: 3, inputFormatter: utils.toHex}, - { name: 'getData', call: 'eth_getData', addDefaultblock: 2}, + { name: 'getCode', call: 'eth_getCode', addDefaultblock: 2}, { name: 'getBlock', call: blockCall, outputFormatter: formatters.outputBlockFormatter, inputFormatter: [utils.toHex, function(param){ return (!param) ? false : true; }]}, diff --git a/libweb3jsonrpc/WebThreeStubServerBase.cpp b/libweb3jsonrpc/WebThreeStubServerBase.cpp index 11f4da3ec..d0cb9c72f 100644 --- a/libweb3jsonrpc/WebThreeStubServerBase.cpp +++ b/libweb3jsonrpc/WebThreeStubServerBase.cpp @@ -435,7 +435,7 @@ string WebThreeStubServerBase::eth_getUncleCountByBlockNumber(string const& _blo return toJS(client()->uncleCount(client()->hashFromNumber(number))); } -string WebThreeStubServerBase::eth_getData(string const& _address, string const& _blockNumber) +string WebThreeStubServerBase::eth_getCode(string const& _address, string const& _blockNumber) { Address address; int number; diff --git a/libweb3jsonrpc/WebThreeStubServerBase.h b/libweb3jsonrpc/WebThreeStubServerBase.h index c71d7ee30..9914d071e 100644 --- a/libweb3jsonrpc/WebThreeStubServerBase.h +++ b/libweb3jsonrpc/WebThreeStubServerBase.h @@ -87,7 +87,7 @@ public: virtual std::string eth_getBlockTransactionCountByNumber(std::string const& _blockNumber); virtual std::string eth_getUncleCountByBlockHash(std::string const& _blockHash); virtual std::string eth_getUncleCountByBlockNumber(std::string const& _blockNumber); - virtual std::string eth_getData(std::string const& _address, std::string const& _blockNumber); + virtual std::string eth_getCode(std::string const& _address, std::string const& _blockNumber); virtual std::string eth_sendTransaction(Json::Value const& _json); virtual std::string eth_call(Json::Value const& _json, std::string const& _blockNumber); virtual bool eth_flush(); diff --git a/libweb3jsonrpc/abstractwebthreestubserver.h b/libweb3jsonrpc/abstractwebthreestubserver.h index cc326183d..6d84571a1 100644 --- a/libweb3jsonrpc/abstractwebthreestubserver.h +++ b/libweb3jsonrpc/abstractwebthreestubserver.h @@ -30,7 +30,7 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServerbindAndAddMethod(jsonrpc::Procedure("eth_getBlockTransactionCountByNumber", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_getBlockTransactionCountByNumberI); this->bindAndAddMethod(jsonrpc::Procedure("eth_getUncleCountByBlockHash", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_getUncleCountByBlockHashI); this->bindAndAddMethod(jsonrpc::Procedure("eth_getUncleCountByBlockNumber", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_getUncleCountByBlockNumberI); - this->bindAndAddMethod(jsonrpc::Procedure("eth_getData", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING,"param2",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_getDataI); + this->bindAndAddMethod(jsonrpc::Procedure("eth_getCode", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING,"param2",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_getDataI); this->bindAndAddMethod(jsonrpc::Procedure("eth_sendTransaction", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_OBJECT, NULL), &AbstractWebThreeStubServer::eth_sendTransactionI); this->bindAndAddMethod(jsonrpc::Procedure("eth_call", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_OBJECT,"param2",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_callI); this->bindAndAddMethod(jsonrpc::Procedure("eth_flush", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, NULL), &AbstractWebThreeStubServer::eth_flushI); @@ -152,7 +152,7 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServereth_getData(request[0u].asString(), request[1u].asString()); + response = this->eth_getCode(request[0u].asString(), request[1u].asString()); } inline virtual void eth_sendTransactionI(const Json::Value &request, Json::Value &response) { @@ -320,7 +320,7 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServerCallMethod("eth_getData",p); + Json::Value result = this->CallMethod("eth_getCode",p); if (result.isString()) return result.asString(); else From 4495de33312c3f14958b6c48c4f845fa98c1b017 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Sat, 14 Mar 2015 19:59:07 +0100 Subject: [PATCH 2/5] Renaming getData -> getCode, remove getStorage, fix a bunch of JSONRPC methods with more expansive error handling. --- libjsqrc/CMakeLists.txt | 6 +- libjsqrc/ethereumjs/dist/ethereum.js | 3 +- libjsqrc/ethereumjs/lib/web3/eth.js | 1 - libweb3jsonrpc/CMakeLists.txt | 1 + libweb3jsonrpc/WebThreeStubServerBase.cpp | 79 +++------------------ libweb3jsonrpc/WebThreeStubServerBase.h | 1 - libweb3jsonrpc/abstractwebthreestubserver.h | 10 +-- libweb3jsonrpc/spec.json | 3 +- test/webthreestubclient.h | 11 --- 9 files changed, 15 insertions(+), 100 deletions(-) diff --git a/libjsqrc/CMakeLists.txt b/libjsqrc/CMakeLists.txt index e5da5c4ee..4e849de12 100644 --- a/libjsqrc/CMakeLists.txt +++ b/libjsqrc/CMakeLists.txt @@ -24,8 +24,6 @@ endif() install( TARGETS jsqrc RUNTIME DESTINATION bin ARCHIVE DESTINATION lib LIBRARY DESTINATION lib ) -file(GLOB_RECURSE SOLFILES "ethereumjs/lib/solidity/*.js") -file(GLOB_RECURSE UTILSFILES "ethereumjs/lib/utils/*.js") -file(GLOB_RECURSE WEB3FILES "ethereumjs/lib/web3/*.js") -add_custom_target(aux_js SOURCES ${SOLFILES} ${UTILSFILES} ${WEB3FILES}) +file(GLOB_RECURSE JSFILES "ethereumjs/lib/*.js") +add_custom_target(aux_js SOURCES ${JSFILES}) diff --git a/libjsqrc/ethereumjs/dist/ethereum.js b/libjsqrc/ethereumjs/dist/ethereum.js index 88a5180a9..725ef476d 100644 --- a/libjsqrc/ethereumjs/dist/ethereum.js +++ b/libjsqrc/ethereumjs/dist/ethereum.js @@ -1706,7 +1706,6 @@ var uncleCountCall = function (args) { var methods = [ { name: 'getBalance', call: 'eth_getBalance', addDefaultblock: 2, outputFormatter: formatters.convertToBigNumber}, - { name: 'getStorage', call: 'eth_getStorage', addDefaultblock: 2}, { name: 'getStorageAt', call: 'eth_getStorageAt', addDefaultblock: 3, inputFormatter: utils.toHex}, { name: 'getData', call: 'eth_getData', addDefaultblock: 2}, @@ -2831,4 +2830,4 @@ module.exports = web3; },{"./lib/solidity/abi":1,"./lib/web3":6,"./lib/web3/contract":7,"./lib/web3/httpprovider":13,"./lib/web3/qtsync":16}]},{},["web3"]) -//# sourceMappingURL=ethereum.js.map \ No newline at end of file +//# sourceMappingURL=ethereum.js.map diff --git a/libjsqrc/ethereumjs/lib/web3/eth.js b/libjsqrc/ethereumjs/lib/web3/eth.js index 9b13eccdb..2875aa94e 100644 --- a/libjsqrc/ethereumjs/lib/web3/eth.js +++ b/libjsqrc/ethereumjs/lib/web3/eth.js @@ -74,7 +74,6 @@ var uncleCountCall = function (args) { var methods = [ { name: 'getBalance', call: 'eth_getBalance', addDefaultblock: 2, outputFormatter: formatters.convertToBigNumber}, - { name: 'getStorage', call: 'eth_getStorage', addDefaultblock: 2}, { name: 'getStorageAt', call: 'eth_getStorageAt', addDefaultblock: 3, inputFormatter: utils.toHex}, { name: 'getCode', call: 'eth_getCode', addDefaultblock: 2}, diff --git a/libweb3jsonrpc/CMakeLists.txt b/libweb3jsonrpc/CMakeLists.txt index b445f77ff..d3f4b70b6 100644 --- a/libweb3jsonrpc/CMakeLists.txt +++ b/libweb3jsonrpc/CMakeLists.txt @@ -56,4 +56,5 @@ endif() install( TARGETS ${EXECUTABLE} RUNTIME DESTINATION bin ARCHIVE DESTINATION lib LIBRARY DESTINATION lib ) install( FILES ${HEADERS} DESTINATION include/${EXECUTABLE} ) +add_custom_target(aux_json SOURCES "spec.json") diff --git a/libweb3jsonrpc/WebThreeStubServerBase.cpp b/libweb3jsonrpc/WebThreeStubServerBase.cpp index d0cb9c72f..0434d1e76 100644 --- a/libweb3jsonrpc/WebThreeStubServerBase.cpp +++ b/libweb3jsonrpc/WebThreeStubServerBase.cpp @@ -295,162 +295,99 @@ string WebThreeStubServerBase::eth_blockNumber() string WebThreeStubServerBase::eth_getBalance(string const& _address, string const& _blockNumber) { - Address address; - int number; - - try - { - address = jsToAddress(_address); - number = toBlockNumber(_blockNumber); - } - catch (...) - { - BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INVALID_PARAMS)); - } - - return toJS(client()->balanceAt(address, number)); -} - - -Json::Value WebThreeStubServerBase::eth_getStorage(string const& _address, string const& _blockNumber) -{ - Address address; - int number; - try { - address = jsToAddress(_address); - number = toBlockNumber(_blockNumber); + return toJS(client()->balanceAt(jsToAddress(_address), toBlockNumber(_blockNumber))); } catch (...) { BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INVALID_PARAMS)); } - - //TODO: fix this naming ! - return toJson(client()->storageAt(address, number)); } string WebThreeStubServerBase::eth_getStorageAt(string const& _address, string const& _position, string const& _blockNumber) { - Address address; - u256 position; - int number; - try { - address = jsToAddress(_address); - position = jsToU256(_position); - number = toBlockNumber(_blockNumber); + return toJS(client()->stateAt(jsToAddress(_address), jsToU256(_position), toBlockNumber(_blockNumber))); } catch (...) { BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INVALID_PARAMS)); } - - //TODO: fix this naming ! - return toJS(client()->stateAt(address, position, number)); } string WebThreeStubServerBase::eth_getTransactionCount(string const& _address, string const& _blockNumber) { - Address address; - int number; - try { - address = jsToAddress(_address); - number = toBlockNumber(_blockNumber); + return toJS(client()->countAt(jsToAddress(_address), toBlockNumber(_blockNumber))); } catch (...) { BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INVALID_PARAMS)); } - - return toJS(client()->countAt(address, number)); } string WebThreeStubServerBase::eth_getBlockTransactionCountByHash(string const& _blockHash) { - h256 hash; - try { - hash = jsToFixed<32>(_blockHash); + return toJS(client()->transactionCount(jsToFixed<32>(_blockHash))); } catch (...) { BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INVALID_PARAMS)); } - - return toJS(client()->transactionCount(hash)); } string WebThreeStubServerBase::eth_getBlockTransactionCountByNumber(string const& _blockNumber) { - int number; - try { - number = toBlockNumber(_blockNumber); + return toJS(client()->transactionCount(client()->hashFromNumber(toBlockNumber(_blockNumber)))); } catch (...) { BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INVALID_PARAMS)); } - - return toJS(client()->transactionCount(client()->hashFromNumber(number))); } string WebThreeStubServerBase::eth_getUncleCountByBlockHash(string const& _blockHash) { - h256 hash; - try { - hash = jsToFixed<32>(_blockHash); + return toJS(client()->uncleCount(jsToFixed<32>(_blockHash))); } catch (...) { BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INVALID_PARAMS)); } - - return toJS(client()->uncleCount(hash)); } string WebThreeStubServerBase::eth_getUncleCountByBlockNumber(string const& _blockNumber) { - int number; - try { - number = toBlockNumber(_blockNumber); + return toJS(client()->uncleCount(client()->hashFromNumber(toBlockNumber(_blockNumber)))); } catch (...) { BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INVALID_PARAMS)); } - - return toJS(client()->uncleCount(client()->hashFromNumber(number))); } string WebThreeStubServerBase::eth_getCode(string const& _address, string const& _blockNumber) { - Address address; - int number; - try { - address = jsToAddress(_address); - number = toBlockNumber(_blockNumber); + return toJS(client()->codeAt(jsToAddress(_address), toBlockNumber(_blockNumber))); } catch (...) { BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INVALID_PARAMS)); } - - return toJS(client()->codeAt(address, number)); } static TransactionSkeleton toTransaction(Json::Value const& _json) diff --git a/libweb3jsonrpc/WebThreeStubServerBase.h b/libweb3jsonrpc/WebThreeStubServerBase.h index 9914d071e..214573e0d 100644 --- a/libweb3jsonrpc/WebThreeStubServerBase.h +++ b/libweb3jsonrpc/WebThreeStubServerBase.h @@ -80,7 +80,6 @@ public: virtual Json::Value eth_accounts(); virtual std::string eth_blockNumber(); virtual std::string eth_getBalance(std::string const& _address, std::string const& _blockNumber); - virtual Json::Value eth_getStorage(std::string const& _address, std::string const& _blockNumber); virtual std::string eth_getStorageAt(std::string const& _address, std::string const& _position, std::string const& _blockNumber); virtual std::string eth_getTransactionCount(std::string const& _address, std::string const& _blockNumber); virtual std::string eth_getBlockTransactionCountByHash(std::string const& _blockHash); diff --git a/libweb3jsonrpc/abstractwebthreestubserver.h b/libweb3jsonrpc/abstractwebthreestubserver.h index 6d84571a1..516817d5c 100644 --- a/libweb3jsonrpc/abstractwebthreestubserver.h +++ b/libweb3jsonrpc/abstractwebthreestubserver.h @@ -23,14 +23,13 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServerbindAndAddMethod(jsonrpc::Procedure("eth_accounts", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_ARRAY, NULL), &AbstractWebThreeStubServer::eth_accountsI); this->bindAndAddMethod(jsonrpc::Procedure("eth_blockNumber", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_blockNumberI); this->bindAndAddMethod(jsonrpc::Procedure("eth_getBalance", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING,"param2",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_getBalanceI); - this->bindAndAddMethod(jsonrpc::Procedure("eth_getStorage", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_OBJECT, "param1",jsonrpc::JSON_STRING,"param2",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_getStorageI); this->bindAndAddMethod(jsonrpc::Procedure("eth_getStorageAt", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING,"param2",jsonrpc::JSON_STRING,"param3",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_getStorageAtI); this->bindAndAddMethod(jsonrpc::Procedure("eth_getTransactionCount", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING,"param2",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_getTransactionCountI); this->bindAndAddMethod(jsonrpc::Procedure("eth_getBlockTransactionCountByHash", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_getBlockTransactionCountByHashI); this->bindAndAddMethod(jsonrpc::Procedure("eth_getBlockTransactionCountByNumber", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_getBlockTransactionCountByNumberI); this->bindAndAddMethod(jsonrpc::Procedure("eth_getUncleCountByBlockHash", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_getUncleCountByBlockHashI); this->bindAndAddMethod(jsonrpc::Procedure("eth_getUncleCountByBlockNumber", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_getUncleCountByBlockNumberI); - this->bindAndAddMethod(jsonrpc::Procedure("eth_getCode", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING,"param2",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_getDataI); + this->bindAndAddMethod(jsonrpc::Procedure("eth_getCode", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING,"param2",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_getCodeI); this->bindAndAddMethod(jsonrpc::Procedure("eth_sendTransaction", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_OBJECT, NULL), &AbstractWebThreeStubServer::eth_sendTransactionI); this->bindAndAddMethod(jsonrpc::Procedure("eth_call", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_OBJECT,"param2",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_callI); this->bindAndAddMethod(jsonrpc::Procedure("eth_flush", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, NULL), &AbstractWebThreeStubServer::eth_flushI); @@ -122,10 +121,6 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServereth_getBalance(request[0u].asString(), request[1u].asString()); } - inline virtual void eth_getStorageI(const Json::Value &request, Json::Value &response) - { - response = this->eth_getStorage(request[0u].asString(), request[1u].asString()); - } inline virtual void eth_getStorageAtI(const Json::Value &request, Json::Value &response) { response = this->eth_getStorageAt(request[0u].asString(), request[1u].asString(), request[2u].asString()); @@ -150,7 +145,7 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServereth_getUncleCountByBlockNumber(request[0u].asString()); } - inline virtual void eth_getDataI(const Json::Value &request, Json::Value &response) + inline virtual void eth_getCodeI(const Json::Value &request, Json::Value &response) { response = this->eth_getCode(request[0u].asString(), request[1u].asString()); } @@ -313,7 +308,6 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServerCallMethod("eth_getStorage",p); - if (result.isObject()) - return result; - 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; From 2121dd1e27b9d67eac2bdd05271c8c651ebcdfe0 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Sat, 14 Mar 2015 20:01:59 +0100 Subject: [PATCH 3/5] Fixes for getCode. --- libjsqrc/ethereumjs/dist/ethereum.js | 4 ++-- libjsqrc/ethereumjs/lib/web3/eth.js | 2 +- libjsqrc/ethereumjs/test/eth.methods.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libjsqrc/ethereumjs/dist/ethereum.js b/libjsqrc/ethereumjs/dist/ethereum.js index 7adfa28ca..4ae476ca5 100644 --- a/libjsqrc/ethereumjs/dist/ethereum.js +++ b/libjsqrc/ethereumjs/dist/ethereum.js @@ -1728,7 +1728,7 @@ var methods = [ outputFormatter: formatters.convertToBigNumber}, { name: 'getStorageAt', call: 'eth_getStorageAt', addDefaultblock: 3, inputFormatter: utils.toHex}, - { name: 'getData', call: 'eth_getData', addDefaultblock: 2}, + { name: 'getCode', call: 'eth_getCode', addDefaultblock: 2}, { name: 'getBlock', call: blockCall, outputFormatter: formatters.outputBlockFormatter, inputFormatter: [utils.toHex, function(param){ return (!param) ? false : true; }]}, @@ -1763,7 +1763,7 @@ var methods = [ { name: 'stateAt', call: 'eth_stateAt', newMethod: 'eth.getStorageAt' }, { name: 'storageAt', call: 'eth_storageAt', newMethod: 'eth.getStorage' }, { name: 'countAt', call: 'eth_countAt', newMethod: 'eth.getTransactionCount' }, - { name: 'codeAt', call: 'eth_codeAt', newMethod: 'eth.getData' }, + { name: 'codeAt', call: 'eth_codeAt', newMethod: 'eth.getCode' }, { name: 'transact', call: 'eth_transact', newMethod: 'eth.sendTransaction' }, { name: 'block', call: blockCall, newMethod: 'eth.getBlock' }, { name: 'transaction', call: transactionFromBlockCall, newMethod: 'eth.getTransaction' }, diff --git a/libjsqrc/ethereumjs/lib/web3/eth.js b/libjsqrc/ethereumjs/lib/web3/eth.js index 4ea5b1886..cfb4280e0 100644 --- a/libjsqrc/ethereumjs/lib/web3/eth.js +++ b/libjsqrc/ethereumjs/lib/web3/eth.js @@ -112,7 +112,7 @@ var methods = [ { name: 'stateAt', call: 'eth_stateAt', newMethod: 'eth.getStorageAt' }, { name: 'storageAt', call: 'eth_storageAt', newMethod: 'eth.getStorage' }, { name: 'countAt', call: 'eth_countAt', newMethod: 'eth.getTransactionCount' }, - { name: 'codeAt', call: 'eth_codeAt', newMethod: 'eth.getData' }, + { name: 'codeAt', call: 'eth_codeAt', newMethod: 'eth.getCode' }, { name: 'transact', call: 'eth_transact', newMethod: 'eth.sendTransaction' }, { name: 'block', call: blockCall, newMethod: 'eth.getBlock' }, { name: 'transaction', call: transactionFromBlockCall, newMethod: 'eth.getTransaction' }, diff --git a/libjsqrc/ethereumjs/test/eth.methods.js b/libjsqrc/ethereumjs/test/eth.methods.js index e1eea1ec4..7fb8d3b24 100644 --- a/libjsqrc/ethereumjs/test/eth.methods.js +++ b/libjsqrc/ethereumjs/test/eth.methods.js @@ -8,7 +8,7 @@ describe('web3', function() { u.methodExists(web3.eth, 'getStorageAt'); u.methodExists(web3.eth, 'getStorage'); u.methodExists(web3.eth, 'getTransactionCount'); - u.methodExists(web3.eth, 'getData'); + u.methodExists(web3.eth, 'getCode'); u.methodExists(web3.eth, 'sendTransaction'); u.methodExists(web3.eth, 'call'); u.methodExists(web3.eth, 'getBlock'); From 53b50a1213ad64de85774183105e123632aa0397 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Sat, 14 Mar 2015 20:13:10 +0100 Subject: [PATCH 4/5] Avoid accidentally reaping properly managed watches. --- alethzero/MainWin.cpp | 2 +- libethereum/Client.cpp | 10 +++++----- libethereum/Client.h | 6 +++--- libethereum/Interface.h | 10 ++++++++-- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/alethzero/MainWin.cpp b/alethzero/MainWin.cpp index a6ef485df..5d4f9770e 100644 --- a/alethzero/MainWin.cpp +++ b/alethzero/MainWin.cpp @@ -263,7 +263,7 @@ unsigned Main::installWatch(LogFilter const& _tf, WatchHandler const& _f) unsigned Main::installWatch(dev::h256 _tf, WatchHandler const& _f) { - auto ret = ethereum()->installWatch(_tf); + auto ret = ethereum()->installWatch(_tf, Reaping::Manual); m_handlers[ret] = _f; return ret; } diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index f46d0d3c9..9d7ecb605 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -249,13 +249,13 @@ void Client::clearPending() noteChanged(changeds); } -unsigned Client::installWatch(h256 _h) +unsigned Client::installWatch(h256 _h, Reaping _r) { unsigned ret; { Guard l(m_filterLock); ret = m_watches.size() ? m_watches.rbegin()->first + 1 : 0; - m_watches[ret] = ClientWatch(_h); + m_watches[ret] = ClientWatch(_h, _r); cwatch << "+++" << ret << _h.abridged(); } auto ch = logs(ret); @@ -268,7 +268,7 @@ unsigned Client::installWatch(h256 _h) return ret; } -unsigned Client::installWatch(LogFilter const& _f) +unsigned Client::installWatch(LogFilter const& _f, Reaping _r) { h256 h = _f.sha3(); { @@ -279,7 +279,7 @@ unsigned Client::installWatch(LogFilter const& _f) m_filters.insert(make_pair(h, _f)); } } - return installWatch(h); + return installWatch(h, _r); } bool Client::uninstallWatch(unsigned _i) @@ -692,7 +692,7 @@ void Client::doWork() { Guard l(m_filterLock); for (auto key: keysOf(m_watches)) - if (chrono::system_clock::now() - m_watches[key].lastPoll > chrono::seconds(20)) + if (m_watches[key].lastPoll != chrono::system_clock::time_point::max() && chrono::system_clock::now() - m_watches[key].lastPoll > chrono::seconds(20)) { toUninstall.push_back(key); cnote << "GC: Uninstall" << key << "(" << chrono::duration_cast(chrono::system_clock::now() - m_watches[key].lastPoll).count() << "s old)"; diff --git a/libethereum/Client.h b/libethereum/Client.h index 04798ecdb..02d8ef6f8 100644 --- a/libethereum/Client.h +++ b/libethereum/Client.h @@ -92,7 +92,7 @@ static const LocalisedLogEntry InitialChange(SpecialLogEntry, 0); struct ClientWatch { ClientWatch(): lastPoll(std::chrono::system_clock::now()) {} - explicit ClientWatch(h256 _id): id(_id), lastPoll(std::chrono::system_clock::now()) {} + explicit ClientWatch(h256 _id, Reaping _r): id(_id), lastPoll(_r == Reaping::Automatic ? std::chrono::system_clock::now() : std::chrono::system_clock::time_point::max()) {} h256 id; LocalisedLogEntries changes = LocalisedLogEntries{ InitialChange }; @@ -246,8 +246,8 @@ public: virtual bytes codeAt(Address _a, int _block) const; virtual std::map storageAt(Address _a, int _block) const; - virtual unsigned installWatch(LogFilter const& _filter) override; - virtual unsigned installWatch(h256 _filterId) override; + virtual unsigned installWatch(LogFilter const& _filter, Reaping _r = Reaping::Automatic) override; + virtual unsigned installWatch(h256 _filterId, Reaping _r = Reaping::Automatic) override; virtual bool uninstallWatch(unsigned _watchId) override; virtual LocalisedLogEntries peekWatch(unsigned _watchId) const; virtual LocalisedLogEntries checkWatch(unsigned _watchId); diff --git a/libethereum/Interface.h b/libethereum/Interface.h index 728cb5030..abf7c0a2d 100644 --- a/libethereum/Interface.h +++ b/libethereum/Interface.h @@ -39,6 +39,12 @@ namespace eth using TransactionHashes = h256s; +enum class Reaping +{ + Automatic, + Manual +}; + /** * @brief Main API hub for interfacing with Ethereum. */ @@ -92,8 +98,8 @@ public: virtual LocalisedLogEntries logs(LogFilter const& _filter) const = 0; /// Install, uninstall and query watches. - virtual unsigned installWatch(LogFilter const& _filter) = 0; - virtual unsigned installWatch(h256 _filterId) = 0; + virtual unsigned installWatch(LogFilter const& _filter, Reaping _r = Reaping::Automatic) = 0; + virtual unsigned installWatch(h256 _filterId, Reaping _r = Reaping::Automatic) = 0; virtual bool uninstallWatch(unsigned _watchId) = 0; LocalisedLogEntries peekWatchSafe(unsigned _watchId) const { try { return peekWatch(_watchId); } catch (...) { return LocalisedLogEntries(); } } LocalisedLogEntries checkWatchSafe(unsigned _watchId) { try { return checkWatch(_watchId); } catch (...) { return LocalisedLogEntries(); } } From 1e0201142f1e581a0d1c616f98091cc2e12dc85e Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Sat, 14 Mar 2015 20:15:15 +0100 Subject: [PATCH 5/5] Mix fix for previous commit. --- mix/MixClient.cpp | 10 ++++++---- mix/MixClient.h | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/mix/MixClient.cpp b/mix/MixClient.cpp index a8619f843..e088a093b 100644 --- a/mix/MixClient.cpp +++ b/mix/MixClient.cpp @@ -40,6 +40,8 @@ namespace dev namespace mix { +// TODO: merge as much as possible with the Client.cpp into a mutually inherited base class. + const Secret c_defaultUserAccountSecret = Secret("cb73d9408c4720e230387d956eb0f829d8a4dd2c1055f96257167e14e7169074"); const u256 c_mixGenesisDifficulty = c_minimumDifficulty; //TODO: make it lower for Mix somehow @@ -360,13 +362,13 @@ eth::LocalisedLogEntries MixClient::logs(eth::LogFilter const& _f) const return ret; } -unsigned MixClient::installWatch(h256 _h) +unsigned MixClient::installWatch(h256 _h, eth::Reaping _r) { unsigned ret; { Guard l(m_filterLock); ret = m_watches.size() ? m_watches.rbegin()->first + 1 : 0; - m_watches[ret] = ClientWatch(_h); + m_watches[ret] = ClientWatch(_h, _r); } auto ch = logs(ret); if (ch.empty()) @@ -378,14 +380,14 @@ unsigned MixClient::installWatch(h256 _h) return ret; } -unsigned MixClient::installWatch(eth::LogFilter const& _f) +unsigned MixClient::installWatch(eth::LogFilter const& _f, eth::Reaping _r) { h256 h = _f.sha3(); { Guard l(m_filterLock); m_filters.insert(std::make_pair(h, _f)); } - return installWatch(h); + return installWatch(h, _r); } bool MixClient::uninstallWatch(unsigned _i) diff --git a/mix/MixClient.h b/mix/MixClient.h index ff85d6458..af5c8ec2b 100644 --- a/mix/MixClient.h +++ b/mix/MixClient.h @@ -60,8 +60,8 @@ public: std::map storageAt(Address _a, int _block) const override; eth::LocalisedLogEntries logs(unsigned _watchId) const override; eth::LocalisedLogEntries logs(eth::LogFilter const& _filter) const override; - unsigned installWatch(eth::LogFilter const& _filter) override; - unsigned installWatch(h256 _filterId) override; + unsigned installWatch(eth::LogFilter const& _filter, eth::Reaping _r = eth::Reaping::Automatic) override; + unsigned installWatch(h256 _filterId, eth::Reaping _r = eth::Reaping::Automatic) override; bool uninstallWatch(unsigned _watchId) override; eth::LocalisedLogEntries peekWatch(unsigned _watchId) const override; eth::LocalisedLogEntries checkWatch(unsigned _watchId) override;