Add support for zboard topics
This commit is contained in:
54
src/rpc.cpp
54
src/rpc.cpp
@@ -807,3 +807,57 @@ void RPC::refreshZECPrice() {
|
||||
Settings::getInstance()->setZECPrice(0);
|
||||
});
|
||||
}
|
||||
|
||||
// Fetch the Z-board topics list
|
||||
void RPC::getZboardTopics(std::function<void(QMap<QString, QString>)> cb) {
|
||||
if (conn == nullptr)
|
||||
return noConnection();
|
||||
|
||||
QUrl cmcURL("http://z-board.net/listTopics");
|
||||
|
||||
QNetworkRequest req;
|
||||
req.setUrl(cmcURL);
|
||||
|
||||
QNetworkReply *reply = conn->restclient->get(req);
|
||||
|
||||
QObject::connect(reply, &QNetworkReply::finished, [=] {
|
||||
reply->deleteLater();
|
||||
|
||||
try {
|
||||
if (reply->error() != QNetworkReply::NoError) {
|
||||
auto parsed = json::parse(reply->readAll(), nullptr, false);
|
||||
if (!parsed.is_discarded() && !parsed["error"]["message"].is_null()) {
|
||||
qDebug() << QString::fromStdString(parsed["error"]["message"]);
|
||||
}
|
||||
else {
|
||||
qDebug() << reply->errorString();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
auto all = reply->readAll();
|
||||
|
||||
auto parsed = json::parse(all, nullptr, false);
|
||||
if (parsed.is_discarded()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QMap<QString, QString> topics;
|
||||
for (const json& item : parsed["topics"].get<json::array_t>()) {
|
||||
if (item.find("addr") == item.end() || item.find("topicName") == item.end())
|
||||
return;
|
||||
|
||||
QString addr = QString::fromStdString(item["addr"].get<json::string_t>());
|
||||
QString topic = QString::fromStdString(item["topicName"].get<json::string_t>());
|
||||
|
||||
topics.insert(topic, addr);
|
||||
}
|
||||
|
||||
cb(topics);
|
||||
}
|
||||
catch (...) {
|
||||
// If anything at all goes wrong, just set the price to 0 and move on.
|
||||
qDebug() << QString("Caught something nasty");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user