Browse Source

Merge remote-tracking branch 'upstream/develop' into addTests

cl-refactor
CJentzsch 10 years ago
parent
commit
837f45ca57
  1. 2
      alethzero/MainWin.cpp
  2. 10
      libethereum/Client.cpp
  3. 6
      libethereum/Client.h
  4. 10
      libethereum/Interface.h
  5. 4
      libjsqrc/CMakeLists.txt
  6. 5
      libjsqrc/ethereumjs/dist/ethereum.js
  7. 5
      libjsqrc/ethereumjs/lib/web3/eth.js
  8. 2
      libjsqrc/ethereumjs/test/eth.methods.js
  9. 1
      libweb3jsonrpc/CMakeLists.txt
  10. 81
      libweb3jsonrpc/WebThreeStubServerBase.cpp
  11. 3
      libweb3jsonrpc/WebThreeStubServerBase.h
  12. 14
      libweb3jsonrpc/abstractwebthreestubserver.h
  13. 3
      libweb3jsonrpc/spec.json
  14. 10
      mix/MixClient.cpp
  15. 4
      mix/MixClient.h
  16. 15
      test/webthreestubclient.h

2
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) 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; m_handlers[ret] = _f;
return ret; return ret;
} }

10
libethereum/Client.cpp

@ -249,13 +249,13 @@ void Client::clearPending()
noteChanged(changeds); noteChanged(changeds);
} }
unsigned Client::installWatch(h256 _h) unsigned Client::installWatch(h256 _h, Reaping _r)
{ {
unsigned ret; unsigned ret;
{ {
Guard l(m_filterLock); Guard l(m_filterLock);
ret = m_watches.size() ? m_watches.rbegin()->first + 1 : 0; 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(); cwatch << "+++" << ret << _h.abridged();
} }
auto ch = logs(ret); auto ch = logs(ret);
@ -268,7 +268,7 @@ unsigned Client::installWatch(h256 _h)
return ret; return ret;
} }
unsigned Client::installWatch(LogFilter const& _f) unsigned Client::installWatch(LogFilter const& _f, Reaping _r)
{ {
h256 h = _f.sha3(); h256 h = _f.sha3();
{ {
@ -279,7 +279,7 @@ unsigned Client::installWatch(LogFilter const& _f)
m_filters.insert(make_pair(h, _f)); m_filters.insert(make_pair(h, _f));
} }
} }
return installWatch(h); return installWatch(h, _r);
} }
bool Client::uninstallWatch(unsigned _i) bool Client::uninstallWatch(unsigned _i)
@ -692,7 +692,7 @@ void Client::doWork()
{ {
Guard l(m_filterLock); Guard l(m_filterLock);
for (auto key: keysOf(m_watches)) 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); toUninstall.push_back(key);
cnote << "GC: Uninstall" << key << "(" << chrono::duration_cast<chrono::seconds>(chrono::system_clock::now() - m_watches[key].lastPoll).count() << "s old)"; cnote << "GC: Uninstall" << key << "(" << chrono::duration_cast<chrono::seconds>(chrono::system_clock::now() - m_watches[key].lastPoll).count() << "s old)";

6
libethereum/Client.h

@ -92,7 +92,7 @@ static const LocalisedLogEntry InitialChange(SpecialLogEntry, 0);
struct ClientWatch struct ClientWatch
{ {
ClientWatch(): lastPoll(std::chrono::system_clock::now()) {} 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; h256 id;
LocalisedLogEntries changes = LocalisedLogEntries{ InitialChange }; LocalisedLogEntries changes = LocalisedLogEntries{ InitialChange };
@ -246,8 +246,8 @@ public:
virtual bytes codeAt(Address _a, int _block) const; virtual bytes codeAt(Address _a, int _block) const;
virtual std::map<u256, u256> storageAt(Address _a, int _block) const; virtual std::map<u256, u256> storageAt(Address _a, int _block) const;
virtual unsigned installWatch(LogFilter const& _filter) override; virtual unsigned installWatch(LogFilter const& _filter, Reaping _r = Reaping::Automatic) override;
virtual unsigned installWatch(h256 _filterId) override; virtual unsigned installWatch(h256 _filterId, Reaping _r = Reaping::Automatic) override;
virtual bool uninstallWatch(unsigned _watchId) override; virtual bool uninstallWatch(unsigned _watchId) override;
virtual LocalisedLogEntries peekWatch(unsigned _watchId) const; virtual LocalisedLogEntries peekWatch(unsigned _watchId) const;
virtual LocalisedLogEntries checkWatch(unsigned _watchId); virtual LocalisedLogEntries checkWatch(unsigned _watchId);

10
libethereum/Interface.h

@ -39,6 +39,12 @@ namespace eth
using TransactionHashes = h256s; using TransactionHashes = h256s;
enum class Reaping
{
Automatic,
Manual
};
/** /**
* @brief Main API hub for interfacing with Ethereum. * @brief Main API hub for interfacing with Ethereum.
*/ */
@ -92,8 +98,8 @@ public:
virtual LocalisedLogEntries logs(LogFilter const& _filter) const = 0; virtual LocalisedLogEntries logs(LogFilter const& _filter) const = 0;
/// Install, uninstall and query watches. /// Install, uninstall and query watches.
virtual unsigned installWatch(LogFilter const& _filter) = 0; virtual unsigned installWatch(LogFilter const& _filter, Reaping _r = Reaping::Automatic) = 0;
virtual unsigned installWatch(h256 _filterId) = 0; virtual unsigned installWatch(h256 _filterId, Reaping _r = Reaping::Automatic) = 0;
virtual bool uninstallWatch(unsigned _watchId) = 0; virtual bool uninstallWatch(unsigned _watchId) = 0;
LocalisedLogEntries peekWatchSafe(unsigned _watchId) const { try { return peekWatch(_watchId); } catch (...) { return LocalisedLogEntries(); } } LocalisedLogEntries peekWatchSafe(unsigned _watchId) const { try { return peekWatch(_watchId); } catch (...) { return LocalisedLogEntries(); } }
LocalisedLogEntries checkWatchSafe(unsigned _watchId) { try { return checkWatch(_watchId); } catch (...) { return LocalisedLogEntries(); } } LocalisedLogEntries checkWatchSafe(unsigned _watchId) { try { return checkWatch(_watchId); } catch (...) { return LocalisedLogEntries(); } }

4
libjsqrc/CMakeLists.txt

@ -23,3 +23,7 @@ if (USENPM)
endif() endif()
install( TARGETS jsqrc RUNTIME DESTINATION bin ARCHIVE DESTINATION lib LIBRARY DESTINATION lib ) install( TARGETS jsqrc RUNTIME DESTINATION bin ARCHIVE DESTINATION lib LIBRARY DESTINATION lib )
file(GLOB_RECURSE JSFILES "ethereumjs/lib/*.js")
add_custom_target(aux_js SOURCES ${JSFILES})

5
libjsqrc/ethereumjs/dist/ethereum.js

@ -1726,10 +1726,9 @@ var uncleCountCall = function (args) {
var methods = [ var methods = [
{ name: 'getBalance', call: 'eth_getBalance', addDefaultblock: 2, { name: 'getBalance', call: 'eth_getBalance', addDefaultblock: 2,
outputFormatter: formatters.convertToBigNumber}, outputFormatter: formatters.convertToBigNumber},
{ name: 'getStorage', call: 'eth_getStorage', addDefaultblock: 2},
{ name: 'getStorageAt', call: 'eth_getStorageAt', addDefaultblock: 3, { name: 'getStorageAt', call: 'eth_getStorageAt', addDefaultblock: 3,
inputFormatter: utils.toHex}, inputFormatter: utils.toHex},
{ name: 'getData', call: 'eth_getData', addDefaultblock: 2}, { name: 'getCode', call: 'eth_getCode', addDefaultblock: 2},
{ name: 'getBlock', call: blockCall, { name: 'getBlock', call: blockCall,
outputFormatter: formatters.outputBlockFormatter, outputFormatter: formatters.outputBlockFormatter,
inputFormatter: [utils.toHex, function(param){ return (!param) ? false : true; }]}, inputFormatter: [utils.toHex, function(param){ return (!param) ? false : true; }]},
@ -1764,7 +1763,7 @@ var methods = [
{ name: 'stateAt', call: 'eth_stateAt', newMethod: 'eth.getStorageAt' }, { name: 'stateAt', call: 'eth_stateAt', newMethod: 'eth.getStorageAt' },
{ name: 'storageAt', call: 'eth_storageAt', newMethod: 'eth.getStorage' }, { name: 'storageAt', call: 'eth_storageAt', newMethod: 'eth.getStorage' },
{ name: 'countAt', call: 'eth_countAt', newMethod: 'eth.getTransactionCount' }, { 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: 'transact', call: 'eth_transact', newMethod: 'eth.sendTransaction' },
{ name: 'block', call: blockCall, newMethod: 'eth.getBlock' }, { name: 'block', call: blockCall, newMethod: 'eth.getBlock' },
{ name: 'transaction', call: transactionFromBlockCall, newMethod: 'eth.getTransaction' }, { name: 'transaction', call: transactionFromBlockCall, newMethod: 'eth.getTransaction' },

5
libjsqrc/ethereumjs/lib/web3/eth.js

@ -75,10 +75,9 @@ var uncleCountCall = function (args) {
var methods = [ var methods = [
{ name: 'getBalance', call: 'eth_getBalance', addDefaultblock: 2, { name: 'getBalance', call: 'eth_getBalance', addDefaultblock: 2,
outputFormatter: formatters.convertToBigNumber}, outputFormatter: formatters.convertToBigNumber},
{ name: 'getStorage', call: 'eth_getStorage', addDefaultblock: 2},
{ name: 'getStorageAt', call: 'eth_getStorageAt', addDefaultblock: 3, { name: 'getStorageAt', call: 'eth_getStorageAt', addDefaultblock: 3,
inputFormatter: utils.toHex}, inputFormatter: utils.toHex},
{ name: 'getData', call: 'eth_getData', addDefaultblock: 2}, { name: 'getCode', call: 'eth_getCode', addDefaultblock: 2},
{ name: 'getBlock', call: blockCall, { name: 'getBlock', call: blockCall,
outputFormatter: formatters.outputBlockFormatter, outputFormatter: formatters.outputBlockFormatter,
inputFormatter: [utils.toHex, function(param){ return (!param) ? false : true; }]}, inputFormatter: [utils.toHex, function(param){ return (!param) ? false : true; }]},
@ -113,7 +112,7 @@ var methods = [
{ name: 'stateAt', call: 'eth_stateAt', newMethod: 'eth.getStorageAt' }, { name: 'stateAt', call: 'eth_stateAt', newMethod: 'eth.getStorageAt' },
{ name: 'storageAt', call: 'eth_storageAt', newMethod: 'eth.getStorage' }, { name: 'storageAt', call: 'eth_storageAt', newMethod: 'eth.getStorage' },
{ name: 'countAt', call: 'eth_countAt', newMethod: 'eth.getTransactionCount' }, { 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: 'transact', call: 'eth_transact', newMethod: 'eth.sendTransaction' },
{ name: 'block', call: blockCall, newMethod: 'eth.getBlock' }, { name: 'block', call: blockCall, newMethod: 'eth.getBlock' },
{ name: 'transaction', call: transactionFromBlockCall, newMethod: 'eth.getTransaction' }, { name: 'transaction', call: transactionFromBlockCall, newMethod: 'eth.getTransaction' },

2
libjsqrc/ethereumjs/test/eth.methods.js

@ -8,7 +8,7 @@ describe('web3', function() {
u.methodExists(web3.eth, 'getStorageAt'); u.methodExists(web3.eth, 'getStorageAt');
u.methodExists(web3.eth, 'getStorage'); u.methodExists(web3.eth, 'getStorage');
u.methodExists(web3.eth, 'getTransactionCount'); u.methodExists(web3.eth, 'getTransactionCount');
u.methodExists(web3.eth, 'getData'); u.methodExists(web3.eth, 'getCode');
u.methodExists(web3.eth, 'sendTransaction'); u.methodExists(web3.eth, 'sendTransaction');
u.methodExists(web3.eth, 'call'); u.methodExists(web3.eth, 'call');
u.methodExists(web3.eth, 'getBlock'); u.methodExists(web3.eth, 'getBlock');

1
libweb3jsonrpc/CMakeLists.txt

@ -56,4 +56,5 @@ endif()
install( TARGETS ${EXECUTABLE} RUNTIME DESTINATION bin ARCHIVE DESTINATION lib LIBRARY DESTINATION lib ) install( TARGETS ${EXECUTABLE} RUNTIME DESTINATION bin ARCHIVE DESTINATION lib LIBRARY DESTINATION lib )
install( FILES ${HEADERS} DESTINATION include/${EXECUTABLE} ) install( FILES ${HEADERS} DESTINATION include/${EXECUTABLE} )
add_custom_target(aux_json SOURCES "spec.json")

81
libweb3jsonrpc/WebThreeStubServerBase.cpp

@ -295,162 +295,99 @@ string WebThreeStubServerBase::eth_blockNumber()
string WebThreeStubServerBase::eth_getBalance(string const& _address, string const& _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 try
{ {
address = jsToAddress(_address); return toJS(client()->balanceAt(jsToAddress(_address), toBlockNumber(_blockNumber)));
number = toBlockNumber(_blockNumber);
} }
catch (...) catch (...)
{ {
BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INVALID_PARAMS)); 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) string WebThreeStubServerBase::eth_getStorageAt(string const& _address, string const& _position, string const& _blockNumber)
{ {
Address address;
u256 position;
int number;
try try
{ {
address = jsToAddress(_address); return toJS(client()->stateAt(jsToAddress(_address), jsToU256(_position), toBlockNumber(_blockNumber)));
position = jsToU256(_position);
number = toBlockNumber(_blockNumber);
} }
catch (...) catch (...)
{ {
BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INVALID_PARAMS)); 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) string WebThreeStubServerBase::eth_getTransactionCount(string const& _address, string const& _blockNumber)
{ {
Address address;
int number;
try try
{ {
address = jsToAddress(_address); return toJS(client()->countAt(jsToAddress(_address), toBlockNumber(_blockNumber)));
number = toBlockNumber(_blockNumber);
} }
catch (...) catch (...)
{ {
BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INVALID_PARAMS)); BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INVALID_PARAMS));
} }
return toJS(client()->countAt(address, number));
} }
string WebThreeStubServerBase::eth_getBlockTransactionCountByHash(string const& _blockHash) string WebThreeStubServerBase::eth_getBlockTransactionCountByHash(string const& _blockHash)
{ {
h256 hash;
try try
{ {
hash = jsToFixed<32>(_blockHash); return toJS(client()->transactionCount(jsToFixed<32>(_blockHash)));
} }
catch (...) catch (...)
{ {
BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INVALID_PARAMS)); BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INVALID_PARAMS));
} }
return toJS(client()->transactionCount(hash));
} }
string WebThreeStubServerBase::eth_getBlockTransactionCountByNumber(string const& _blockNumber) string WebThreeStubServerBase::eth_getBlockTransactionCountByNumber(string const& _blockNumber)
{ {
int number;
try try
{ {
number = toBlockNumber(_blockNumber); return toJS(client()->transactionCount(client()->hashFromNumber(toBlockNumber(_blockNumber))));
} }
catch (...) catch (...)
{ {
BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INVALID_PARAMS)); BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INVALID_PARAMS));
} }
return toJS(client()->transactionCount(client()->hashFromNumber(number)));
} }
string WebThreeStubServerBase::eth_getUncleCountByBlockHash(string const& _blockHash) string WebThreeStubServerBase::eth_getUncleCountByBlockHash(string const& _blockHash)
{ {
h256 hash;
try try
{ {
hash = jsToFixed<32>(_blockHash); return toJS(client()->uncleCount(jsToFixed<32>(_blockHash)));
} }
catch (...) catch (...)
{ {
BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INVALID_PARAMS)); BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INVALID_PARAMS));
} }
return toJS(client()->uncleCount(hash));
} }
string WebThreeStubServerBase::eth_getUncleCountByBlockNumber(string const& _blockNumber) string WebThreeStubServerBase::eth_getUncleCountByBlockNumber(string const& _blockNumber)
{ {
int number;
try try
{ {
number = toBlockNumber(_blockNumber); return toJS(client()->uncleCount(client()->hashFromNumber(toBlockNumber(_blockNumber))));
} }
catch (...) catch (...)
{ {
BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INVALID_PARAMS)); BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INVALID_PARAMS));
} }
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;
try try
{ {
address = jsToAddress(_address); return toJS(client()->codeAt(jsToAddress(_address), toBlockNumber(_blockNumber)));
number = toBlockNumber(_blockNumber);
} }
catch (...) catch (...)
{ {
BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INVALID_PARAMS)); BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INVALID_PARAMS));
} }
return toJS(client()->codeAt(address, number));
} }
static TransactionSkeleton toTransaction(Json::Value const& _json) static TransactionSkeleton toTransaction(Json::Value const& _json)

