Skip to content
This repository was archived by the owner on Oct 28, 2021. It is now read-only.

Commit 9fcdd46

Browse files
committed
Merge branch 'develop' of github.com:ethereum/cpp-ethereum into develop
2 parents 2368a8c + daaf928 commit 9fcdd46

File tree

6 files changed

+123
-20
lines changed

6 files changed

+123
-20
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,15 @@ ipch
1919
*.opensdf
2020
*.suo
2121

22+
#Xcode stuff
23+
build_xc
24+
2225
*.user
2326
*.user.*
2427
*~
2528

2629
build/
2730

2831
*.pyc
32+
33+
.DS_Store

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Contributors, builders and testers include Eric Lombrozo (cross-compilation), Ti
88

99
### Building
1010

11-
See [Build Instructions](https://github.com/ethereum/cpp-ethereum/wiki/Build-Instructions) and [Compatibility Info and Build Tips](https://github.com/ethereum/cpp-ethereum/wiki/Compatibility-Info-and-Build-Tips).
11+
See the [Wiki](https://github.com/ethereum/cpp-ethereum/wiki) for build instructions, compatibility information and build tips.
1212

1313
### Testing
1414

eth/EthStubServer.cpp

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,29 @@ EthStubServer::EthStubServer(jsonrpc::AbstractServerConnector* _conn, Client& _c
3333
{
3434
}
3535

36+
//only works with a json spec that doesn't have notifications for now
37+
Json::Value EthStubServer::procedures()
38+
{
39+
Json::Value ret;
40+
41+
for (auto proc: this->GetProtocolHanlder()->GetProcedures())
42+
{
43+
Json::Value proc_j;
44+
45+
proc_j[proc.second->GetProcedureType() == 0 ? "method" : "notification"] = proc.first;
46+
47+
Json::Value params_j;
48+
for (auto params: proc.second->GetParameters())
49+
params_j[params.first] = jsontypeToValue(params.second);
50+
proc_j["params"] = params_j;
51+
52+
proc_j["returns"] = jsontypeToValue(proc.second->GetReturnType());
53+
54+
ret.append(proc_j);
55+
}
56+
return ret;
57+
}
58+
3659
std::string EthStubServer::coinbase()
3760
{
3861
ClientGuard g(&m_client);
@@ -129,4 +152,54 @@ std::string EthStubServer::secretToAddress(const std::string& _a)
129152
{
130153
return toJS(KeyPair(jsToSecret(_a)).address());
131154
}
155+
156+
Json::Value EthStubServer::lastBlock()
157+
{
158+
return blockJson("");
159+
}
160+
161+
Json::Value EthStubServer::block(const std::string& _hash)
162+
{
163+
return blockJson(_hash);
164+
}
165+
166+
Json::Value EthStubServer::blockJson(const std::string& _hash)
167+
{
168+
Json::Value res;
169+
auto const& bc = m_client.blockChain();
170+
171+
auto b = _hash.length() ? bc.block(h256(_hash)) : bc.block();
172+
173+
auto bi = BlockInfo(b);
174+
res["number"] = to_string(bc.details(bc.currentHash()).number);
175+
res["hash"] = boost::lexical_cast<string>(bi.hash);
176+
res["parentHash"] = boost::lexical_cast<string>(bi.parentHash);
177+
res["sha3Uncles"] = boost::lexical_cast<string>(bi.sha3Uncles);
178+
res["coinbaseAddress"] = boost::lexical_cast<string>(bi.coinbaseAddress);
179+
res["stateRoot"] = boost::lexical_cast<string>(bi.stateRoot);
180+
res["transactionsRoot"] = boost::lexical_cast<string>(bi.transactionsRoot);
181+
res["minGasPrice"] = boost::lexical_cast<string>(bi.minGasPrice);
182+
res["gasLimit"] = boost::lexical_cast<string>(bi.gasLimit);
183+
res["gasUsed"] = boost::lexical_cast<string>(bi.gasUsed);
184+
res["difficulty"] = boost::lexical_cast<string>(bi.difficulty);
185+
res["timestamp"] = boost::lexical_cast<string>(bi.timestamp);
186+
res["nonce"] = boost::lexical_cast<string>(bi.nonce);
187+
188+
return res;
189+
}
190+
191+
Json::Value EthStubServer::jsontypeToValue(int _jsontype)
192+
{
193+
switch (_jsontype)
194+
{
195+
case jsonrpc::JSON_STRING: return ""; //Json::stringValue segfault, fuck knows why
196+
case jsonrpc::JSON_BOOLEAN: return Json::booleanValue;
197+
case jsonrpc::JSON_INTEGER: return Json::intValue;
198+
case jsonrpc::JSON_REAL: return Json::realValue;
199+
case jsonrpc::JSON_OBJECT: return Json::objectValue;
200+
case jsonrpc::JSON_ARRAY: return Json::arrayValue;
201+
default: return Json::nullValue;
202+
}
203+
}
204+
132205
#endif

eth/EthStubServer.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class EthStubServer: public AbstractEthStubServer
3636
public:
3737
EthStubServer(jsonrpc::AbstractServerConnector* _conn, eth::Client& _client);
3838

39+
virtual Json::Value procedures();
3940
virtual std::string balanceAt(std::string const& _a);
4041
virtual Json::Value check(Json::Value const& _as);
4142
virtual std::string coinbase();
@@ -51,10 +52,12 @@ class EthStubServer: public AbstractEthStubServer
5152
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);
5253
virtual std::string txCountAt(const std::string& a);
5354
virtual std::string secretToAddress(const std::string& a);
54-
55+
virtual Json::Value lastBlock();
56+
virtual Json::Value block(const std::string&);
5557
void setKeys(std::vector<eth::KeyPair> _keys) { m_keys = _keys; }
56-
5758
private:
5859
eth::Client& m_client;
5960
std::vector<eth::KeyPair> m_keys;
61+
Json::Value jsontypeToValue(int);
62+
Json::Value blockJson(const std::string&);
6063
};

eth/abstractethstubserver.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class AbstractEthStubServer : public jsonrpc::AbstractServer<AbstractEthStubServ
1414
jsonrpc::AbstractServer<AbstractEthStubServer>(conn)
1515
{
1616
this->bindAndAddMethod(new jsonrpc::Procedure("balanceAt", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "a",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::balanceAtI);
17+
this->bindAndAddMethod(new jsonrpc::Procedure("block", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, "a",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::blockI);
1718
this->bindAndAddMethod(new jsonrpc::Procedure("check", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_ARRAY, "a",jsonrpc::JSON_ARRAY, NULL), &AbstractEthStubServer::checkI);
1819
this->bindAndAddMethod(new jsonrpc::Procedure("coinbase", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::coinbaseI);
1920
this->bindAndAddMethod(new jsonrpc::Procedure("create", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, "bCode",jsonrpc::JSON_STRING,"sec",jsonrpc::JSON_STRING,"xEndowment",jsonrpc::JSON_STRING,"xGas",jsonrpc::JSON_STRING,"xGasPrice",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::createI);
@@ -23,7 +24,9 @@ class AbstractEthStubServer : public jsonrpc::AbstractServer<AbstractEthStubServ
2324
this->bindAndAddMethod(new jsonrpc::Procedure("isMining", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_BOOLEAN, NULL), &AbstractEthStubServer::isMiningI);
2425
this->bindAndAddMethod(new jsonrpc::Procedure("key", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::keyI);
2526
this->bindAndAddMethod(new jsonrpc::Procedure("keys", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_ARRAY, NULL), &AbstractEthStubServer::keysI);
27+
this->bindAndAddMethod(new jsonrpc::Procedure("lastBlock", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_OBJECT, NULL), &AbstractEthStubServer::lastBlockI);
2628
this->bindAndAddMethod(new jsonrpc::Procedure("peerCount", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_INTEGER, NULL), &AbstractEthStubServer::peerCountI);
29+
this->bindAndAddMethod(new jsonrpc::Procedure("procedures", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_ARRAY, NULL), &AbstractEthStubServer::proceduresI);
2730
this->bindAndAddMethod(new jsonrpc::Procedure("secretToAddress", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "a",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::secretToAddressI);
2831
this->bindAndAddMethod(new jsonrpc::Procedure("storageAt", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING, "a",jsonrpc::JSON_STRING,"x",jsonrpc::JSON_STRING, NULL), &AbstractEthStubServer::storageAtI);
2932
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);
@@ -36,6 +39,11 @@ class AbstractEthStubServer : public jsonrpc::AbstractServer<AbstractEthStubServ
3639
response = this->balanceAt(request["a"].asString());
3740
}
3841

42+
inline virtual void blockI(const Json::Value& request, Json::Value& response)
43+
{
44+
response = this->block(request["a"].asString());
45+
}
46+
3947
inline virtual void checkI(const Json::Value& request, Json::Value& response)
4048
{
4149
response = this->check(request["a"]);
@@ -81,11 +89,21 @@ class AbstractEthStubServer : public jsonrpc::AbstractServer<AbstractEthStubServ
8189
response = this->keys();
8290
}
8391

92+
inline virtual void lastBlockI(const Json::Value& request, Json::Value& response)
93+
{
94+
response = this->lastBlock();
95+
}
96+
8497
inline virtual void peerCountI(const Json::Value& request, Json::Value& response)
8598
{
8699
response = this->peerCount();
87100
}
88101

102+
inline virtual void proceduresI(const Json::Value& request, Json::Value& response)
103+
{
104+
response = this->procedures();
105+
}
106+
89107
inline virtual void secretToAddressI(const Json::Value& request, Json::Value& response)
90108
{
91109
response = this->secretToAddress(request["a"].asString());
@@ -108,6 +126,7 @@ class AbstractEthStubServer : public jsonrpc::AbstractServer<AbstractEthStubServ
108126

109127

110128
virtual std::string balanceAt(const std::string& a) = 0;
129+
virtual Json::Value block(const std::string& a) = 0;
111130
virtual Json::Value check(const Json::Value& a) = 0;
112131
virtual std::string coinbase() = 0;
113132
virtual Json::Value create(const std::string& bCode, const std::string& sec, const std::string& xEndowment, const std::string& xGas, const std::string& xGasPrice) = 0;
@@ -117,7 +136,9 @@ class AbstractEthStubServer : public jsonrpc::AbstractServer<AbstractEthStubServ
117136
virtual bool isMining() = 0;
118137
virtual std::string key() = 0;
119138
virtual Json::Value keys() = 0;
139+
virtual Json::Value lastBlock() = 0;
120140
virtual int peerCount() = 0;
141+
virtual Json::Value procedures() = 0;
121142
virtual std::string secretToAddress(const std::string& a) = 0;
122143
virtual std::string storageAt(const std::string& a, const std::string& x) = 0;
123144
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;

eth/spec.json

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
[
2-
{ "method": "coinbase", "params": null, "returns" : "" },
3-
{ "method": "isListening", "params": null, "returns" : false },
4-
{ "method": "isMining", "params": null, "returns" : false },
5-
{ "method": "gasPrice", "params": null, "returns" : "" },
6-
{ "method": "key", "params": null, "returns" : "" },
7-
{ "method": "keys", "params": null, "returns" : [""] },
8-
{ "method": "peerCount", "params": null, "returns" : 0 },
9-
{ "method": "balanceAt", "params": { "a": "" }, "order": ["a"], "returns" : "" },
10-
{ "method": "storageAt", "params": { "a": "", "x": "" }, "order": ["a", "x"], "returns" : "" },
11-
{ "method": "txCountAt", "params": { "a": "" }, "order": ["a"], "returns" : "" },
12-
{ "method": "isContractAt", "params": { "a": "" }, "order": ["a"], "returns" : false },
13-
{ "method": "create", "params": { "sec": "", "xEndowment": "", "bCode": "", "xGas": "", "xGasPrice": "" }, "order": ["sec", "xEndowment", "bCode", "xGas", "xGasPrice"] },
14-
{ "method": "transact", "params": { "sec": "", "xValue": "", "aDest": "", "bData": "", "xGas": "", "xGasPrice": "" }, "order": ["sec", "xValue", "aDest", "bData", "xGas", "xGasPrice"] },
15-
{ "method": "secretToAddress", "params": { "a": "" }, "order": ["a"], "returns" : "" }
16-
,
17-
18-
{ "method": "check", "params": { "a": [ "", "", "" ] }, "returns" : [ "", "" ] }
2+
{ "method": "procedures", "params": null, "order": [], "returns": [] },
3+
{ "method": "coinbase", "params": null, "order": [], "returns" : "" },
4+
{ "method": "isListening", "params": null, "order": [], "returns" : false },
5+
{ "method": "isMining", "params": null, "order": [], "returns" : false },
6+
{ "method": "gasPrice", "params": null, "order": [], "returns" : "" },
7+
{ "method": "key", "params": null, "order": [], "returns" : "" },
8+
{ "method": "keys", "params": null, "order": [], "returns" : [] },
9+
{ "method": "peerCount", "params": null, "order": [], "returns" : 0 },
10+
{ "method": "balanceAt", "params": { "a": "" }, "order": ["a"], "returns" : "" },
11+
{ "method": "storageAt", "params": { "a": "", "x": "" }, "order": ["a", "x"], "returns" : "" },
12+
{ "method": "txCountAt", "params": { "a": "" },"order": ["a"], "returns" : "" },
13+
{ "method": "isContractAt", "params": { "a": "" }, "order": ["a"], "returns" : false },
14+
{ "method": "create", "params": { "sec": "", "xEndowment": "", "bCode": "", "xGas": "", "xGasPrice": "" }, "order": ["sec", "xEndowment", "bCode", "xGas", "xGasPrice"] , "returns": {} },
15+
{ "method": "transact", "params": { "sec": "", "xValue": "", "aDest": "", "bData": "", "xGas": "", "xGasPrice": "" }, "order": ["sec", "xValue", "aDest", "bData", "xGas", "xGasPrice"], "returns": {} },
16+
{ "method": "secretToAddress", "params": { "a": "" }, "order": ["a"], "returns" : "" },
17+
{ "method": "check", "params": { "a": [] }, "order": ["a"], "returns" : [] },
18+
{ "method": "lastBlock", "params": null, "order": [], "returns": {}},
19+
{ "method": "block", "params": {"a":""}, "order": ["a"], "returns": {}}
1920
]
2021

2122

0 commit comments

Comments
 (0)