Browse Source

eth_call on block with number

cl-refactor
Marek Kotewicz 10 years ago
parent
commit
26c2470516
  1. 4
      libethereum/Client.cpp
  2. 2
      libethereum/Client.h
  3. 2
      libethereum/Interface.h
  4. 6
      libweb3jsonrpc/WebThreeStubServerBase.cpp
  5. 2
      libweb3jsonrpc/WebThreeStubServerBase.h
  6. 6
      libweb3jsonrpc/abstractwebthreestubserver.h
  7. 2
      libweb3jsonrpc/spec.json
  8. 4
      mix/MixClient.cpp
  9. 2
      mix/MixClient.h
  10. 4
      mix/Web3Server.cpp
  11. 2
      mix/Web3Server.h
  12. 3
      test/webthreestubclient.h

4
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);

2
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);

2
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]

6
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<u256>(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;
}

2
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);

6
libweb3jsonrpc/abstractwebthreestubserver.h

@ -30,7 +30,7 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
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_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::AbstractServer<AbstractWebThr
}
inline virtual void eth_callI(const Json::Value &request, Json::Value &response)
{
response = this->eth_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::AbstractServer<AbstractWebThr
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_sendTransaction(const Json::Value& param1) = 0;
virtual std::string eth_call(const Json::Value& param1) = 0;
virtual std::string eth_call(const Json::Value& param1, const std::string& param2) = 0;
virtual bool eth_flush() = 0;
virtual Json::Value eth_getBlockByHash(const std::string& param1, bool param2) = 0;
virtual Json::Value eth_getBlockByNumber(const std::string& param1, bool param2) = 0;

2
libweb3jsonrpc/spec.json

@ -19,7 +19,7 @@
{ "name": "eth_getUncleCountByBlockNumber", "params": [""], "order": [], "returns" : ""},
{ "name": "eth_getData", "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_getBlockByHash", "params": ["", false],"order": [], "returns": {}},
{ "name": "eth_getBlockByNumber", "params": ["", false],"order": [], "returns": {}},

4
mix/MixClient.cpp

@ -274,13 +274,13 @@ void MixClient::flushTransactions()
{
}
bytes MixClient::call(Secret _secret, u256 _value, Address _dest, bytes const& _data, u256 _gas, u256 _gasPrice)
bytes MixClient::call(Secret _secret, u256 _value, Address _dest, bytes const& _data, u256 _gas, u256 _gasPrice, int _blockNumber)
{
u256 n;
State temp;
{
ReadGuard lr(x_state);
temp = m_state;
temp = asOf(_blockNumber);
n = temp.transactionsFrom(toAddress(_secret));
}
Transaction t(_value, _gasPrice, _gas, _dest, _data, n, _secret);

2
mix/MixClient.h

@ -52,7 +52,7 @@ public:
Address transact(Secret _secret, u256 _endowment, bytes const& _init, u256 _gas, u256 _gasPrice) override;
void inject(bytesConstRef _rlp) override;
void flushTransactions() override;
bytes call(Secret _secret, u256 _value, Address _dest, bytes const& _data, u256 _gas, u256 _gasPrice) override;
bytes call(Secret _secret, u256 _value, Address _dest, bytes const& _data, u256 _gas, u256 _gasPrice, int _blockNumber) override;
u256 balanceAt(Address _a, int _block) const override;
u256 countAt(Address _a, int _block) const override;
u256 stateAt(Address _a, u256 _l, int _block) const override;

4
mix/Web3Server.cpp

@ -67,9 +67,9 @@ std::string Web3Server::eth_sendTransaction(Json::Value const& _json)
return ret;
}
std::string Web3Server::eth_call(Json::Value const& _json)
std::string Web3Server::eth_call(Json::Value const& _json, std::string const& _blockNumber)
{
std::string ret = WebThreeStubServerBase::eth_call(_json);
std::string ret = WebThreeStubServerBase::eth_call(_json, _blockNumber);
emit newTransaction();
return ret;
}

2
mix/Web3Server.h

@ -46,7 +46,7 @@ signals:
protected:
virtual Json::Value eth_getFilterChanges(std::string const& _filterId) override;
virtual std::string eth_sendTransaction(Json::Value const& _json) override;
virtual std::string eth_call(Json::Value const& _json) override;
virtual std::string eth_call(Json::Value const& _json, std::string const& _blockNumber) override;
private:
dev::eth::Interface* client() override { return m_client; }

3
test/webthreestubclient.h

@ -198,10 +198,11 @@ class WebThreeStubClient : public jsonrpc::Client
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
std::string eth_call(const Json::Value& param1) throw (jsonrpc::JsonRpcException)
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();

Loading…
Cancel
Save