Browse Source

Merge pull request #1418 from debris/1351_jsonrpc

split #1351, jsonrpc changes
cl-refactor
Gav Wood 10 years ago
parent
commit
24c052ac51
  1. 24
      libweb3jsonrpc/WebThreeStubServerBase.cpp

24
libweb3jsonrpc/WebThreeStubServerBase.cpp

@ -57,7 +57,7 @@ const unsigned dev::SensibleHttpPort = 8080;
static Json::Value toJson(dev::eth::BlockInfo const& _bi) static Json::Value toJson(dev::eth::BlockInfo const& _bi)
{ {
Json::Value res; Json::Value res;
res["hash"] = boost::lexical_cast<string>(_bi.hash); res["hash"] = toJS(_bi.hash);
res["parentHash"] = toJS(_bi.parentHash); res["parentHash"] = toJS(_bi.parentHash);
res["sha3Uncles"] = toJS(_bi.sha3Uncles); res["sha3Uncles"] = toJS(_bi.sha3Uncles);
res["miner"] = toJS(_bi.coinbaseAddress); res["miner"] = toJS(_bi.coinbaseAddress);
@ -65,10 +65,12 @@ static Json::Value toJson(dev::eth::BlockInfo const& _bi)
res["transactionsRoot"] = toJS(_bi.transactionsRoot); res["transactionsRoot"] = toJS(_bi.transactionsRoot);
res["difficulty"] = toJS(_bi.difficulty); res["difficulty"] = toJS(_bi.difficulty);
res["number"] = toJS(_bi.number); res["number"] = toJS(_bi.number);
res["gasUsed"] = toJS(_bi.gasUsed);
res["gasLimit"] = toJS(_bi.gasLimit); res["gasLimit"] = toJS(_bi.gasLimit);
res["timestamp"] = toJS(_bi.timestamp); res["timestamp"] = toJS(_bi.timestamp);
res["extraData"] = toJS(_bi.extraData); res["extraData"] = toJS(_bi.extraData);
res["nonce"] = toJS(_bi.nonce); res["nonce"] = toJS(_bi.nonce);
res["logsBloom"] = toJS(_bi.logBloom);
return res; return res;
} }
@ -86,18 +88,24 @@ static Json::Value toJson(dev::eth::Transaction const& _t)
return res; return res;
} }
static Json::Value toJson(dev::eth::BlockInfo const& _bi, Transactions const& _ts) static Json::Value toJson(dev::eth::BlockInfo const& _bi, UncleHashes const& _us, Transactions const& _ts)
{ {
Json::Value res = toJson(_bi); Json::Value res = toJson(_bi);
res["uncles"] = Json::Value(Json::arrayValue);
for (h256 h: _us)
res["uncles"].append(toJS(h));
res["transactions"] = Json::Value(Json::arrayValue); res["transactions"] = Json::Value(Json::arrayValue);
for (Transaction const& t: _ts) for (Transaction const& t: _ts)
res["transactions"].append(toJson(t)); res["transactions"].append(toJson(t));
return res; return res;
} }
static Json::Value toJson(dev::eth::BlockInfo const& _bi, TransactionHashes const& _ts) static Json::Value toJson(dev::eth::BlockInfo const& _bi, UncleHashes const& _us, TransactionHashes const& _ts)
{ {
Json::Value res = toJson(_bi); Json::Value res = toJson(_bi);
res["uncles"] = Json::Value(Json::arrayValue);
for (h256 h: _us)
res["uncles"].append(toJS(h));
res["transactions"] = Json::Value(Json::arrayValue); res["transactions"] = Json::Value(Json::arrayValue);
for (h256 const& t: _ts) for (h256 const& t: _ts)
res["transactions"].append(toJS(t)); res["transactions"].append(toJS(t));
@ -394,7 +402,7 @@ string WebThreeStubServerBase::eth_getCode(string const& _address, string const&
{ {
try try
{ {
return toJS(client()->codeAt(jsToAddress(_address), toBlockNumber(_blockNumber))); return toJS(client()->codeAt(jsToAddress(_address), toBlockNumber(_blockNumber)), 1);
} }
catch (...) catch (...)
{ {
@ -505,9 +513,9 @@ Json::Value WebThreeStubServerBase::eth_getBlockByHash(string const& _blockHash,
{ {
auto h = jsToFixed<32>(_blockHash); auto h = jsToFixed<32>(_blockHash);
if (_includeTransactions) if (_includeTransactions)
return toJson(client()->blockInfo(h), client()->transactions(h)); return toJson(client()->blockInfo(h), client()->uncleHashes(h), client()->transactions(h));
else else
return toJson(client()->blockInfo(h), client()->transactionHashes(h)); return toJson(client()->blockInfo(h), client()->uncleHashes(h), client()->transactionHashes(h));
} }
catch (...) catch (...)
{ {
@ -521,9 +529,9 @@ Json::Value WebThreeStubServerBase::eth_getBlockByNumber(string const& _blockNum
{ {
auto h = client()->hashFromNumber(jsToInt(_blockNumber)); auto h = client()->hashFromNumber(jsToInt(_blockNumber));
if (_includeTransactions) if (_includeTransactions)
return toJson(client()->blockInfo(h), client()->transactions(h)); return toJson(client()->blockInfo(h), client()->uncleHashes(h), client()->transactions(h));
else else
return toJson(client()->blockInfo(h), client()->transactionHashes(h)); return toJson(client()->blockInfo(h), client()->uncleHashes(h), client()->transactionHashes(h));
} }
catch (...) catch (...)
{ {

Loading…
Cancel
Save