Browse Source

jsonrpc in progress

cl-refactor
Marek Kotewicz 10 years ago
parent
commit
00bbca9997
  1. 150
      eth/EthStubServer.cpp
  2. 20
      eth/EthStubServer.h
  3. 52
      eth/abstractethstubserver.h
  4. 16
      eth/eth.js
  5. 16
      eth/spec.json
  6. 16
      libdevcore/CommonJS.h

150
eth/EthStubServer.cpp

@ -20,7 +20,7 @@
* @date 2014 * @date 2014
*/ */
#if ETH_JSONRPC //#if ETH_JSONRPC
#include "EthStubServer.h" #include "EthStubServer.h"
#include <libevmface/Instruction.h> #include <libevmface/Instruction.h>
#include <liblll/Compiler.h> #include <liblll/Compiler.h>
@ -37,69 +37,141 @@ EthStubServer::EthStubServer(jsonrpc::AbstractServerConnector* _conn, WebThreeDi
{ {
} }
dev::eth::Client& EthStubServer::ethereum() const dev::eth::Interface* EthStubServer::client() const
{ {
return *m_web3.ethereum(); return &(*m_web3.ethereum());
} }
std::string EthStubServer::balanceAt(const string &a, const string &block) std::string EthStubServer::balanceAt(const string &a, const int& block)
{ {
return toJS(client()->balanceAt(jsToAddress(a), block));
} }
std::string EthStubServer::block(const string &numberOrHash) //TODO BlockDetails?
Json::Value EthStubServer::block(const string &numberOrHash)
{ {
auto n = jsToU256(numberOrHash);
auto h = n < client()->number() ? client()->hashFromNumber((unsigned)n) : ::jsToFixed<32>(numberOrHash);
Json::Value res;
BlockInfo bi = client()->blockInfo(h);
res["hash"] = boost::lexical_cast<string>(bi.hash);
res["parentHash"] = boost::lexical_cast<string>(bi.parentHash);
res["sha3Uncles"] = boost::lexical_cast<string>(bi.sha3Uncles);
res["miner"] = boost::lexical_cast<string>(bi.coinbaseAddress);
res["stateRoot"] = boost::lexical_cast<string>(bi.stateRoot);
res["transactionsRoot"] = boost::lexical_cast<string>(bi.transactionsRoot);
res["difficulty"] = boost::lexical_cast<string>(bi.difficulty);
res["number"] = boost::lexical_cast<string>(bi.number);
res["minGasPrice"] = boost::lexical_cast<string>(bi.minGasPrice);
res["gasLimit"] = boost::lexical_cast<string>(bi.gasLimit);
res["timestamp"] = boost::lexical_cast<string>(bi.timestamp);
res["extraData"] = jsFromBinary(bi.extraData);
res["nonce"] = boost::lexical_cast<string>(bi.nonce);
return res;
} }
std::string EthStubServer::call(const string &json) static TransactionJS toTransaction(const Json::Value &json)
{ {
TransactionJS ret;
if (!json.isObject() || json.empty()){
return ret;
}
if (!json["from"].empty())
ret.from = jsToSecret(json["from"].asString());
if (!json["to"].empty())
ret.to = jsToAddress(json["to"].asString());
if (!json["value"].empty())
ret.value = jsToU256(json["value"].asString());
if (!json["gas"].empty())
ret.gas = jsToU256(json["gas"].asString());
if (!json["gasPrice"].empty())
ret.gasPrice = jsToU256(json["gasPrice"].asString());
if (!json["data"].empty() || json["code"].empty() || json["dataclose"].empty())
{
if (json["data"].isString())
ret.data = jsToBytes(json["data"].asString());
else if (json["code"].isString())
ret.data = jsToBytes(json["code"].asString());
else if (json["data"].isArray())
for (auto i: json["data"])
dev::operator +=(ret.data, asBytes(jsPadded(i.asString(), 32)));
else if (json["code"].isArray())
for (auto i: json["code"])
dev::operator +=(ret.data, asBytes(jsPadded(i.asString(), 32)));
else if (json["dataclose"].isArray())
for (auto i: json["dataclose"])
dev::operator +=(ret.data, jsToBytes(i.asString()));
}
return ret;
} }
std::string EthStubServer::codeAt(const string &a, const string &block) std::string EthStubServer::call(const Json::Value &json)
{ {
std::string ret;
if (!client())
return ret;
TransactionJS t = toTransaction(json);
if (!t.to)
return ret;
if (!t.from && m_keys.size())
t.from = m_keys[0].secret();
if (!t.gasPrice)
t.gasPrice = 10 * dev::eth::szabo;
if (!t.gas)
t.gas = client()->balanceAt(KeyPair(t.from).address()) / t.gasPrice;
ret = toJS(client()->call(t.from, t.value, t.to, t.data, t.gas, t.gasPrice));
return ret;
}
std::string EthStubServer::codeAt(const string &a, const int& block)
{
return client() ? jsFromBinary(client()->codeAt(jsToAddress(a), block)) : "";
} }
std::string EthStubServer::coinbase() std::string EthStubServer::coinbase()
{ {
return client() ? toJS(client()->address()) : "";
} }
int EthStubServer::countAt(const string &a, const string &block) std::string EthStubServer::countAt(const string &a, const int& block)
{ {
return client() ? toJS(client()->countAt(jsToAddress(a), block)) : "";
} }
int EthStubServer::defaultBlock() int EthStubServer::defaultBlock()
{ {
return client() ? client()->getDefault() : 0;
} }
std::string EthStubServer::fromAscii(const string &s) std::string EthStubServer::fromAscii(const int& padding, const std::string& s)
{ {
return jsFromBinary(s, padding);
} }
std::string EthStubServer::fromFixed(const string &s) double EthStubServer::fromFixed(const string &s)
{ {
return jsFromFixed(s);
} }
std::string EthStubServer::gasPrice() std::string EthStubServer::gasPrice()
{ {
return toJS(10 * dev::eth::szabo);
} }
//TODO
bool EthStubServer::isListening() bool EthStubServer::isListening()
{ {
return /*client() ? client()->haveNetwork() :*/ false;
} }
bool EthStubServer::isMining() bool EthStubServer::isMining()
{ {
return client() ? client()->isMining() : false;
} }
std::string EthStubServer::key() std::string EthStubServer::key()
@ -119,7 +191,7 @@ Json::Value EthStubServer::keys()
std::string EthStubServer::lll(const string &s) std::string EthStubServer::lll(const string &s)
{ {
return toJS(dev::eth::compileLLL(s));
} }
std::string EthStubServer::messages(const string &json) std::string EthStubServer::messages(const string &json)
@ -157,7 +229,7 @@ std::string EthStubServer::sha3(const string &s)
} }
std::string EthStubServer::stateAt(const string &a, const string &block, const string &p) std::string EthStubServer::stateAt(const string &a, const int& block, const string &p)
{ {
} }
@ -200,24 +272,24 @@ std::string EthStubServer::watch(const string &json)
Json::Value EthStubServer::blockJson(const std::string& _hash) Json::Value EthStubServer::blockJson(const std::string& _hash)
{ {
Json::Value res; Json::Value res;
auto const& bc = ethereum().blockChain(); // auto const& bc = client()->blockChain();
auto b = _hash.length() ? bc.block(h256(_hash)) : bc.block(); // auto b = _hash.length() ? bc.block(h256(_hash)) : bc.block();
auto bi = BlockInfo(b); // auto bi = BlockInfo(b);
res["number"] = boost::lexical_cast<string>(bi.number); // res["number"] = boost::lexical_cast<string>(bi.number);
res["hash"] = boost::lexical_cast<string>(bi.hash); // res["hash"] = boost::lexical_cast<string>(bi.hash);
res["parentHash"] = boost::lexical_cast<string>(bi.parentHash); // res["parentHash"] = boost::lexical_cast<string>(bi.parentHash);
res["sha3Uncles"] = boost::lexical_cast<string>(bi.sha3Uncles); // res["sha3Uncles"] = boost::lexical_cast<string>(bi.sha3Uncles);
res["coinbaseAddress"] = boost::lexical_cast<string>(bi.coinbaseAddress); // res["coinbaseAddress"] = boost::lexical_cast<string>(bi.coinbaseAddress);
res["stateRoot"] = boost::lexical_cast<string>(bi.stateRoot); // res["stateRoot"] = boost::lexical_cast<string>(bi.stateRoot);
res["transactionsRoot"] = boost::lexical_cast<string>(bi.transactionsRoot); // res["transactionsRoot"] = boost::lexical_cast<string>(bi.transactionsRoot);
res["minGasPrice"] = boost::lexical_cast<string>(bi.minGasPrice); // res["minGasPrice"] = boost::lexical_cast<string>(bi.minGasPrice);
res["gasLimit"] = boost::lexical_cast<string>(bi.gasLimit); // res["gasLimit"] = boost::lexical_cast<string>(bi.gasLimit);
res["gasUsed"] = boost::lexical_cast<string>(bi.gasUsed); // res["gasUsed"] = boost::lexical_cast<string>(bi.gasUsed);
res["difficulty"] = boost::lexical_cast<string>(bi.difficulty); // res["difficulty"] = boost::lexical_cast<string>(bi.difficulty);
res["timestamp"] = boost::lexical_cast<string>(bi.timestamp); // res["timestamp"] = boost::lexical_cast<string>(bi.timestamp);
res["nonce"] = boost::lexical_cast<string>(bi.nonce); // res["nonce"] = boost::lexical_cast<string>(bi.nonce);
return res; return res;
} }
@ -236,4 +308,4 @@ Json::Value EthStubServer::jsontypeToValue(int _jsontype)
} }
} }
#endif //#endif

