From 26c2470516a0fad6f0800b9b1683b41e9569c97b Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Tue, 10 Mar 2015 11:40:30 +0100 Subject: [PATCH] eth_call on block with number --- libethereum/Client.cpp | 4 ++-- libethereum/Client.h | 2 +- libethereum/Interface.h | 2 +- libweb3jsonrpc/WebThreeStubServerBase.cpp | 6 ++++-- libweb3jsonrpc/WebThreeStubServerBase.h | 2 +- libweb3jsonrpc/abstractwebthreestubserver.h | 6 +++--- libweb3jsonrpc/spec.json | 2 +- mix/MixClient.cpp | 4 ++-- mix/MixClient.h | 2 +- mix/Web3Server.cpp | 4 ++-- mix/Web3Server.h | 2 +- test/webthreestubclient.h | 3 ++- 12 files changed, 21 insertions(+), 18 deletions(-) diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index 18376c071..c8510e00c 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -493,7 +493,7 @@ void Client::transact(Secret _secret, u256 _value, Address _dest, bytes const& _ m_tq.attemptImport(t.rlp()); } -bytes Client::call(Secret _secret, u256 _value, Address _dest, bytes const& _data, u256 _gas, u256 _gasPrice) +bytes Client::call(Secret _secret, u256 _value, Address _dest, bytes const& _data, u256 _gas, u256 _gasPrice, int _blockNumber) { bytes out; try @@ -503,7 +503,7 @@ bytes Client::call(Secret _secret, u256 _value, Address _dest, bytes const& _dat // cdebug << "Nonce at " << toAddress(_secret) << " pre:" << m_preMine.transactionsFrom(toAddress(_secret)) << " post:" << m_postMine.transactionsFrom(toAddress(_secret)); { ReadGuard l(x_stateDB); - temp = m_postMine; + temp = asOf(_blockNumber); n = temp.transactionsFrom(toAddress(_secret)); } Transaction t(_value, _gasPrice, _gas, _dest, _data, n, _secret); diff --git a/libethereum/Client.h b/libethereum/Client.h index 39a9fd49e..61d0c824c 100644 --- a/libethereum/Client.h +++ b/libethereum/Client.h @@ -226,7 +226,7 @@ public: virtual void flushTransactions(); /// Makes the given call. Nothing is recorded into the state. - virtual bytes call(Secret _secret, u256 _value, Address _dest, bytes const& _data = bytes(), u256 _gas = 10000, u256 _gasPrice = 10 * szabo); + virtual bytes call(Secret _secret, u256 _value, Address _dest, bytes const& _data = bytes(), u256 _gas = 10000, u256 _gasPrice = 10 * szabo, int _blockNumber = 0); /// Makes the given call. Nothing is recorded into the state. This cheats by creating a null address and endowing it with a lot of ETH. virtual bytes call(Address _dest, bytes const& _data = bytes(), u256 _gas = 125000, u256 _value = 0, u256 _gasPrice = 1 * ether); diff --git a/libethereum/Interface.h b/libethereum/Interface.h index 56d24116d..2c57ae58e 100644 --- a/libethereum/Interface.h +++ b/libethereum/Interface.h @@ -67,7 +67,7 @@ public: virtual void flushTransactions() = 0; /// Makes the given call. Nothing is recorded into the state. - virtual bytes call(Secret _secret, u256 _value, Address _dest, bytes const& _data = bytes(), u256 _gas = 10000, u256 _gasPrice = 10 * szabo) = 0; + virtual bytes call(Secret _secret, u256 _value, Address _dest, bytes const& _data = bytes(), u256 _gas = 10000, u256 _gasPrice = 10 * szabo, int _blockNumber = 0) = 0; // [STATE-QUERY API] diff --git a/libweb3jsonrpc/WebThreeStubServerBase.cpp b/libweb3jsonrpc/WebThreeStubServerBase.cpp index 6ba14a682..75c480850 100644 --- a/libweb3jsonrpc/WebThreeStubServerBase.cpp +++ b/libweb3jsonrpc/WebThreeStubServerBase.cpp @@ -526,13 +526,15 @@ string WebThreeStubServerBase::eth_sendTransaction(Json::Value const& _json) } -string WebThreeStubServerBase::eth_call(Json::Value const& _json) +string WebThreeStubServerBase::eth_call(Json::Value const& _json, string const& _blockNumber) { TransactionSkeleton t; + int number; try { t = toTransaction(_json); + number = toBlockNumber(_blockNumber); } catch (...) { @@ -548,7 +550,7 @@ string WebThreeStubServerBase::eth_call(Json::Value const& _json) t.gasPrice = 10 * dev::eth::szabo; if (!t.gas) t.gas = min(client()->gasLimitRemaining(), client()->balanceAt(t.from) / t.gasPrice); - ret = toJS(client()->call(m_accounts->secretKey(t.from), t.value, t.to, t.data, t.gas, t.gasPrice)); + ret = toJS(client()->call(m_accounts->secretKey(t.from), t.value, t.to, t.data, t.gas, t.gasPrice, number)); return ret; } diff --git a/libweb3jsonrpc/WebThreeStubServerBase.h b/libweb3jsonrpc/WebThreeStubServerBase.h index 128dcc1af..6b926251b 100644 --- a/libweb3jsonrpc/WebThreeStubServerBase.h +++ b/libweb3jsonrpc/WebThreeStubServerBase.h @@ -87,7 +87,7 @@ public: 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_sendTransaction(Json::Value const& _json); - virtual std::string eth_call(Json::Value const& _json); + virtual std::string eth_call(Json::Value const& _json, std::string const& _blockNumber); virtual bool eth_flush(); virtual Json::Value eth_getBlockByHash(std::string const& _blockHash, bool _includeTransactions); virtual Json::Value eth_getBlockByNumber(std::string const& _blockNumber, bool _includeTransactions); diff --git a/libweb3jsonrpc/abstractwebthreestubserver.h b/libweb3jsonrpc/abstractwebthreestubserver.h index a24988e27..fa9952f11 100644 --- a/libweb3jsonrpc/abstractwebthreestubserver.h +++ b/libweb3jsonrpc/abstractwebthreestubserver.h @@ -30,7 +30,7 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServerbindAndAddMethod(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_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, 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_getBlockByHash", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_OBJECT, "param1",jsonrpc::JSON_STRING,"param2",jsonrpc::JSON_BOOLEAN, NULL), &AbstractWebThreeStubServer::eth_getBlockByHashI); this->bindAndAddMethod(jsonrpc::Procedure("eth_getBlockByNumber", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_OBJECT, "param1",jsonrpc::JSON_STRING,"param2",jsonrpc::JSON_BOOLEAN, NULL), &AbstractWebThreeStubServer::eth_getBlockByNumberI); @@ -148,7 +148,7 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServereth_call(request[0u]); + response = this->eth_call(request[0u], request[1u].asString()); } inline virtual void eth_flushI(const Json::Value &request, Json::Value &response) { @@ -308,7 +308,7 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServerCallMethod("eth_call",p); if (result.isString()) return result.asString();