Browse Source

Add support for zboard topics

import_zecw
adityapk 6 years ago
parent
commit
8dec650c65
  1. 16
      src/mainwindow.cpp
  2. 54
      src/rpc.cpp
  3. 2
      src/rpc.h
  4. 12
      src/zboard.ui

16
src/mainwindow.cpp

@ -458,6 +458,18 @@ void MainWindow::postToZBoard() {
}
}
QMap<QString, QString> topics;
// Insert the main topic automatically
topics.insert("#Main_Area", Utils::getZboardAddr());
zb.topicsList->addItem(topics.firstKey());
// Then call the API to get topics, and if it returns successfully, then add the rest of the topics
rpc->getZboardTopics([&](QMap<QString, QString> topicsMap) {
for (auto t : topicsMap.keys()) {
topics.insert(t, topicsMap[t]);
zb.topicsList->addItem(t);
}
});
// Testnet warning
if (Settings::getInstance()->isTestnet()) {
zb.testnetWarning->setText("You are on testnet, your post won't actually appear on z-board.net");
@ -524,7 +536,8 @@ void MainWindow::postToZBoard() {
if (!zb.postAs->text().trimmed().isEmpty())
memo = zb.postAs->text().trimmed() + ":: " + memo;
tx.toAddrs.push_back(ToFields{ Utils::getZboardAddr(), Utils::getZboardAmount(), memo, memo.toUtf8().toHex() });
auto toAddr = topics[zb.topicsList->currentText()];
tx.toAddrs.push_back(ToFields{ toAddr, Utils::getZboardAmount(), memo, memo.toUtf8().toHex() });
tx.fee = Utils::getMinerFee();
json params = json::array();
@ -543,7 +556,6 @@ void MainWindow::postToZBoard() {
}
void MainWindow::doImport(QList<QString>* keys) {
qDebug() << keys->size();
if (keys->isEmpty()) {
delete keys;
ui->statusBar->showMessage("Private key import rescan finished");

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");
}
});
}

2
src/rpc.h

@ -36,7 +36,9 @@ public:
void refresh(bool force = false);
void refreshAddresses();
void refreshZECPrice();
void getZboardTopics(std::function<void(QMap<QString, QString>)> cb);
void fillTxJsonParams(json& params, Tx tx);
void sendZTransaction (json params, const std::function<void(json)>& cb);

12
src/zboard.ui

@ -82,7 +82,7 @@
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="label_2">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;ZBoard: Fully anonymous and untraceable chat messages based on the ZCash blockchain. &lt;a href=&quot;http://www.z-board.net/&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;http://www.z-board.net/&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Posting to ZBoard: #Main_Area&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;ZBoard: Fully anonymous and untraceable chat messages based on the ZCash blockchain. &lt;a href=&quot;http://www.z-board.net/&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;http://www.z-board.net/&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="wordWrap">
<bool>true</bool>
@ -115,6 +115,16 @@
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="topicsList"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Posting to Board</string>
</property>
</widget>
</item>
</layout>
</widget>
<tabstops>

Loading…
Cancel
Save