Browse Source

contract calls working from js

cl-refactor
Marek Kotewicz 10 years ago
parent
commit
ed7cbeaacd
  1. 6
      libweb3jsonrpc/WebThreeStubServer.cpp
  2. 2
      libweb3jsonrpc/WebThreeStubServer.h
  3. 6
      libweb3jsonrpc/abstractwebthreestubserver.h
  4. 2
      libweb3jsonrpc/spec.json
  5. 3
      test/webthreestubclient.h

6
libweb3jsonrpc/WebThreeStubServer.cpp

@ -538,7 +538,7 @@ static bytes toMethodCall(int const& _index, Json::Value const& _params)
return data;
}
std::string WebThreeStubServer::eth_contractCall(std::string const& _address, int const& _index, Json::Value const& _params)
std::string WebThreeStubServer::eth_contractCall(std::string const& _address, std::string const& _bytes)
{
auto from = m_accounts.begin()->first;
for (auto a: m_accounts)
@ -549,8 +549,8 @@ std::string WebThreeStubServer::eth_contractCall(std::string const& _address, in
auto gasPrice = 10 * dev::eth::szabo;
auto gas = min<u256>(client()->gasLimitRemaining(), client()->balanceAt(from) / gasPrice);
auto bytes = toMethodCall(_index, _params);
return toJS(client()->call(m_accounts[from].secret(), 0, jsToAddress(_address), toMethodCall(_index, _params), gas, gasPrice));
auto bytes = jsToBytes(_bytes);
return toJS(client()->call(m_accounts[from].secret(), 0, jsToAddress(_address), bytes, gas, gasPrice));
}
std::string WebThreeStubServer::eth_contractCreate(std::string const& _bytecode)

2
libweb3jsonrpc/WebThreeStubServer.h

@ -73,7 +73,7 @@ public:
virtual std::string eth_codeAt(std::string const& _address);
virtual std::string eth_coinbase();
virtual Json::Value eth_compilers();
virtual std::string eth_contractCall(std::string const& _address, int const& _index, Json::Value const& _params);
virtual std::string eth_contractCall(std::string const& _address, std::string const& _bytes);
virtual std::string eth_contractCreate(std::string const& _bytecode);
virtual double eth_countAt(std::string const& _address);
virtual int eth_defaultBlock();

6
libweb3jsonrpc/abstractwebthreestubserver.h

@ -26,7 +26,7 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
this->bindAndAddMethod(new jsonrpc::Procedure("eth_codeAt", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_codeAtI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_coinbase", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_coinbaseI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_compilers", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_ARRAY, NULL), &AbstractWebThreeStubServer::eth_compilersI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_contractCall", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING,"param2",jsonrpc::JSON_INTEGER,"param3",jsonrpc::JSON_ARRAY, NULL), &AbstractWebThreeStubServer::eth_contractCallI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_contractCall", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING,"param2",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_contractCallI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_contractCreate", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_contractCreateI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_countAt", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_REAL, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_countAtI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_defaultBlock", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::eth_defaultBlockI);
@ -129,7 +129,7 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
inline virtual void eth_contractCallI(const Json::Value& request, Json::Value& response)
{
response = this->eth_contractCall(request[0u].asString(), request[1u].asInt(), request[2u]);
response = this->eth_contractCall(request[0u].asString(), request[1u].asString());
}
inline virtual void eth_contractCreateI(const Json::Value& request, Json::Value& response)
@ -306,7 +306,7 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
virtual std::string eth_codeAt(const std::string& param1) = 0;
virtual std::string eth_coinbase() = 0;
virtual Json::Value eth_compilers() = 0;
virtual std::string eth_contractCall(const std::string& param1, const int& param2, const Json::Value& param3) = 0;
virtual std::string eth_contractCall(const std::string& param1, const std::string& param2) = 0;
virtual std::string eth_contractCreate(const std::string& param1) = 0;
virtual double eth_countAt(const std::string& param1) = 0;
virtual int eth_defaultBlock() = 0;

2
libweb3jsonrpc/spec.json

@ -31,7 +31,7 @@
{ "method": "eth_lll", "params": [""], "order": [], "returns": ""},
{ "method": "eth_solidity", "params": [""], "order": [], "returns": ""},
{ "method": "eth_contractCreate", "params": [""], "order": [], "returns": ""},
{ "method": "eth_contractCall", "params": ["", 0, []], "order": [], "returns": ""},
{ "method": "eth_contractCall", "params": ["", ""], "order": [], "returns": ""},
{ "method": "eth_newFilter", "params": [{}], "order": [], "returns": 0},
{ "method": "eth_newFilterString", "params": [""], "order": [], "returns": 0},

3
test/webthreestubclient.h

@ -191,12 +191,11 @@ p.append(param3);
}
std::string eth_contractCall(const std::string& param1, const int& param2, const Json::Value& param3) throw (jsonrpc::JsonRpcException)
std::string eth_contractCall(const std::string& param1, const std::string& param2) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p.append(param1);
p.append(param2);
p.append(param3);
Json::Value result = this->client->CallMethod("eth_contractCall",p);
if (result.isString())

Loading…
Cancel
Save