コード例 #1
0
static QString messageToString(shh::Envelope const& _e, shh::Message const& _m, QString const& _topic)
{
	time_t birth = _e.expiry() - _e.ttl();
	QString t(ctime(&birth));
	t.chop(6);
	t = t.right(t.size() - 4);

	QString seal = QString("{%1 -> %2}").arg(_m.from() ? _m.from().abridged().c_str() : "?").arg(_m.to() ? _m.to().abridged().c_str() : "X");
	QString item = QString("[%1, ttl: %2] *%3 [%4] %5").arg(t).arg(_e.ttl()).arg(_e.workProved()).arg(_topic).arg(seal);

	bytes raw = _m.payload();
	if (raw.size())
	{
		QString plaintext = QString::fromUtf8((const char*)(raw.data()), raw.size());
		item += ": ";
		item += plaintext;
	}

	return item;
}
コード例 #2
0
static Json::Value toJson(h256 const& _h, shh::Envelope const& _e, shh::Message const& _m)
{
	Json::Value res;
	res["hash"] = toJS(_h);
	res["expiry"] = (int)_e.expiry();
	res["sent"] = (int)_e.sent();
	res["ttl"] = (int)_e.ttl();
	res["workProved"] = (int)_e.workProved();
	for (auto const& t: _e.topic())
		res["topic"].append(toJS(t));
	res["payload"] = toJS(_m.payload());
	res["from"] = toJS(_m.from());
	res["to"] = toJS(_m.to());
	return res;
}