20
eth/EthStubServer.h

@ -29,22 +29,22 @@
#include "abstractethstubserver.h" #include "abstractethstubserver.h"
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
namespace dev { class WebThreeDirect; namespace eth { class Client; } class KeyPair; } namespace dev { class WebThreeDirect; namespace eth { class Interface; } class KeyPair; }
class EthStubServer: public AbstractEthStubServer class EthStubServer: public AbstractEthStubServer
{ {
public: public:
EthStubServer(jsonrpc::AbstractServerConnector* _conn, dev::WebThreeDirect& _web3); EthStubServer(jsonrpc::AbstractServerConnector* _conn, dev::WebThreeDirect& _web3);
virtual std::string balanceAt(const std::string& a, const std::string& block); virtual std::string balanceAt(const std::string& a, const int& block);
virtual std::string block(const std::string& numberOrHash); virtual Json::Value block(const std::string& numberOrHash);
virtual std::string call(const std::string& json); virtual std::string call(const Json::Value& json);
virtual std::string codeAt(const std::string& a, const std::string& block); virtual std::string codeAt(const std::string& a, const int& block);
virtual std::string coinbase(); virtual std::string coinbase();
virtual int countAt(const std::string& a, const std::string& block); virtual std::string countAt(const std::string& a, const int& block);
virtual int defaultBlock(); virtual int defaultBlock();
virtual std::string fromAscii(const std::string& s); virtual std::string fromAscii(const int& padding, const std::string& s);
virtual std::string fromFixed(const std::string& s); virtual double fromFixed(const std::string& s);
virtual std::string gasPrice(); virtual std::string gasPrice();
virtual bool isListening(); virtual bool isListening();
virtual bool isMining(); virtual bool isMining();
@ -58,7 +58,7 @@ public:
virtual std::string setListening(const std::string& l); virtual std::string setListening(const std::string& l);
virtual std::string setMining(const std::string& l); virtual std::string setMining(const std::string& l);
virtual std::string sha3(const std::string& s); virtual std::string sha3(const std::string& s);
virtual std::string stateAt(const std::string& a, const std::string& block, const std::string& p); virtual std::string stateAt(const std::string& a, const int& block, const std::string& p);
virtual std::string toAscii(const std::string& s); virtual std::string toAscii(const std::string& s);
virtual std::string toDecimal(const std::string& s); virtual std::string toDecimal(const std::string& s);
virtual std::string toFixed(const std::string& s); virtual std::string toFixed(const std::string& s);
@ -69,7 +69,7 @@ public:
void setKeys(std::vector<dev::KeyPair> _keys) { m_keys = _keys; } void setKeys(std::vector<dev::KeyPair> _keys) { m_keys = _keys; }
private: private:
dev::eth::Client& ethereum() const; dev::eth::Interface* client() const;
dev::WebThreeDirect& m_web3; dev::WebThreeDirect& m_web3;
std::vector<dev::KeyPair> m_keys; std::vector<dev::KeyPair> m_keys;
Json::Value jsontypeToValue(int); Json::Value jsontypeToValue(int);

52
eth/abstractethstubserver.h

@ -2,8 +2,8 @@
* THIS FILE IS GENERATED BY jsonrpcstub, DO NOT CHANGE IT!!!!! * THIS FILE IS GENERATED BY jsonrpcstub, DO NOT CHANGE IT!!!!!
*/ */
#ifndef _AbstractEthStubServer_H_ #ifndef _ABSTRACTETHSTUBSERVER_H_
#define _AbstractEthStubServer_H_ #define _ABSTRACTETHSTUBSERVER_H_
#include <jsonrpc/rpc.h> #include <jsonrpc/rpc.h>
@ -11,17 +11,17 @@ class AbstractEthStubServer : public jsonrpc::AbstractServer<AbstractEthStubServ
{ {
public: public:
AbstractEthStubServer(jsonrpc::AbstractServerConnector* conn) : AbstractEthStubServer(jsonrpc::AbstractServerConnector* conn) :
jsonrpc::AbstractServer<AbstractEthStubServer>(conn) jsonrpc::AbstractServer<AbstractEthStubServer>(conn)
{ {
this->bindAndAddMethod(new jsonrpc::Procedure("balanceAt", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "a",jsonrpc::JSON_STRING,"block",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::balanceAtI); this->bindAndAddMethod(new jsonrpc::Procedure("balanceAt", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "a",jsonrpc::JSON_STRING,"block",jsonrpc::JSON_INTEGER, NULL), &AbstractEthStubServer::balanceAtI);
this->bindAndAddMethod(new jsonrpc::Procedure("block", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "numberOrHash",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::blockI); this->bindAndAddMethod(new jsonrpc::Procedure("block", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_ARRAY, "numberOrHash",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::blockI);
this->bindAndAddMethod(new jsonrpc::Procedure("call", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "json",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::callI); this->bindAndAddMethod(new jsonrpc::Procedure("call", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "json",jsonrpc::JSON_ARRAY, NULL), &AbstractEthStubServer::callI);
this->bindAndAddMethod(new jsonrpc::Procedure("codeAt", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "a",jsonrpc::JSON_STRING,"block",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::codeAtI); this->bindAndAddMethod(new jsonrpc::Procedure("codeAt", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "a",jsonrpc::JSON_STRING,"block",jsonrpc::JSON_INTEGER, NULL), &AbstractEthStubServer::codeAtI);
this->bindAndAddMethod(new jsonrpc::Procedure("coinbase", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::coinbaseI); this->bindAndAddMethod(new jsonrpc::Procedure("coinbase", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::coinbaseI);
this->bindAndAddMethod(new jsonrpc::Procedure("countAt", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_INTEGER, "a",jsonrpc::JSON_STRING,"block",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::countAtI); this->bindAndAddMethod(new jsonrpc::Procedure("countAt", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "a",jsonrpc::JSON_STRING,"block",jsonrpc::JSON_INTEGER, NULL), &AbstractEthStubServer::countAtI);
this->bindAndAddMethod(new jsonrpc::Procedure("defaultBlock", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_INTEGER, NULL), &AbstractEthStubServer::defaultBlockI); this->bindAndAddMethod(new jsonrpc::Procedure("defaultBlock", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_INTEGER, NULL), &AbstractEthStubServer::defaultBlockI);
this->bindAndAddMethod(new jsonrpc::Procedure("fromAscii", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "s",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::fromAsciiI); this->bindAndAddMethod(new jsonrpc::Procedure("fromAscii", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "padding",jsonrpc::JSON_INTEGER,"s",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::fromAsciiI);
this->bindAndAddMethod(new jsonrpc::Procedure("fromFixed", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "s",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::fromFixedI); this->bindAndAddMethod(new jsonrpc::Procedure("fromFixed", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_REAL, "s",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::fromFixedI);
this->bindAndAddMethod(new jsonrpc::Procedure("gasPrice", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::gasPriceI); this->bindAndAddMethod(new jsonrpc::Procedure("gasPrice", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::gasPriceI);
this->bindAndAddMethod(new jsonrpc::Procedure("isListening", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_BOOLEAN, NULL), &AbstractEthStubServer::isListeningI); this->bindAndAddMethod(new jsonrpc::Procedure("isListening", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_BOOLEAN, NULL), &AbstractEthStubServer::isListeningI);
this->bindAndAddMethod(new jsonrpc::Procedure("isMining", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_BOOLEAN, NULL), &AbstractEthStubServer::isMiningI); this->bindAndAddMethod(new jsonrpc::Procedure("isMining", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_BOOLEAN, NULL), &AbstractEthStubServer::isMiningI);
@ -35,7 +35,7 @@ class AbstractEthStubServer : public jsonrpc::AbstractServer<AbstractEthStubServ
this->bindAndAddMethod(new jsonrpc::Procedure("setListening", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "l",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::setListeningI); this->bindAndAddMethod(new jsonrpc::Procedure("setListening", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "l",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::setListeningI);
this->bindAndAddMethod(new jsonrpc::Procedure("setMining", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "l",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::setMiningI); this->bindAndAddMethod(new jsonrpc::Procedure("setMining", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "l",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::setMiningI);
this->bindAndAddMethod(new jsonrpc::Procedure("sha3", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "s",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::sha3I); this->bindAndAddMethod(new jsonrpc::Procedure("sha3", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "s",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::sha3I);
this->bindAndAddMethod(new jsonrpc::Procedure("stateAt", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "a",jsonrpc::JSON_STRING,"block",jsonrpc::JSON_STRING,"p",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::stateAtI); this->bindAndAddMethod(new jsonrpc::Procedure("stateAt", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "a",jsonrpc::JSON_STRING,"block",jsonrpc::JSON_INTEGER,"p",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::stateAtI);
this->bindAndAddMethod(new jsonrpc::Procedure("toAscii", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "s",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::toAsciiI); this->bindAndAddMethod(new jsonrpc::Procedure("toAscii", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "s",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::toAsciiI);
this->bindAndAddMethod(new jsonrpc::Procedure("toDecimal", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "s",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::toDecimalI); this->bindAndAddMethod(new jsonrpc::Procedure("toDecimal", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "s",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::toDecimalI);
this->bindAndAddMethod(new jsonrpc::Procedure("toFixed", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "s",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::toFixedI); this->bindAndAddMethod(new jsonrpc::Procedure("toFixed", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "s",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::toFixedI);
@ -48,7 +48,7 @@ class AbstractEthStubServer : public jsonrpc::AbstractServer<AbstractEthStubServ
inline virtual void balanceAtI(const Json::Value& request, Json::Value& response) inline virtual void balanceAtI(const Json::Value& request, Json::Value& response)
{ {
response = this->balanceAt(request["a"].asString(), request["block"].asString()); response = this->balanceAt(request["a"].asString(), request["block"].asInt());
} }
inline virtual void blockI(const Json::Value& request, Json::Value& response) inline virtual void blockI(const Json::Value& request, Json::Value& response)
@ -58,12 +58,12 @@ class AbstractEthStubServer : public jsonrpc::AbstractServer<AbstractEthStubServ
inline virtual void callI(const Json::Value& request, Json::Value& response) inline virtual void callI(const Json::Value& request, Json::Value& response)
{ {
response = this->call(request["json"].asString()); response = this->call(request["json"]);
} }
inline virtual void codeAtI(const Json::Value& request, Json::Value& response) inline virtual void codeAtI(const Json::Value& request, Json::Value& response)
{ {
response = this->codeAt(request["a"].asString(), request["block"].asString()); response = this->codeAt(request["a"].asString(), request["block"].asInt());
} }
inline virtual void coinbaseI(const Json::Value& request, Json::Value& response) inline virtual void coinbaseI(const Json::Value& request, Json::Value& response)
@ -73,7 +73,7 @@ class AbstractEthStubServer : public jsonrpc::AbstractServer<AbstractEthStubServ
inline virtual void countAtI(const Json::Value& request, Json::Value& response) inline virtual void countAtI(const Json::Value& request, Json::Value& response)
{ {
response = this->countAt(request["a"].asString(), request["block"].asString()); response = this->countAt(request["a"].asString(), request["block"].asInt());
} }
inline virtual void defaultBlockI(const Json::Value& request, Json::Value& response) inline virtual void defaultBlockI(const Json::Value& request, Json::Value& response)
@ -83,7 +83,7 @@ class AbstractEthStubServer : public jsonrpc::AbstractServer<AbstractEthStubServ
inline virtual void fromAsciiI(const Json::Value& request, Json::Value& response) inline virtual void fromAsciiI(const Json::Value& request, Json::Value& response)
{ {
response = this->fromAscii(request["s"].asString()); response = this->fromAscii(request["padding"].asInt(), request["s"].asString());
} }
inline virtual void fromFixedI(const Json::Value& request, Json::Value& response) inline virtual void fromFixedI(const Json::Value& request, Json::Value& response)
@ -158,7 +158,7 @@ class AbstractEthStubServer : public jsonrpc::AbstractServer<AbstractEthStubServ
inline virtual void stateAtI(const Json::Value& request, Json::Value& response) inline virtual void stateAtI(const Json::Value& request, Json::Value& response)
{ {
response = this->stateAt(request["a"].asString(), request["block"].asString(), request["p"].asString()); response = this->stateAt(request["a"].asString(), request["block"].asInt(), request["p"].asString());
} }
inline virtual void toAsciiI(const Json::Value& request, Json::Value& response) inline virtual void toAsciiI(const Json::Value& request, Json::Value& response)
@ -197,15 +197,15 @@ class AbstractEthStubServer : public jsonrpc::AbstractServer<AbstractEthStubServ
} }
virtual std::string balanceAt(const std::string& a, const std::string& block) = 0; virtual std::string balanceAt(const std::string& a, const int& block) = 0;
virtual std::string block(const std::string& numberOrHash) = 0; virtual Json::Value block(const std::string& numberOrHash) = 0;
virtual std::string call(const std::string& json) = 0; virtual std::string call(const Json::Value& json) = 0;
virtual std::string codeAt(const std::string& a, const std::string& block) = 0; virtual std::string codeAt(const std::string& a, const int& block) = 0;
virtual std::string coinbase() = 0; virtual std::string coinbase() = 0;
virtual int countAt(const std::string& a, const std::string& block) = 0; virtual std::string countAt(const std::string& a, const int& block) = 0;
virtual int defaultBlock() = 0; virtual int defaultBlock() = 0;
virtual std::string fromAscii(const std::string& s) = 0; virtual std::string fromAscii(const int& padding, const std::string& s) = 0;
virtual std::string fromFixed(const std::string& s) = 0; virtual double fromFixed(const std::string& s) = 0;
virtual std::string gasPrice() = 0; virtual std::string gasPrice() = 0;
virtual bool isListening() = 0; virtual bool isListening() = 0;
virtual bool isMining() = 0; virtual bool isMining() = 0;
@ -219,7 +219,7 @@ class AbstractEthStubServer : public jsonrpc::AbstractServer<AbstractEthStubServ
virtual std::string setListening(const std::string& l) = 0; virtual std::string setListening(const std::string& l) = 0;
virtual std::string setMining(const std::string& l) = 0; virtual std::string setMining(const std::string& l) = 0;
virtual std::string sha3(const std::string& s) = 0; virtual std::string sha3(const std::string& s) = 0;
virtual std::string stateAt(const std::string& a, const std::string& block, const std::string& p) = 0; virtual std::string stateAt(const std::string& a, const int& block, const std::string& p) = 0;
virtual std::string toAscii(const std::string& s) = 0; virtual std::string toAscii(const std::string& s) = 0;
virtual std::string toDecimal(const std::string& s) = 0; virtual std::string toDecimal(const std::string& s) = 0;
virtual std::string toFixed(const std::string& s) = 0; virtual std::string toFixed(const std::string& s) = 0;
@ -229,4 +229,4 @@ class AbstractEthStubServer : public jsonrpc::AbstractServer<AbstractEthStubServ
virtual std::string watch(const std::string& json) = 0; virtual std::string watch(const std::string& json) = 0;
}; };
#endif //_AbstractEthStubServer_H_ #endif //_ABSTRACTETHSTUBSERVER_H_

16
eth/eth.js

@ -31,17 +31,17 @@ var spec = [
{ "method": "number", "params": null, "order": [], "returns" : 0}, { "method": "number", "params": null, "order": [], "returns" : 0},
// synchronous getters // synchronous getters
{ "method": "balanceAt", "params": { "a": "", "block": ""}, "order": ["a", "block"], "returns" : ""}, { "method": "balanceAt", "params": { "a": "", "block": 0}, "order": ["a", "block"], "returns" : ""},
{ "method": "stateAt", "params": { "a": "", "p": "", "block": ""}, "order": ["a", "p", "block"], "returns": ""}, { "method": "stateAt", "params": { "a": "", "p": "", "block": 0}, "order": ["a", "p", "block"], "returns": ""},
{ "method": "countAt", "params": { "a": "", "block": ""}, "order": ["a", "block"], "returns" : 0}, { "method": "countAt", "params": { "a": "", "block": 0}, "order": ["a", "block"], "returns" : ""},
{ "method": "codeAt", "params": { "a": "", "block": ""}, "order": ["a", "block"], "returns": ""}, { "method": "codeAt", "params": { "a": "", "block": 0}, "order": ["a", "block"], "returns": ""},
// transactions // transactions
{ "method": "transact", "params": { "json": ""}, "order": ["json"], "returns": ""}, { "method": "transact", "params": { "json": ""}, "order": ["json"], "returns": ""},
{ "method": "call", "params": { "json": ""}, "order": ["json"], "returns": ""}, { "method": "call", "params": { "json": []}, "order": ["json"], "returns": ""},
// blockchain // blockchain
{ "method": "block", "params": { "numberOrHash": ""}, "order": ["numberOrHash"], "returns": ""}, { "method": "block", "params": { "numberOrHash": ""}, "order": ["numberOrHash"], "returns": []},
{ "method": "transaction", "params": { "numberOrHash": "", "i": ""}, "order": ["numberOrHash", "i"], "returns": ""}, { "method": "transaction", "params": { "numberOrHash": "", "i": ""}, "order": ["numberOrHash", "i"], "returns": ""},
{ "method": "uncle", "params": { "numberOrHash": "", "i": ""}, "order": ["numberOrHash", "i"], "returns": ""}, { "method": "uncle", "params": { "numberOrHash": "", "i": ""}, "order": ["numberOrHash", "i"], "returns": ""},
@ -54,10 +54,10 @@ var spec = [
{ "method": "lll", "params": { "s": ""}, "order": ["s"], "returns": ""}, { "method": "lll", "params": { "s": ""}, "order": ["s"], "returns": ""},
{ "method": "sha3", "params": { "s": ""}, "order": ["s"], "returns": ""}, // TODO other sha3 { "method": "sha3", "params": { "s": ""}, "order": ["s"], "returns": ""}, // TODO other sha3
{ "method": "toAscii", "params": { "s": ""}, "order": ["s"], "returns": ""}, { "method": "toAscii", "params": { "s": ""}, "order": ["s"], "returns": ""},
{ "method": "fromAscii", "params": { "s": ""}, "order": ["s"], "returns": ""}, // TODO padding { "method": "fromAscii", "params": { "s": "", "padding": 0}, "order": ["s", "padding"], "returns": ""},
{ "method": "toDecimal", "params": {"s": ""}, "order": ["s"], "returns" : ""}, { "method": "toDecimal", "params": {"s": ""}, "order": ["s"], "returns" : ""},
{ "method": "toFixed", "params": {"s": ""}, "order": ["s"], "returns" : ""}, { "method": "toFixed", "params": {"s": ""}, "order": ["s"], "returns" : ""},
{ "method": "fromFixed", "params": {"s": ""}, "order": ["s"], "returns" : ""}, { "method": "fromFixed", "params": {"s": ""}, "order": ["s"], "returns" : 0.0},
{ "method": "offset", "params": {"s": "", "offset": ""}, "order": ["s", "offset"], "returns" : ""}, { "method": "offset", "params": {"s": "", "offset": ""}, "order": ["s", "offset"], "returns" : ""},
]; ];

16
eth/spec.json

@ -12,15 +12,15 @@
{ "method": "number", "params": null, "order": [], "returns" : 0}, { "method": "number", "params": null, "order": [], "returns" : 0},
{ "method": "balanceAt", "params": { "a": "", "block": ""}, "order": ["a", "block"], "returns" : ""}, { "method": "balanceAt", "params": { "a": "", "block": 0}, "order": ["a", "block"], "returns" : ""},
{ "method": "stateAt", "params": { "a": "", "p": "", "block": ""}, "order": ["a", "p", "block"], "returns": ""}, { "method": "stateAt", "params": { "a": "", "p": "", "block": 0}, "order": ["a", "p", "block"], "returns": ""},
{ "method": "countAt", "params": { "a": "", "block": ""}, "order": ["a", "block"], "returns" : 0}, { "method": "countAt", "params": { "a": "", "block": 0}, "order": ["a", "block"], "returns" : ""},
{ "method": "codeAt", "params": { "a": "", "block": ""}, "order": ["a", "block"], "returns": ""}, { "method": "codeAt", "params": { "a": "", "block": 0}, "order": ["a", "block"], "returns": ""},
{ "method": "transact", "params": { "json": ""}, "order": ["json"], "returns": ""}, { "method": "transact", "params": { "json": ""}, "order": ["json"], "returns": ""},
{ "method": "call", "params": { "json": ""}, "order": ["json"], "returns": ""}, { "method": "call", "params": { "json": []}, "order": ["json"], "returns": ""},
{ "method": "block", "params": { "numberOrHash": ""}, "order": ["numberOrHash"], "returns": ""}, { "method": "block", "params": { "numberOrHash": ""}, "order": ["numberOrHash"], "returns": []},
{ "method": "transaction", "params": { "numberOrHash": "", "i": ""}, "order": ["numberOrHash", "i"], "returns": ""}, { "method": "transaction", "params": { "numberOrHash": "", "i": ""}, "order": ["numberOrHash", "i"], "returns": ""},
{ "method": "uncle", "params": { "numberOrHash": "", "i": ""}, "order": ["numberOrHash", "i"], "returns": ""}, { "method": "uncle", "params": { "numberOrHash": "", "i": ""}, "order": ["numberOrHash", "i"], "returns": ""},
@ -31,10 +31,10 @@
{ "method": "lll", "params": { "s": ""}, "order": ["s"], "returns": ""}, { "method": "lll", "params": { "s": ""}, "order": ["s"], "returns": ""},
{ "method": "sha3", "params": { "s": ""}, "order": ["s"], "returns": ""}, { "method": "sha3", "params": { "s": ""}, "order": ["s"], "returns": ""},
{ "method": "toAscii", "params": { "s": ""}, "order": ["s"], "returns": ""}, { "method": "toAscii", "params": { "s": ""}, "order": ["s"], "returns": ""},
{ "method": "fromAscii", "params": { "s": ""}, "order": ["s"], "returns": ""}, { "method": "fromAscii", "params": { "s": "", "padding": 0}, "order": ["s", "padding"], "returns": ""},
{ "method": "toDecimal", "params": {"s": ""}, "order": ["s"], "returns" : ""}, { "method": "toDecimal", "params": {"s": ""}, "order": ["s"], "returns" : ""},
{ "method": "toFixed", "params": {"s": ""}, "order": ["s"], "returns" : ""}, { "method": "toFixed", "params": {"s": ""}, "order": ["s"], "returns" : ""},
{ "method": "fromFixed", "params": {"s": ""}, "order": ["s"], "returns" : ""} { "method": "fromFixed", "params": {"s": ""}, "order": ["s"], "returns" : 0.0}
] ]

16
libdevcore/CommonJS.h

@ -65,6 +65,22 @@ inline std::string jsFromBinary(std::string const& _s, unsigned _padding = 32)
return jsFromBinary(asBytes(_s), _padding); return jsFromBinary(asBytes(_s), _padding);
} }
inline double jsFromFixed(std::string const& _s)
{
return (double)jsToU256(_s) / (double)(dev::u256(1) << 128);
}
struct TransactionJS
{
Secret from;
Address to;
u256 value;
bytes data;
u256 gas;
u256 gasPrice;
};
} }
} }

Loading…
Cancel
Save