Browse Source

contract create and contract call working

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

18
libweb3jsonrpc/WebThreeStubServer.cpp

@ -528,19 +528,17 @@ Json::Value WebThreeStubServer::eth_compilers()
return ret;
}
static bytes paramsToBytes(Json::Value const& _params)
static bytes toMethodCall(int const& _index, Json::Value const& _params)
{
bytes data;
bytes data(1, _index);
if (_params.isArray())
for (auto i: _params)
// data += asBytes(i.asString());
// data += toBigEndian(jsToU256(i.asString()));
data += asBytes(jsPadded(i.asString(), 33));
data += asBytes(jsPadded(i.asString(), 32));
cwarn << data;
return data;
}
std::string WebThreeStubServer::eth_contractCall(std::string const& _address, std::string const& _value, Json::Value const& _params)
std::string WebThreeStubServer::eth_contractCall(std::string const& _address, int const& _index, Json::Value const& _params)
{
auto from = m_accounts.begin()->first;
for (auto a: m_accounts)
@ -551,11 +549,11 @@ std::string WebThreeStubServer::eth_contractCall(std::string const& _address, st
auto gasPrice = 10 * dev::eth::szabo;
auto gas = min<u256>(client()->gasLimitRemaining(), client()->balanceAt(from) / gasPrice);
auto bytes = paramsToBytes(_params);
return toJS(client()->call(m_accounts[from].secret(), jsToU256(_value), jsToAddress(_address), paramsToBytes(_params), gas, gasPrice));
auto bytes = toMethodCall(_index, _params);
return toJS(client()->call(m_accounts[from].secret(), 0, jsToAddress(_address), toMethodCall(_index, _params), gas, gasPrice));
}
std::string WebThreeStubServer::eth_contractCreate(std::string const& _bytecode, std::string const& _value)
std::string WebThreeStubServer::eth_contractCreate(std::string const& _bytecode)
{
auto from = m_accounts.begin()->first;
for (auto a: m_accounts)
@ -566,7 +564,7 @@ std::string WebThreeStubServer::eth_contractCreate(std::string const& _bytecode,
auto gasPrice = 10 * dev::eth::szabo;
auto gas = min<u256>(client()->gasLimitRemaining(), client()->balanceAt(from) / gasPrice);
return toJS(client()->transact(m_accounts[from].secret(), jsToU256(_value), jsToBytes(_bytecode), gas, gasPrice));
return toJS(client()->transact(m_accounts[from].secret(), 0, jsToBytes(_bytecode), gas, gasPrice));
}
std::string WebThreeStubServer::eth_lll(std::string const& _code)

4
libweb3jsonrpc/WebThreeStubServer.h

@ -73,8 +73,8 @@ 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, std::string const& _value, Json::Value const& _params);
virtual std::string eth_contractCreate(std::string const& _bytecode, std::string const& _value);
virtual std::string eth_contractCall(std::string const& _address, int const& _index, Json::Value const& _params);
virtual std::string eth_contractCreate(std::string const& _bytecode);
virtual double eth_countAt(std::string const& _address);
virtual int eth_defaultBlock();
virtual std::string eth_gasPrice();

12
libweb3jsonrpc/abstractwebthreestubserver.h

@ -26,8 +26,8 @@ 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_STRING,"param3",jsonrpc::JSON_ARRAY, NULL), &AbstractWebThreeStubServer::eth_contractCallI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_contractCreate", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING,"param2",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_contractCreateI);
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_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);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_gasPrice", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_gasPriceI);
@ -129,12 +129,12 @@ 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].asString(), request[2u]);
response = this->eth_contractCall(request[0u].asString(), request[1u].asInt(), request[2u]);
}
inline virtual void eth_contractCreateI(const Json::Value& request, Json::Value& response)
{
response = this->eth_contractCreate(request[0u].asString(), request[1u].asString());
response = this->eth_contractCreate(request[0u].asString());
}
inline virtual void eth_countAtI(const Json::Value& request, Json::Value& response)
@ -306,8 +306,8 @@ 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 std::string& param2, const Json::Value& param3) = 0;
virtual std::string eth_contractCreate(const std::string& param1, const std::string& param2) = 0;
virtual std::string eth_contractCall(const std::string& param1, const int& param2, const Json::Value& param3) = 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;
virtual std::string eth_gasPrice() = 0;

4
libweb3jsonrpc/spec.json

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

5
test/webthreestubclient.h

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

Loading…
Cancel
Save