diff --git a/eth/abstractethstubserver.h b/eth/abstractethstubserver.h index 7f110513d..6b55852dd 100644 --- a/eth/abstractethstubserver.h +++ b/eth/abstractethstubserver.h @@ -2,8 +2,8 @@ * THIS FILE IS GENERATED BY jsonrpcstub, DO NOT CHANGE IT!!!!! */ -#ifndef _ABSTRACTETHSTUBSERVER_H_ -#define _ABSTRACTETHSTUBSERVER_H_ +#ifndef _ABSTRACTTEST.HSERVER_H_ +#define _ABSTRACTTEST.HSERVER_H_ #include @@ -11,44 +11,59 @@ class AbstractEthStubServer : public jsonrpc::AbstractServer(conn) - { - this->bindAndAddMethod(new jsonrpc::Procedure("balanceAt", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "a",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::balanceAtI); - this->bindAndAddMethod(new jsonrpc::Procedure("block", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, "a",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::blockI); - this->bindAndAddMethod(new jsonrpc::Procedure("check", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_ARRAY, "a",jsonrpc::JSON_ARRAY, NULL), &AbstractEthStubServer::checkI); - this->bindAndAddMethod(new jsonrpc::Procedure("coinbase", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::coinbaseI); - this->bindAndAddMethod(new jsonrpc::Procedure("create", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "bCode",jsonrpc::JSON_STRING,"sec",jsonrpc::JSON_STRING,"xEndowment",jsonrpc::JSON_STRING,"xGas",jsonrpc::JSON_STRING,"xGasPrice",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::createI); - this->bindAndAddMethod(new jsonrpc::Procedure("gasPrice", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::gasPriceI); - this->bindAndAddMethod(new jsonrpc::Procedure("isContractAt", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_BOOLEAN, "a",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::isContractAtI); - 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("key", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::keyI); - this->bindAndAddMethod(new jsonrpc::Procedure("keys", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_ARRAY, NULL), &AbstractEthStubServer::keysI); - this->bindAndAddMethod(new jsonrpc::Procedure("lastBlock", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, NULL), &AbstractEthStubServer::lastBlockI); - this->bindAndAddMethod(new jsonrpc::Procedure("lll", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "s",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::lllI); - this->bindAndAddMethod(new jsonrpc::Procedure("peerCount", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_INTEGER, NULL), &AbstractEthStubServer::peerCountI); - this->bindAndAddMethod(new jsonrpc::Procedure("procedures", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_ARRAY, NULL), &AbstractEthStubServer::proceduresI); - this->bindAndAddMethod(new jsonrpc::Procedure("secretToAddress", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "a",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::secretToAddressI); - this->bindAndAddMethod(new jsonrpc::Procedure("storageAt", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "a",jsonrpc::JSON_STRING,"x",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::storageAtI); - this->bindAndAddMethod(new jsonrpc::Procedure("stateAt", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "a",jsonrpc::JSON_STRING,"x",jsonrpc::JSON_STRING,"s",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::stateAtI); - this->bindAndAddMethod(new jsonrpc::Procedure("transact", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, "aDest",jsonrpc::JSON_STRING,"bData",jsonrpc::JSON_STRING,"sec",jsonrpc::JSON_STRING,"xGas",jsonrpc::JSON_STRING,"xGasPrice",jsonrpc::JSON_STRING,"xValue",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::transactI); - this->bindAndAddMethod(new jsonrpc::Procedure("txCountAt", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "a",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::txCountAtI); + jsonrpc::AbstractServer(conn) + { + this->bindAndAddMethod(new jsonrpc::Procedure("balanceAt", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "a",jsonrpc::JSON_STRING,"block",jsonrpc::JSON_STRING, NULL), &Abstracttest.hServer::balanceAtI); + this->bindAndAddMethod(new jsonrpc::Procedure("block", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "numberOrHash",jsonrpc::JSON_STRING, NULL), &Abstracttest.hServer::blockI); + this->bindAndAddMethod(new jsonrpc::Procedure("call", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "json",jsonrpc::JSON_STRING, NULL), &Abstracttest.hServer::callI); + this->bindAndAddMethod(new jsonrpc::Procedure("codeAt", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "a",jsonrpc::JSON_STRING,"block",jsonrpc::JSON_STRING, NULL), &Abstracttest.hServer::codeAtI); + this->bindAndAddMethod(new jsonrpc::Procedure("coinbase", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, NULL), &Abstracttest.hServer::coinbaseI); + this->bindAndAddMethod(new jsonrpc::Procedure("countAt", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_INTEGER, "a",jsonrpc::JSON_STRING,"block",jsonrpc::JSON_STRING, NULL), &Abstracttest.hServer::countAtI); + this->bindAndAddMethod(new jsonrpc::Procedure("defaultBlock", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_INTEGER, NULL), &Abstracttest.hServer::defaultBlockI); + this->bindAndAddMethod(new jsonrpc::Procedure("fromAscii", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "s",jsonrpc::JSON_STRING, NULL), &Abstracttest.hServer::fromAsciiI); + this->bindAndAddMethod(new jsonrpc::Procedure("fromFixed", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "s",jsonrpc::JSON_STRING, NULL), &Abstracttest.hServer::fromFixedI); + this->bindAndAddMethod(new jsonrpc::Procedure("gasPrice", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, NULL), &Abstracttest.hServer::gasPriceI); + this->bindAndAddMethod(new jsonrpc::Procedure("isListening", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_BOOLEAN, NULL), &Abstracttest.hServer::isListeningI); + this->bindAndAddMethod(new jsonrpc::Procedure("isMining", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_BOOLEAN, NULL), &Abstracttest.hServer::isMiningI); + this->bindAndAddMethod(new jsonrpc::Procedure("key", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, NULL), &Abstracttest.hServer::keyI); + this->bindAndAddMethod(new jsonrpc::Procedure("keys", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_ARRAY, NULL), &Abstracttest.hServer::keysI); + this->bindAndAddMethod(new jsonrpc::Procedure("lll", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "s",jsonrpc::JSON_STRING, NULL), &Abstracttest.hServer::lllI); + this->bindAndAddMethod(new jsonrpc::Procedure("messages", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "json",jsonrpc::JSON_STRING, NULL), &Abstracttest.hServer::messagesI); + this->bindAndAddMethod(new jsonrpc::Procedure("number", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_INTEGER, NULL), &Abstracttest.hServer::numberI); + this->bindAndAddMethod(new jsonrpc::Procedure("peerCount", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_INTEGER, NULL), &Abstracttest.hServer::peerCountI); + this->bindAndAddMethod(new jsonrpc::Procedure("secretToAddress", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "s",jsonrpc::JSON_STRING, NULL), &Abstracttest.hServer::secretToAddressI); + this->bindAndAddMethod(new jsonrpc::Procedure("setListening", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "l",jsonrpc::JSON_STRING, NULL), &Abstracttest.hServer::setListeningI); + this->bindAndAddMethod(new jsonrpc::Procedure("setMining", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "l",jsonrpc::JSON_STRING, NULL), &Abstracttest.hServer::setMiningI); + this->bindAndAddMethod(new jsonrpc::Procedure("sha3", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "s",jsonrpc::JSON_STRING, NULL), &Abstracttest.hServer::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), &Abstracttest.hServer::stateAtI); + this->bindAndAddMethod(new jsonrpc::Procedure("toAscii", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "s",jsonrpc::JSON_STRING, NULL), &Abstracttest.hServer::toAsciiI); + this->bindAndAddMethod(new jsonrpc::Procedure("toDecimal", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "s",jsonrpc::JSON_STRING, NULL), &Abstracttest.hServer::toDecimalI); + this->bindAndAddMethod(new jsonrpc::Procedure("toFixed", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "s",jsonrpc::JSON_STRING, NULL), &Abstracttest.hServer::toFixedI); + this->bindAndAddMethod(new jsonrpc::Procedure("transact", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "json",jsonrpc::JSON_STRING, NULL), &Abstracttest.hServer::transactI); + this->bindAndAddMethod(new jsonrpc::Procedure("transaction", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "i",jsonrpc::JSON_STRING,"numberOrHash",jsonrpc::JSON_STRING, NULL), &Abstracttest.hServer::transactionI); + this->bindAndAddMethod(new jsonrpc::Procedure("uncle", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "i",jsonrpc::JSON_STRING,"numberOrHash",jsonrpc::JSON_STRING, NULL), &Abstracttest.hServer::uncleI); + this->bindAndAddMethod(new jsonrpc::Procedure("watch", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "json",jsonrpc::JSON_STRING, NULL), &Abstracttest.hServer::watchI); } inline virtual void balanceAtI(const Json::Value& request, Json::Value& response) { - response = this->balanceAt(request["a"].asString()); + response = this->balanceAt(request["a"].asString(), request["block"].asString()); } inline virtual void blockI(const Json::Value& request, Json::Value& response) { - response = this->block(request["a"].asString()); + response = this->block(request["numberOrHash"].asString()); } - inline virtual void checkI(const Json::Value& request, Json::Value& response) + inline virtual void callI(const Json::Value& request, Json::Value& response) { - response = this->check(request["a"]); + response = this->call(request["json"].asString()); + } + + inline virtual void codeAtI(const Json::Value& request, Json::Value& response) + { + response = this->codeAt(request["a"].asString(), request["block"].asString()); } inline virtual void coinbaseI(const Json::Value& request, Json::Value& response) @@ -56,19 +71,29 @@ class AbstractEthStubServer : public jsonrpc::AbstractServercoinbase(); } - inline virtual void createI(const Json::Value& request, Json::Value& response) + inline virtual void countAtI(const Json::Value& request, Json::Value& response) { - response = this->create(request["bCode"].asString(), request["sec"].asString(), request["xEndowment"].asString(), request["xGas"].asString(), request["xGasPrice"].asString()); + response = this->countAt(request["a"].asString(), request["block"].asString()); } - inline virtual void gasPriceI(const Json::Value& request, Json::Value& response) + inline virtual void defaultBlockI(const Json::Value& request, Json::Value& response) { - response = this->gasPrice(); + response = this->defaultBlock(); + } + + inline virtual void fromAsciiI(const Json::Value& request, Json::Value& response) + { + response = this->fromAscii(request["s"].asString()); + } + + inline virtual void fromFixedI(const Json::Value& request, Json::Value& response) + { + response = this->fromFixed(request["s"].asString()); } - inline virtual void isContractAtI(const Json::Value& request, Json::Value& response) + inline virtual void gasPriceI(const Json::Value& request, Json::Value& response) { - response = this->isContractAt(request["a"].asString()); + response = this->gasPrice(); } inline virtual void isListeningI(const Json::Value& request, Json::Value& response) @@ -91,14 +116,19 @@ class AbstractEthStubServer : public jsonrpc::AbstractServerkeys(); } - inline virtual void lastBlockI(const Json::Value& request, Json::Value& response) + inline virtual void lllI(const Json::Value& request, Json::Value& response) + { + response = this->lll(request["s"].asString()); + } + + inline virtual void messagesI(const Json::Value& request, Json::Value& response) { - response = this->lastBlock(); + response = this->messages(request["json"].asString()); } - inline virtual void lllI(const Json::Value& request, Json::Value& response) + inline virtual void numberI(const Json::Value& request, Json::Value& response) { - response = this->lll(request["s"].asString()); + response = this->number(); } inline virtual void peerCountI(const Json::Value& request, Json::Value& response) @@ -106,57 +136,97 @@ class AbstractEthStubServer : public jsonrpc::AbstractServerpeerCount(); } - inline virtual void proceduresI(const Json::Value& request, Json::Value& response) + inline virtual void secretToAddressI(const Json::Value& request, Json::Value& response) { - response = this->procedures(); + response = this->secretToAddress(request["s"].asString()); } - inline virtual void secretToAddressI(const Json::Value& request, Json::Value& response) + inline virtual void setListeningI(const Json::Value& request, Json::Value& response) + { + response = this->setListening(request["l"].asString()); + } + + inline virtual void setMiningI(const Json::Value& request, Json::Value& response) + { + response = this->setMining(request["l"].asString()); + } + + inline virtual void sha3I(const Json::Value& request, Json::Value& response) + { + response = this->sha3(request["s"].asString()); + } + + inline virtual void stateAtI(const Json::Value& request, Json::Value& response) { - response = this->secretToAddress(request["a"].asString()); + response = this->stateAt(request["a"].asString(), request["block"].asString(), request["p"].asString()); } - inline virtual void storageAtI(const Json::Value& request, Json::Value& response) + inline virtual void toAsciiI(const Json::Value& request, Json::Value& response) { - response = this->storageAt(request["a"].asString(), request["x"].asString()); + response = this->toAscii(request["s"].asString()); } - inline virtual void stateAtI(const Json::Value& request, Json::Value& response) + inline virtual void toDecimalI(const Json::Value& request, Json::Value& response) { - response = this->stateAt(request["a"].asString(), request["x"].asString(), request["s"].asString()); + response = this->toDecimal(request["s"].asString()); + } + + inline virtual void toFixedI(const Json::Value& request, Json::Value& response) + { + response = this->toFixed(request["s"].asString()); } inline virtual void transactI(const Json::Value& request, Json::Value& response) { - response = this->transact(request["aDest"].asString(), request["bData"].asString(), request["sec"].asString(), request["xGas"].asString(), request["xGasPrice"].asString(), request["xValue"].asString()); + response = this->transact(request["json"].asString()); + } + + inline virtual void transactionI(const Json::Value& request, Json::Value& response) + { + response = this->transaction(request["i"].asString(), request["numberOrHash"].asString()); + } + + inline virtual void uncleI(const Json::Value& request, Json::Value& response) + { + response = this->uncle(request["i"].asString(), request["numberOrHash"].asString()); } - inline virtual void txCountAtI(const Json::Value& request, Json::Value& response) + inline virtual void watchI(const Json::Value& request, Json::Value& response) { - response = this->txCountAt(request["a"].asString()); + response = this->watch(request["json"].asString()); } - virtual std::string balanceAt(const std::string& a) = 0; - virtual Json::Value block(const std::string& a) = 0; - virtual Json::Value check(const Json::Value& a) = 0; + virtual std::string balanceAt(const std::string& a, const std::string& block) = 0; + virtual std::string block(const std::string& numberOrHash) = 0; + virtual std::string call(const std::string& json) = 0; + virtual std::string codeAt(const std::string& a, const std::string& block) = 0; virtual std::string coinbase() = 0; - virtual std::string create(const std::string& bCode, const std::string& sec, const std::string& xEndowment, const std::string& xGas, const std::string& xGasPrice) = 0; + virtual int countAt(const std::string& a, const std::string& block) = 0; + virtual int defaultBlock() = 0; + virtual std::string fromAscii(const std::string& s) = 0; + virtual std::string fromFixed(const std::string& s) = 0; virtual std::string gasPrice() = 0; - virtual bool isContractAt(const std::string& a) = 0; virtual bool isListening() = 0; virtual bool isMining() = 0; virtual std::string key() = 0; virtual Json::Value keys() = 0; - virtual Json::Value lastBlock() = 0; virtual std::string lll(const std::string& s) = 0; + virtual std::string messages(const std::string& json) = 0; + virtual int number() = 0; virtual int peerCount() = 0; - virtual Json::Value procedures() = 0; - virtual std::string secretToAddress(const std::string& a) = 0; - virtual std::string storageAt(const std::string& a, const std::string& x) = 0; - virtual std::string stateAt(const std::string& a, const std::string& x, const std::string& b) = 0; - virtual Json::Value transact(const std::string& aDest, const std::string& bData, const std::string& sec, const std::string& xGas, const std::string& xGasPrice, const std::string& xValue) = 0; - virtual std::string txCountAt(const std::string& a) = 0; + virtual std::string secretToAddress(const std::string& s) = 0; + virtual std::string setListening(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 stateAt(const std::string& a, const std::string& block, const std::string& p) = 0; + virtual std::string toAscii(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 transact(const std::string& json) = 0; + virtual std::string transaction(const std::string& i, const std::string& numberOrHash) = 0; + virtual std::string uncle(const std::string& i, const std::string& numberOrHash) = 0; + virtual std::string watch(const std::string& json) = 0; }; -#endif //_ABSTRACTETHSTUBSERVER_H_ +#endif //_ABSTRACTTEST.HSERVER_H_ diff --git a/eth/spec.json b/eth/spec.json index 4be3f8f00..664f59258 100644 --- a/eth/spec.json +++ b/eth/spec.json @@ -1,24 +1,40 @@ [ - { "method": "procedures", "params": null, "order": [], "returns": [] }, - { "method": "coinbase", "params": null, "order": [], "returns" : "" }, - { "method": "isListening", "params": null, "order": [], "returns" : false }, - { "method": "isMining", "params": null, "order": [], "returns" : false }, - { "method": "gasPrice", "params": null, "order": [], "returns" : "" }, - { "method": "key", "params": null, "order": [], "returns" : "" }, - { "method": "keys", "params": null, "order": [], "returns" : [] }, - { "method": "peerCount", "params": null, "order": [], "returns" : 0 }, - { "method": "balanceAt", "params": { "a": "" }, "order": ["a"], "returns" : "" }, - { "method": "storageAt", "params": { "a": "", "x": "" }, "order": ["a", "x"], "returns" : "" }, - { "method": "txCountAt", "params": { "a": "" },"order": ["a"], "returns" : "" }, - { "method": "isContractAt", "params": { "a": "" }, "order": ["a"], "returns" : false }, - { "method": "create", "params": { "sec": "", "xEndowment": "", "bCode": "", "xGas": "", "xGasPrice": "" }, "order": ["sec", "xEndowment", "bCode", "xGas", "xGasPrice"] , "returns": "" }, - { "method": "transact", "params": { "sec": "", "xValue": "", "aDest": "", "bData": "", "xGas": "", "xGasPrice": "" }, "order": ["sec", "xValue", "aDest", "bData", "xGas", "xGasPrice"], "returns": {} }, - { "method": "secretToAddress", "params": { "a": "" }, "order": ["a"], "returns" : "" }, - { "method": "lll", "params": { "s": "" }, "order": ["s"], "returns" : "" } -, - { "method": "check", "params": { "a": [] }, "order": ["a"], "returns" : [] }, - { "method": "lastBlock", "params": null, "order": [], "returns": {}}, - { "method": "block", "params": {"a":""}, "order": ["a"], "returns": {}} + { "method": "coinbase", "params": null, "order": [], "returns" : "" }, + { "method": "isListening", "params": null, "order": [], "returns" : false }, + { "method": "setListening", "params": { "l": "" }, "order" : ["l"], "returns" : ""}, + { "method": "isMining", "params": null, "order": [], "returns" : false }, + { "method": "setMining", "params": { "l": "" }, "order" : ["l"], "returns" : ""}, + { "method": "gasPrice", "params": null, "order": [], "returns" : "" }, + { "method": "key", "params": null, "order": [], "returns" : "" }, + { "method": "keys", "params": null, "order": [], "returns" : [] }, + { "method": "peerCount", "params": null, "order": [], "returns" : 0 }, + { "method": "defaultBlock", "params": null, "order": [], "returns" : 0}, + { "method": "number", "params": null, "order": [], "returns" : 0}, + + + { "method": "balanceAt", "params": { "a": "", "block": ""}, "order": ["a", "block"], "returns" : ""}, + { "method": "stateAt", "params": { "a": "", "p": "", "block": ""}, "order": ["a", "p", "block"], "returns": ""}, + { "method": "countAt", "params": { "a": "", "block": ""}, "order": ["a", "block"], "returns" : 0}, + { "method": "codeAt", "params": { "a": "", "block": ""}, "order": ["a", "block"], "returns": ""}, + + { "method": "transact", "params": { "json": ""}, "order": ["json"], "returns": ""}, + { "method": "call", "params": { "json": ""}, "order": ["json"], "returns": ""}, + + { "method": "block", "params": { "numberOrHash": ""}, "order": ["numberOrHash"], "returns": ""}, + { "method": "transaction", "params": { "numberOrHash": "", "i": ""}, "order": ["numberOrHash", "i"], "returns": ""}, + { "method": "uncle", "params": { "numberOrHash": "", "i": ""}, "order": ["numberOrHash", "i"], "returns": ""}, + + { "method": "messages", "params": { "json": ""}, "order": ["json"], "returns": ""}, + { "method": "watch", "params": { "json": ""}, "order": ["json"], "returns": ""}, + + { "method": "secretToAddress", "params": { "s": ""}, "order": ["s"], "returns": ""}, + { "method": "lll", "params": { "s": ""}, "order": ["s"], "returns": ""}, + { "method": "sha3", "params": { "s": ""}, "order": ["s"], "returns": ""}, + { "method": "toAscii", "params": { "s": ""}, "order": ["s"], "returns": ""}, + { "method": "fromAscii", "params": { "s": ""}, "order": ["s"], "returns": ""}, + { "method": "toDecimal", "params": {"s": ""}, "order": ["s"], "returns" : ""}, + { "method": "toFixed", "params": {"s": ""}, "order": ["s"], "returns" : ""}, + { "method": "fromFixed", "params": {"s": ""}, "order": ["s"], "returns" : ""} ] diff --git a/libdevcore/CommonJS.cpp b/libdevcore/CommonJS.cpp index 4c227bcad..a24edd795 100644 --- a/libdevcore/CommonJS.cpp +++ b/libdevcore/CommonJS.cpp @@ -53,6 +53,11 @@ void CommonJS::setAccounts(std::vector _accounts) m_accounts = _accounts; } +std::string CommonJS::ethTest() const +{ + return "Hello World!"; +} + std::string CommonJS::coinbase() const { return m_client ? toJS(client()->address()) : ""; @@ -144,6 +149,55 @@ std::string CommonJS::codeAt(const std::string &_a, int _block) const return m_client ? jsFromBinary(client()->codeAt(jsToAddress(_a), _block)) : ""; } +std::string CommonJS::transact(TransactionSkeleton _t) +{ + std::string ret; + if (!m_client) + return ret; + // what if there is no from accout specified? + if (!_t.from.secret() && m_accounts.size()) + { + auto b = m_accounts.front(); + for (auto a: m_accounts) + if (client()->balanceAt(KeyPair(a).address()) > client()->balanceAt(KeyPair(b).address())) + b = a; + _t.from = b; + } + if (!_t.gasPrice) + _t.gasPrice = 10 * dev::eth::szabo; + if (!_t.gas) + _t.gas = std::min(client()->gasLimitRemaining(), client()->balanceAt(KeyPair(_t.from).address()) / _t.gasPrice); + if (_t.to) + client()->transact(_t.from.secret(), _t.value, _t.to, _t.data, _t.gas, _t.gasPrice); + else + ret = toJS(client()->transact(_t.from.secret(), _t.value, _t.data, _t.gas, _t.gasPrice)); + client()->flushTransactions(); + return ret; +} + +std::string CommonJS::call(TransactionSkeleton _t) +{ + std::string ret; + if (!m_client) + return ret; + if (!_t.to) + return ret; + if (!_t.from.secret() && m_accounts.size()) + _t.from = m_accounts[0]; + if (!_t.gasPrice) + _t.gasPrice = 10 * dev::eth::szabo; + if (!_t.gas) + _t.gas = client()->balanceAt(_t.from.address()) / _t.gasPrice; + ret = toJS(client()->call(_t.from.secret(), _t.value, _t.to, _t.data, _t.gas, _t.gasPrice)); + return ret; +} + +std::tuple CommonJS::block(const std::string &_numberOrHash) const +{ + auto n = jsToU256(_numberOrHash); + auto h = n < m_client->number() ? m_client->hashFromNumber((unsigned)n) : jsToFixed<32>(_numberOrHash); + return std::make_tuple(m_client->blockInfo(h), m_client->blockDetails(h)); +} diff --git a/libdevcore/CommonJS.h b/libdevcore/CommonJS.h index 2e4750589..b48082ac1 100644 --- a/libdevcore/CommonJS.h +++ b/libdevcore/CommonJS.h @@ -2,6 +2,7 @@ #include #include +#include #include #include "Common.h" #include "CommonData.h" @@ -9,6 +10,10 @@ namespace dev { namespace eth { +template std::string toJS(FixedHash const& _h) { return "0x" + toHex(_h.ref()); } +template std::string toJS(boost::multiprecision::number> const& _n) { return "0x" + toHex(toCompactBigEndian(_n)); } +inline std::string toJS(dev::bytes const& _n) { return "0x" + dev::toHex(_n); } + bytes jsToBytes(std::string const& _s); std::string jsPadded(std::string const& _s, unsigned _l, unsigned _r); std::string jsPadded(std::string const& _s, unsigned _l); @@ -27,6 +32,12 @@ template FixedHash jsToFixed(std::string const& _s) return FixedHash(asBytes(jsPadded(_s, N))); } +inline std::string jsToFixed(double _s) +{ + return toJS(dev::u256(_s * (double)(dev::u256(1) << 128))); +} + + template boost::multiprecision::number> jsToInt(std::string const& _s) { if (_s.substr(0, 2) == "0x") @@ -55,9 +66,18 @@ inline std::string jsFromBinary(std::string const& _s, unsigned _padding = 32) return jsFromBinary(asBytes(_s), _padding); } +// we note really need KeyPair from +// but it usefull for checking the balance +struct TransactionSkeleton +{ + dev::KeyPair from; + Address to; + u256 value; + bytes data; + u256 gas; + u256 gasPrice; +}; -template std::string toJS(FixedHash const& _h) { return "0x" + toHex(_h.ref()); } -template std::string toJS(boost::multiprecision::number> const& _n) { return "0x" + toHex(toCompactBigEndian(_n)); } class CommonJS { @@ -88,10 +108,23 @@ public: std::string codeAt(std::string const &_a, int _block) const; // transactions - void transact(std::string const &_json); - void call(std::string const &_json); + std::string transact(dev::eth::TransactionSkeleton _t); + std::string call(dev::eth::TransactionSkeleton _t); // blockchain + std::tuple block(std::string const &_numberOrHash) const; + std::string transaction(std::string const &_numberOrHash, int _index) const; + std::string uncle(std::string const &_numberOrHash, int _index) const; + + // watches and messages filtering + std::string messages(std::string const &_attribs) const; + // TODO watch + + // misc + std::string secretToAddress(std::string const &_a) const; + std::string lll(std::string const &_l) const; + std::string sha3(std::string const &_s) const; + private: