Add support for zboard topics
This commit is contained in:
parent
b60d65ee82
commit
8dec650c65
|
@ -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
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");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -82,7 +82,7 @@
|
|||
<item row="0" column="0" colspan="2">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string><html><head/><body><p>ZBoard: Fully anonymous and untraceable chat messages based on the ZCash blockchain. <a href="http://www.z-board.net/"><span style=" text-decoration: underline; color:#0000ff;">http://www.z-board.net/</span></a></p><p>Posting to ZBoard: #Main_Area</p></body></html></string>
|
||||
<string><html><head/><body><p>ZBoard: Fully anonymous and untraceable chat messages based on the ZCash blockchain. <a href="http://www.z-board.net/"><span style=" text-decoration: underline; color:#0000ff;">http://www.z-board.net/</span></a></p></body></html></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…
Reference in New Issue