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;
}
Beispiel #2
0
shh::Envelope toSealed(Json::Value const& _json, shh::Message const& _m, Secret _from)
{
    unsigned ttl = 50;
    unsigned workToProve = 50;
    shh::BuildTopic bt;

    if (!_json["ttl"].empty())
        ttl = jsToInt(_json["ttl"].asString());

    if (!_json["workToProve"].empty())
        workToProve = jsToInt(_json["workToProve"].asString());

    if (!_json["topics"].empty())
        for (auto i: _json["topics"])
        {
            if (i.isArray())
            {
                for (auto j: i)
                    if (!j.isNull())
                        bt.shift(jsToBytes(j.asString()));
            }
            else if (!i.isNull()) // if it is anything else then string, it should and will fail
                bt.shift(jsToBytes(i.asString()));
        }

    return _m.seal(_from, bt, ttl, workToProve);
}
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;
}
static shh::Envelope toSealed(Json::Value const& _json, shh::Message const& _m, Secret _from)
{
	unsigned ttl = 50;
	unsigned workToProve = 50;
	shh::BuildTopic bt;

	if (_json["ttl"].isInt())
		ttl = _json["ttl"].asInt();
	if (_json["workToProve"].isInt())
		workToProve = _json["workToProve"].asInt();
	if (!_json["topic"].empty())
	{
		if (_json["topic"].isString())
			bt.shift(jsToBytes(_json["topic"].asString()));
		else if (_json["topic"].isArray())
			for (auto i: _json["topic"])
				if (i.isString())
					bt.shift(jsToBytes(i.asString()));
	}
	return _m.seal(_from, bt, ttl, workToProve);
}