Browse Source

null return for invalid values.

cl-refactor
Gav Wood 10 years ago
parent
commit
d4ee45acfd
  1. 2
      libethcore/BlockInfo.h
  2. 80
      libweb3jsonrpc/WebThreeStubServerBase.cpp

2
libethcore/BlockInfo.h

@ -80,7 +80,7 @@ public:
u256 number; u256 number;
u256 gasLimit; u256 gasLimit;
u256 gasUsed; u256 gasUsed;
u256 timestamp; u256 timestamp = Invalid256;
bytes extraData; bytes extraData;
h256 mixHash; h256 mixHash;
Nonce nonce; Nonce nonce;

80
libweb3jsonrpc/WebThreeStubServerBase.cpp

@ -57,58 +57,70 @@ 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"] = toJS(_bi.hash); if (_bi)
res["parentHash"] = toJS(_bi.parentHash); {
res["sha3Uncles"] = toJS(_bi.sha3Uncles); res["hash"] = toJS(_bi.hash);
res["miner"] = toJS(_bi.coinbaseAddress); res["parentHash"] = toJS(_bi.parentHash);
res["stateRoot"] = toJS(_bi.stateRoot); res["sha3Uncles"] = toJS(_bi.sha3Uncles);
res["transactionsRoot"] = toJS(_bi.transactionsRoot); res["miner"] = toJS(_bi.coinbaseAddress);
res["difficulty"] = toJS(_bi.difficulty); res["stateRoot"] = toJS(_bi.stateRoot);
res["number"] = toJS(_bi.number); res["transactionsRoot"] = toJS(_bi.transactionsRoot);
res["gasUsed"] = toJS(_bi.gasUsed); res["difficulty"] = toJS(_bi.difficulty);
res["gasLimit"] = toJS(_bi.gasLimit); res["number"] = toJS(_bi.number);
res["timestamp"] = toJS(_bi.timestamp); res["gasUsed"] = toJS(_bi.gasUsed);
res["extraData"] = toJS(_bi.extraData); res["gasLimit"] = toJS(_bi.gasLimit);
res["nonce"] = toJS(_bi.nonce); res["timestamp"] = toJS(_bi.timestamp);
res["logsBloom"] = toJS(_bi.logBloom); res["extraData"] = toJS(_bi.extraData);
res["nonce"] = toJS(_bi.nonce);
res["logsBloom"] = toJS(_bi.logBloom);
}
return res; return res;
} }
static Json::Value toJson(dev::eth::Transaction const& _t) static Json::Value toJson(dev::eth::Transaction const& _t)
{ {
Json::Value res; Json::Value res;
res["hash"] = toJS(_t.sha3()); if (_t)
res["input"] = toJS(_t.data()); {
res["to"] = _t.isCreation() ? Json::Value() : toJS(_t.receiveAddress()); res["hash"] = toJS(_t.sha3());
res["from"] = toJS(_t.safeSender()); res["input"] = toJS(_t.data());
res["gas"] = toJS(_t.gas()); res["to"] = _t.isCreation() ? Json::Value() : toJS(_t.receiveAddress());
res["gasPrice"] = toJS(_t.gasPrice()); res["from"] = toJS(_t.safeSender());
res["nonce"] = toJS(_t.nonce()); res["gas"] = toJS(_t.gas());
res["value"] = toJS(_t.value()); res["gasPrice"] = toJS(_t.gasPrice());
res["nonce"] = toJS(_t.nonce());
res["value"] = toJS(_t.value());
}
return res; return res;
} }
static Json::Value toJson(dev::eth::BlockInfo const& _bi, UncleHashes const& _us, 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); if (_bi)
for (h256 h: _us) {
res["uncles"].append(toJS(h)); res["uncles"] = Json::Value(Json::arrayValue);
res["transactions"] = Json::Value(Json::arrayValue); for (h256 h: _us)
for (Transaction const& t: _ts) res["uncles"].append(toJS(h));
res["transactions"].append(toJson(t)); res["transactions"] = Json::Value(Json::arrayValue);
for (Transaction const& t: _ts)
res["transactions"].append(toJson(t));
}
return res; return res;
} }
static Json::Value toJson(dev::eth::BlockInfo const& _bi, UncleHashes const& _us, 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); if (_bi)
for (h256 h: _us) {
res["uncles"].append(toJS(h)); res["uncles"] = Json::Value(Json::arrayValue);
res["transactions"] = Json::Value(Json::arrayValue); for (h256 h: _us)
for (h256 const& t: _ts) res["uncles"].append(toJS(h));
res["transactions"].append(toJS(t)); res["transactions"] = Json::Value(Json::arrayValue);
for (h256 const& t: _ts)
res["transactions"].append(toJS(t));
}
return res; return res;
} }

Loading…
Cancel
Save