3
libweb3jsonrpc/WebThreeStubServerBase.h

@ -80,14 +80,13 @@ public:
virtual Json::Value eth_accounts(); virtual Json::Value eth_accounts();
virtual std::string eth_blockNumber(); virtual std::string eth_blockNumber();
virtual std::string eth_getBalance(std::string const& _address, std::string const& _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_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_getTransactionCount(std::string const& _address, std::string const& _blockNumber);
virtual std::string eth_getBlockTransactionCountByHash(std::string const& _blockHash); virtual std::string eth_getBlockTransactionCountByHash(std::string const& _blockHash);
virtual std::string eth_getBlockTransactionCountByNumber(std::string const& _blockNumber); virtual std::string eth_getBlockTransactionCountByNumber(std::string const& _blockNumber);
virtual std::string eth_getUncleCountByBlockHash(std::string const& _blockHash); virtual std::string eth_getUncleCountByBlockHash(std::string const& _blockHash);
virtual std::string eth_getUncleCountByBlockNumber(std::string const& _blockNumber); 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_sendTransaction(Json::Value const& _json);
virtual std::string eth_call(Json::Value const& _json, std::string const& _blockNumber); virtual std::string eth_call(Json::Value const& _json, std::string const& _blockNumber);
virtual bool eth_flush(); virtual bool eth_flush();

14
libweb3jsonrpc/abstractwebthreestubserver.h

@ -23,14 +23,13 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
this->bindAndAddMethod(jsonrpc::Procedure("eth_accounts", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_ARRAY, NULL), &AbstractWebThreeStubServer::eth_accountsI); this->bindAndAddMethod(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_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_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_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_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_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_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_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_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_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_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_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); 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::AbstractServer<AbstractWebThr
{ {
response = this->eth_getBalance(request[0u].asString(), request[1u].asString()); response = this->eth_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) 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()); response = this->eth_getStorageAt(request[0u].asString(), request[1u].asString(), request[2u].asString());
@ -150,9 +145,9 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
{ {
response = this->eth_getUncleCountByBlockNumber(request[0u].asString()); response = this->eth_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_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) inline virtual void eth_sendTransactionI(const Json::Value &request, Json::Value &response)
{ {
@ -313,14 +308,13 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
virtual Json::Value eth_accounts() = 0; virtual Json::Value eth_accounts() = 0;
virtual std::string eth_blockNumber() = 0; virtual std::string eth_blockNumber() = 0;
virtual std::string eth_getBalance(const std::string& param1, const std::string& param2) = 0; virtual std::string eth_getBalance(const std::string& param1, const std::string& param2) = 0;
virtual Json::Value eth_getStorage(const std::string& param1, const std::string& param2) = 0;
virtual std::string eth_getStorageAt(const std::string& param1, const std::string& param2, const std::string& param3) = 0; virtual std::string eth_getStorageAt(const std::string& param1, const std::string& param2, const std::string& param3) = 0;
virtual std::string eth_getTransactionCount(const std::string& param1, const std::string& param2) = 0; virtual std::string eth_getTransactionCount(const std::string& param1, const std::string& param2) = 0;
virtual std::string eth_getBlockTransactionCountByHash(const std::string& param1) = 0; virtual std::string eth_getBlockTransactionCountByHash(const std::string& param1) = 0;
virtual std::string eth_getBlockTransactionCountByNumber(const std::string& param1) = 0; virtual std::string eth_getBlockTransactionCountByNumber(const std::string& param1) = 0;
virtual std::string eth_getUncleCountByBlockHash(const std::string& param1) = 0; virtual std::string eth_getUncleCountByBlockHash(const std::string& param1) = 0;
virtual std::string eth_getUncleCountByBlockNumber(const std::string& param1) = 0; virtual std::string eth_getUncleCountByBlockNumber(const std::string& param1) = 0;
virtual std::string eth_getData(const std::string& param1, const std::string& param2) = 0; virtual std::string eth_getCode(const std::string& param1, const std::string& param2) = 0;
virtual std::string eth_sendTransaction(const Json::Value& param1) = 0; virtual std::string eth_sendTransaction(const Json::Value& param1) = 0;
virtual std::string eth_call(const Json::Value& param1, const std::string& param2) = 0; virtual std::string eth_call(const Json::Value& param1, const std::string& param2) = 0;
virtual bool eth_flush() = 0; virtual bool eth_flush() = 0;

3
libweb3jsonrpc/spec.json

@ -12,14 +12,13 @@
{ "name": "eth_accounts", "params": [], "order": [], "returns" : [] }, { "name": "eth_accounts", "params": [], "order": [], "returns" : [] },
{ "name": "eth_blockNumber", "params": [], "order": [], "returns" : ""}, { "name": "eth_blockNumber", "params": [], "order": [], "returns" : ""},
{ "name": "eth_getBalance", "params": ["", ""], "order": [], "returns" : ""}, { "name": "eth_getBalance", "params": ["", ""], "order": [], "returns" : ""},
{ "name": "eth_getStorage", "params": ["", ""], "order": [], "returns": {}},
{ "name": "eth_getStorageAt", "params": ["", "", ""], "order": [], "returns": ""}, { "name": "eth_getStorageAt", "params": ["", "", ""], "order": [], "returns": ""},
{ "name": "eth_getTransactionCount", "params": ["", ""], "order": [], "returns" : ""}, { "name": "eth_getTransactionCount", "params": ["", ""], "order": [], "returns" : ""},
{ "name": "eth_getBlockTransactionCountByHash", "params": [""], "order": [], "returns" : ""}, { "name": "eth_getBlockTransactionCountByHash", "params": [""], "order": [], "returns" : ""},
{ "name": "eth_getBlockTransactionCountByNumber", "params": [""], "order": [], "returns" : ""}, { "name": "eth_getBlockTransactionCountByNumber", "params": [""], "order": [], "returns" : ""},
{ "name": "eth_getUncleCountByBlockHash", "params": [""], "order": [], "returns" : ""}, { "name": "eth_getUncleCountByBlockHash", "params": [""], "order": [], "returns" : ""},
{ "name": "eth_getUncleCountByBlockNumber", "params": [""], "order": [], "returns" : ""}, { "name": "eth_getUncleCountByBlockNumber", "params": [""], "order": [], "returns" : ""},
{ "name": "eth_getData", "params": ["", ""], "order": [], "returns": ""}, { "name": "eth_getCode", "params": ["", ""], "order": [], "returns": ""},
{ "name": "eth_sendTransaction", "params": [{}], "order": [], "returns": ""}, { "name": "eth_sendTransaction", "params": [{}], "order": [], "returns": ""},
{ "name": "eth_call", "params": [{}, ""], "order": [], "returns": ""}, { "name": "eth_call", "params": [{}, ""], "order": [], "returns": ""},
{ "name": "eth_flush", "params": [], "order": [], "returns" : true}, { "name": "eth_flush", "params": [], "order": [], "returns" : true},

10
mix/MixClient.cpp

@ -40,6 +40,8 @@ namespace dev
namespace mix 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 Secret c_defaultUserAccountSecret = Secret("cb73d9408c4720e230387d956eb0f829d8a4dd2c1055f96257167e14e7169074");
const u256 c_mixGenesisDifficulty = c_minimumDifficulty; //TODO: make it lower for Mix somehow 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; return ret;
} }
unsigned MixClient::installWatch(h256 _h) unsigned MixClient::installWatch(h256 _h, eth::Reaping _r)
{ {
unsigned ret; unsigned ret;
{ {
Guard l(m_filterLock); Guard l(m_filterLock);
ret = m_watches.size() ? m_watches.rbegin()->first + 1 : 0; 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); auto ch = logs(ret);
if (ch.empty()) if (ch.empty())
@ -378,14 +380,14 @@ unsigned MixClient::installWatch(h256 _h)
return ret; return ret;
} }
unsigned MixClient::installWatch(eth::LogFilter const& _f) unsigned MixClient::installWatch(eth::LogFilter const& _f, eth::Reaping _r)
{ {
h256 h = _f.sha3(); h256 h = _f.sha3();
{ {
Guard l(m_filterLock); Guard l(m_filterLock);
m_filters.insert(std::make_pair(h, _f)); m_filters.insert(std::make_pair(h, _f));
} }
return installWatch(h); return installWatch(h, _r);
} }
bool MixClient::uninstallWatch(unsigned _i) bool MixClient::uninstallWatch(unsigned _i)

4
mix/MixClient.h

@ -60,8 +60,8 @@ public:
std::map<u256, u256> storageAt(Address _a, int _block) const override; std::map<u256, u256> storageAt(Address _a, int _block) const override;
eth::LocalisedLogEntries logs(unsigned _watchId) const override; eth::LocalisedLogEntries logs(unsigned _watchId) const override;
eth::LocalisedLogEntries logs(eth::LogFilter const& _filter) const override; eth::LocalisedLogEntries logs(eth::LogFilter const& _filter) const override;
unsigned installWatch(eth::LogFilter const& _filter) override; unsigned installWatch(eth::LogFilter const& _filter, eth::Reaping _r = eth::Reaping::Automatic) override;
unsigned installWatch(h256 _filterId) override; unsigned installWatch(h256 _filterId, eth::Reaping _r = eth::Reaping::Automatic) override;
bool uninstallWatch(unsigned _watchId) override; bool uninstallWatch(unsigned _watchId) override;
eth::LocalisedLogEntries peekWatch(unsigned _watchId) const override; eth::LocalisedLogEntries peekWatch(unsigned _watchId) const override;
eth::LocalisedLogEntries checkWatch(unsigned _watchId) override; eth::LocalisedLogEntries checkWatch(unsigned _watchId) override;

15
test/webthreestubclient.h

@ -123,17 +123,6 @@ class WebThreeStubClient : public jsonrpc::Client
else else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
} }
Json::Value eth_getStorage(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_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) std::string eth_getStorageAt(const std::string& param1, const std::string& param2, const std::string& param3) throw (jsonrpc::JsonRpcException)
{ {
Json::Value p; Json::Value p;
@ -197,12 +186,12 @@ class WebThreeStubClient : public jsonrpc::Client
else else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
} }
std::string eth_getData(const std::string& param1, const std::string& param2) throw (jsonrpc::JsonRpcException) std::string eth_getCode(const std::string& param1, const std::string& param2) throw (jsonrpc::JsonRpcException)
{ {
Json::Value p; Json::Value p;
p.append(param1); p.append(param1);
p.append(param2); p.append(param2);
Json::Value result = this->CallMethod("eth_getData",p); Json::Value result = this->CallMethod("eth_getCode",p);
if (result.isString()) if (result.isString())
return result.asString(); return result.asString();
else else

Loading…
Cancel
Save