|
@ -57,9 +57,9 @@ static Json::Value toJson(dev::eth::BlockInfo const& _bi) |
|
|
res["stateRoot"] = toJS(_bi.stateRoot); |
|
|
res["stateRoot"] = toJS(_bi.stateRoot); |
|
|
res["transactionsRoot"] = toJS(_bi.transactionsRoot); |
|
|
res["transactionsRoot"] = toJS(_bi.transactionsRoot); |
|
|
res["difficulty"] = toJS(_bi.difficulty); |
|
|
res["difficulty"] = toJS(_bi.difficulty); |
|
|
res["number"] = (int)_bi.number; |
|
|
res["number"] = toJS(_bi.number); |
|
|
res["gasLimit"] = (int)_bi.gasLimit; |
|
|
res["gasLimit"] = toJS(_bi.gasLimit); |
|
|
res["timestamp"] = (int)_bi.timestamp; |
|
|
res["timestamp"] = toJS(_bi.timestamp); |
|
|
res["extraData"] = jsFromBinary(_bi.extraData); |
|
|
res["extraData"] = jsFromBinary(_bi.extraData); |
|
|
res["nonce"] = toJS(_bi.nonce); |
|
|
res["nonce"] = toJS(_bi.nonce); |
|
|
return res; |
|
|
return res; |
|
@ -72,7 +72,7 @@ static Json::Value toJson(dev::eth::Transaction const& _t) |
|
|
res["input"] = jsFromBinary(_t.data()); |
|
|
res["input"] = jsFromBinary(_t.data()); |
|
|
res["to"] = toJS(_t.receiveAddress()); |
|
|
res["to"] = toJS(_t.receiveAddress()); |
|
|
res["from"] = toJS(_t.safeSender()); |
|
|
res["from"] = toJS(_t.safeSender()); |
|
|
res["gas"] = (int)_t.gas(); |
|
|
res["gas"] = toJS(_t.gas()); |
|
|
res["gasPrice"] = toJS(_t.gasPrice()); |
|
|
res["gasPrice"] = toJS(_t.gasPrice()); |
|
|
res["nonce"] = toJS(_t.nonce()); |
|
|
res["nonce"] = toJS(_t.nonce()); |
|
|
res["value"] = toJS(_t.value()); |
|
|
res["value"] = toJS(_t.value()); |
|
@ -136,34 +136,33 @@ static dev::eth::LogFilter toLogFilter(Json::Value const& _json) // commented to |
|
|
if (!_json.isObject() || _json.empty()) |
|
|
if (!_json.isObject() || _json.empty()) |
|
|
return filter; |
|
|
return filter; |
|
|
|
|
|
|
|
|
if (_json["earliest"].isInt()) |
|
|
// check only !empty. it should throw exceptions if input params are incorrect
|
|
|
filter.withEarliest(_json["earliest"].asInt()); |
|
|
if (!_json["earliest"].empty()) |
|
|
if (_json["latest"].isInt()) |
|
|
filter.withEarliest(jsToInt(_json["earliest"].asString())); |
|
|
filter.withLatest(_json["lastest"].asInt()); |
|
|
if (!_json["latest"].empty()) |
|
|
if (_json["max"].isInt()) |
|
|
filter.withLatest(jsToInt(_json["latest"].asString())); |
|
|
filter.withMax(_json["max"].asInt()); |
|
|
if (!_json["max"].empty()) |
|
|
if (_json["skip"].isInt()) |
|
|
filter.withMax(jsToInt(_json["max"].asString())); |
|
|
filter.withSkip(_json["skip"].asInt()); |
|
|
if (!_json["skip"].empty()) |
|
|
|
|
|
filter.withSkip(jsToInt(_json["skip"].asString())); |
|
|
if (!_json["address"].empty()) |
|
|
if (!_json["address"].empty()) |
|
|
{ |
|
|
{ |
|
|
if (_json["address"].isArray()) |
|
|
if (_json["address"].isArray()) |
|
|
{ |
|
|
|
|
|
for (auto i : _json["address"]) |
|
|
for (auto i : _json["address"]) |
|
|
if (i.isString()) |
|
|
|
|
|
filter.address(jsToAddress(i.asString())); |
|
|
filter.address(jsToAddress(i.asString())); |
|
|
} |
|
|
else |
|
|
else if (_json["address"].isString()) |
|
|
|
|
|
filter.address(jsToAddress(_json["address"].asString())); |
|
|
filter.address(jsToAddress(_json["address"].asString())); |
|
|
} |
|
|
} |
|
|
if (!_json["topic"].empty() && _json["topic"].isArray()) |
|
|
if (!_json["topic"].empty()) |
|
|
{ |
|
|
{ |
|
|
unsigned i = 0; |
|
|
unsigned i = 0; |
|
|
for (auto t: _json["topic"]) |
|
|
for (auto t: _json["topic"]) |
|
|
{ |
|
|
{ |
|
|
|
|
|
// array in array?
|
|
|
if (t.isArray()) |
|
|
if (t.isArray()) |
|
|
for (auto tt: t) |
|
|
for (auto tt: t) |
|
|
filter.topic(i, jsToFixed<32>(tt.asString())); |
|
|
filter.topic(i, jsToFixed<32>(tt.asString())); |
|
|
else if (t.isString()) |
|
|
else |
|
|
filter.topic(i, jsToFixed<32>(t.asString())); |
|
|
filter.topic(i, jsToFixed<32>(t.asString())); |
|
|
i++; |
|
|
i++; |
|
|
} |
|
|
} |
|
@ -174,11 +173,11 @@ static dev::eth::LogFilter toLogFilter(Json::Value const& _json) // commented to |
|
|
static shh::Message toMessage(Json::Value const& _json) |
|
|
static shh::Message toMessage(Json::Value const& _json) |
|
|
{ |
|
|
{ |
|
|
shh::Message ret; |
|
|
shh::Message ret; |
|
|
if (_json["from"].isString()) |
|
|
if (!_json["from"].empty()) |
|
|
ret.setFrom(jsToPublic(_json["from"].asString())); |
|
|
ret.setFrom(jsToPublic(_json["from"].asString())); |
|
|
if (_json["to"].isString()) |
|
|
if (!_json["to"].empty()) |
|
|
ret.setTo(jsToPublic(_json["to"].asString())); |
|
|
ret.setTo(jsToPublic(_json["to"].asString())); |
|
|
if (_json["payload"].isString()) |
|
|
if (!_json["payload"].empty()) |
|
|
ret.setPayload(jsToBytes(_json["payload"].asString())); |
|
|
ret.setPayload(jsToBytes(_json["payload"].asString())); |
|
|
return ret; |
|
|
return ret; |
|
|
} |
|
|
} |
|
@ -189,17 +188,16 @@ static shh::Envelope toSealed(Json::Value const& _json, shh::Message const& _m, |
|
|
unsigned workToProve = 50; |
|
|
unsigned workToProve = 50; |
|
|
shh::BuildTopic bt; |
|
|
shh::BuildTopic bt; |
|
|
|
|
|
|
|
|
if (_json["ttl"].isInt()) |
|
|
if (!_json["ttl"].empty()) |
|
|
ttl = _json["ttl"].asInt(); |
|
|
ttl = jsToInt(_json["ttl"].asString()); |
|
|
if (_json["workToProve"].isInt()) |
|
|
if (!_json["workToProve"].empty()) |
|
|
workToProve = _json["workToProve"].asInt(); |
|
|
workToProve = jsToInt(_json["workToProve"].asString()); |
|
|
if (!_json["topic"].empty()) |
|
|
if (!_json["topic"].empty()) |
|
|
{ |
|
|
{ |
|
|
if (_json["topic"].isString()) |
|
|
if (_json["topic"].isString()) |
|
|
bt.shift(jsToBytes(_json["topic"].asString())); |
|
|
bt.shift(jsToBytes(_json["topic"].asString())); |
|
|
else if (_json["topic"].isArray()) |
|
|
else |
|
|
for (auto i: _json["topic"]) |
|
|
for (auto i: _json["topic"]) |
|
|
if (i.isString()) |
|
|
|
|
|
bt.shift(jsToBytes(i.asString())); |
|
|
bt.shift(jsToBytes(i.asString())); |
|
|
} |
|
|
} |
|
|
return _m.seal(_from, bt, ttl, workToProve); |
|
|
return _m.seal(_from, bt, ttl, workToProve); |
|
@ -210,16 +208,15 @@ static pair<shh::FullTopic, Public> toWatch(Json::Value const& _json) |
|
|
shh::BuildTopic bt; |
|
|
shh::BuildTopic bt; |
|
|
Public to; |
|
|
Public to; |
|
|
|
|
|
|
|
|
if (_json["to"].isString()) |
|
|
if (!_json["to"].empty()) |
|
|
to = jsToPublic(_json["to"].asString()); |
|
|
to = jsToPublic(_json["to"].asString()); |
|
|
|
|
|
|
|
|
if (!_json["topic"].empty()) |
|
|
if (!_json["topic"].empty()) |
|
|
{ |
|
|
{ |
|
|
if (_json["topic"].isString()) |
|
|
if (_json["topic"].isString()) |
|
|
bt.shift(jsToBytes(_json["topic"].asString())); |
|
|
bt.shift(jsToBytes(_json["topic"].asString())); |
|
|
else if (_json["topic"].isArray()) |
|
|
else |
|
|
for (auto i: _json["topic"]) |
|
|
for (auto i: _json["topic"]) |
|
|
if (i.isString()) |
|
|
|
|
|
bt.shift(jsToBytes(i.asString())); |
|
|
bt.shift(jsToBytes(i.asString())); |
|
|
} |
|
|
} |
|
|
return make_pair(bt, to); |
|
|
return make_pair(bt, to); |
|
@ -229,10 +226,10 @@ static Json::Value toJson(h256 const& _h, shh::Envelope const& _e, shh::Message |
|
|
{ |
|
|
{ |
|
|
Json::Value res; |
|
|
Json::Value res; |
|
|
res["hash"] = toJS(_h); |
|
|
res["hash"] = toJS(_h); |
|
|
res["expiry"] = (int)_e.expiry(); |
|
|
res["expiry"] = toJS(_e.expiry()); |
|
|
res["sent"] = (int)_e.sent(); |
|
|
res["sent"] = toJS(_e.sent()); |
|
|
res["ttl"] = (int)_e.ttl(); |
|
|
res["ttl"] = toJS(_e.ttl()); |
|
|
res["workProved"] = (int)_e.workProved(); |
|
|
res["workProved"] = toJS(_e.workProved()); |
|
|
res["topic"] = Json::Value(Json::arrayValue); |
|
|
res["topic"] = Json::Value(Json::arrayValue); |
|
|
for (auto const& t: _e.topic()) |
|
|
for (auto const& t: _e.topic()) |
|
|
res["topic"].append(toJS(t)); |
|
|
res["topic"].append(toJS(t)); |
|
@ -465,26 +462,26 @@ static TransactionSkeleton toTransaction(Json::Value const& _json) |
|
|
if (!_json.isObject() || _json.empty()) |
|
|
if (!_json.isObject() || _json.empty()) |
|
|
return ret; |
|
|
return ret; |
|
|
|
|
|
|
|
|
if (_json["from"].isString()) |
|
|
if (!_json["from"].empty()) |
|
|
ret.from = jsToAddress(_json["from"].asString()); |
|
|
ret.from = jsToAddress(_json["from"].asString()); |
|
|
if (_json["to"].isString()) |
|
|
if (!_json["to"].empty()) |
|
|
ret.to = jsToAddress(_json["to"].asString()); |
|
|
ret.to = jsToAddress(_json["to"].asString()); |
|
|
else |
|
|
else |
|
|
ret.creation = true; |
|
|
ret.creation = true; |
|
|
|
|
|
|
|
|
if (_json["value"].isString()) |
|
|
if (!_json["value"].empty()) |
|
|
ret.value = jsToU256(_json["value"].asString()); |
|
|
ret.value = jsToU256(_json["value"].asString()); |
|
|
|
|
|
|
|
|
if (_json["gas"].isString()) |
|
|
if (!_json["gas"].empty()) |
|
|
ret.gas = jsToU256(_json["gas"].asString()); |
|
|
ret.gas = jsToU256(_json["gas"].asString()); |
|
|
|
|
|
|
|
|
if (_json["gasPrice"].isString()) |
|
|
if (!_json["gasPrice"].empty()) |
|
|
ret.gasPrice = jsToU256(_json["gasPrice"].asString()); |
|
|
ret.gasPrice = jsToU256(_json["gasPrice"].asString()); |
|
|
|
|
|
|
|
|
if (_json["data"].isString()) // ethereum.js has preconstructed the data array
|
|
|
if (!_json["data"].empty()) // ethereum.js has preconstructed the data array
|
|
|
ret.data = jsToBytes(_json["data"].asString()); |
|
|
ret.data = jsToBytes(_json["data"].asString()); |
|
|
|
|
|
|
|
|
if (_json["code"].isString()) |
|
|
if (!_json["code"].empty()) |
|
|
ret.data = jsToBytes(_json["code"].asString()); |
|
|
ret.data = jsToBytes(_json["code"].asString()); |
|
|
return ret; |
|
|
return ret; |
|
|
} |
|
|
} |
|
|