Qtification "lite" - first round
This commit is contained in:
18928
src/3rdparty/json/json.hpp
vendored
18928
src/3rdparty/json/json.hpp
vendored
File diff suppressed because it is too large
Load Diff
@@ -59,15 +59,16 @@ void ChatDataStore::setPassword(QString password)
|
||||
|
||||
QString ChatDataStore::dump()
|
||||
{
|
||||
json chats;
|
||||
chats["count"] = this->data.size();
|
||||
json j = {};
|
||||
QJsonObject chats;
|
||||
chats["count"] = (qint64)this->data.size();
|
||||
QJsonArray j;
|
||||
for (auto &c: this->data)
|
||||
{
|
||||
j.push_back(c.second.toJson());
|
||||
}
|
||||
chats["chatitems"] = j;
|
||||
return QString::fromStdString(chats.dump());
|
||||
QJsonDocument jd_chats = QJsonDocument(chats);
|
||||
return QLatin1String(jd_chats.toJson(QJsonDocument::Compact));
|
||||
}
|
||||
|
||||
std::map<QString, ChatItem> ChatDataStore::getAllRawChatItems()
|
||||
@@ -136,4 +137,4 @@ std::map<QString, ChatItem> ChatDataStore::getAllMemos()
|
||||
|
||||
|
||||
ChatDataStore* ChatDataStore::instance = nullptr;
|
||||
bool ChatDataStore::instanced = false;
|
||||
bool ChatDataStore::instanced = false;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#ifndef CHATDATASTORE_H
|
||||
#define CHATDATASTORE_H
|
||||
#include "../chatmodel.h"
|
||||
using json = nlohmann::json;
|
||||
|
||||
class ChatDataStore
|
||||
{
|
||||
@@ -45,4 +44,4 @@ class ChatDataStore
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -33,9 +33,9 @@ ContactItem ContactDataStore::getData(QString key)
|
||||
|
||||
QString ContactDataStore::dump()
|
||||
{
|
||||
json contacts;
|
||||
contacts["count"] = this->data.size();
|
||||
json j = {};
|
||||
QJsonObject contacts;
|
||||
contacts["count"] = (qint64)this->data.size();
|
||||
QJsonArray j = {};
|
||||
for (auto &c: this->data)
|
||||
{
|
||||
qDebug() << c.second.toQTString();
|
||||
@@ -43,8 +43,11 @@ QString ContactDataStore::dump()
|
||||
j.push_back(c.second.toJson());
|
||||
}
|
||||
contacts["contacts"] = j;
|
||||
return QString::fromStdString(contacts.dump(4));
|
||||
QJsonDocument jd_contacts = QJsonDocument(contacts);
|
||||
return QLatin1String(jd_contacts.toJson(QJsonDocument::Compact));
|
||||
|
||||
// return QString::fromStdString(contacts.dump(4));
|
||||
}
|
||||
|
||||
ContactDataStore* ContactDataStore::instance = nullptr;
|
||||
bool ContactDataStore::instanced = false;
|
||||
bool ContactDataStore::instanced = false;
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
#define CONTACTDATASTORE_H
|
||||
#include "../Model/ContactItem.h"
|
||||
#include <string>
|
||||
using json = nlohmann::json;
|
||||
|
||||
class ContactDataStore
|
||||
{
|
||||
@@ -31,4 +30,4 @@ class ContactDataStore
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
#ifndef SIETCHDATASTORE_H
|
||||
#define SIETCHDATASTORE_H
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
class SietchDataStore
|
||||
{
|
||||
private:
|
||||
@@ -28,4 +26,4 @@ class SietchDataStore
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include "../Model/ContactItem.h"
|
||||
#include "../Crypto/FileEncryption.h"
|
||||
#include <fstream>
|
||||
using json = nlohmann::json;
|
||||
|
||||
class FileSystem
|
||||
{
|
||||
private:
|
||||
@@ -28,4 +28,4 @@ class FileSystem
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -184,17 +184,17 @@ QString ChatItem::toChatLine()
|
||||
return line;
|
||||
}
|
||||
|
||||
json ChatItem::toJson()
|
||||
QJsonValue ChatItem::toJson()
|
||||
{
|
||||
json j;
|
||||
j["_timestamp"] = _timestamp;
|
||||
j["_address"] = _address.toStdString();
|
||||
j["_contact"] = _contact.toStdString();
|
||||
j["_memo"] = _memo.toStdString();
|
||||
j["_requestZaddr"] = _requestZaddr.toStdString();
|
||||
j["_type"] = _type.toStdString();
|
||||
j["_cid"] = _cid.toStdString();
|
||||
j["_txid"] = _txid.toStdString();
|
||||
QJsonObject j;
|
||||
j["_timestamp"] = (qint64)_timestamp;
|
||||
j["_address"] = _address;
|
||||
j["_contact"] = _contact;
|
||||
j["_memo"] = _memo;
|
||||
j["_requestZaddr"] = _requestZaddr;
|
||||
j["_type"] = _type;
|
||||
j["_cid"] = _cid;
|
||||
j["_txid"] = _txid;
|
||||
j["_confirmations"] = _confirmations;
|
||||
j["_outgoing"] = _outgoing;
|
||||
return j;
|
||||
@@ -203,4 +203,4 @@ json ChatItem::toJson()
|
||||
ChatItem::~ChatItem()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#define CHATITEM_H
|
||||
|
||||
#include <QString>
|
||||
using json = nlohmann::json;
|
||||
|
||||
class ChatItem
|
||||
{
|
||||
@@ -53,8 +52,8 @@ class ChatItem
|
||||
void notarized();
|
||||
void contact(bool iscontact);
|
||||
QString toChatLine();
|
||||
json toJson();
|
||||
QJsonValue toJson();
|
||||
~ChatItem();
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -86,13 +86,13 @@ QString ContactItem::toQTString()
|
||||
return _name + "|" + _partnerAddress + "|" + _myAddress + "|" + _cid + "|" + _avatar;
|
||||
}
|
||||
|
||||
json ContactItem::toJson()
|
||||
QJsonValue ContactItem::toJson()
|
||||
{
|
||||
json j;
|
||||
j["_myAddress"] = _myAddress.toStdString();
|
||||
j["_partnerAddress"] = _partnerAddress.toStdString();
|
||||
j["_name"] = _name.toStdString();
|
||||
j["_cid"] = _cid.toStdString();
|
||||
j["_avatar"] = _avatar.toStdString();
|
||||
QJsonObject j;
|
||||
j["_myAddress"] = _myAddress;
|
||||
j["_partnerAddress"] = _partnerAddress;
|
||||
j["_name"] = _name;
|
||||
j["_cid"] = _cid;
|
||||
j["_avatar"] = _avatar;
|
||||
return j;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
#include <vector>
|
||||
#include <QString>
|
||||
#include "mainwindow.h"
|
||||
using json = nlohmann::json;
|
||||
|
||||
class ContactItem
|
||||
{
|
||||
@@ -34,7 +33,7 @@ public:
|
||||
void setcid(QString cid);
|
||||
void setAvatar(QString avatar);
|
||||
QString toQTString();
|
||||
json toJson();
|
||||
QJsonValue toJson();
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -93,4 +93,4 @@ void ContactRequest::clear()
|
||||
ContactRequest::~ContactRequest()
|
||||
{
|
||||
clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#define CONTACTREQUEST_H
|
||||
|
||||
#include <QString>
|
||||
using json = nlohmann::json;
|
||||
|
||||
class ContactRequest
|
||||
{
|
||||
@@ -37,4 +36,4 @@ class ContactRequest
|
||||
~ContactRequest();
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -153,8 +153,8 @@ void AddressBook::open(MainWindow* parent, QLineEdit* target)
|
||||
bool sapling = true;
|
||||
try
|
||||
{
|
||||
rpc->createNewZaddr(sapling, [=] (json reply) {
|
||||
QString myAddr = QString::fromStdString(reply.get<json::array_t>()[0]);
|
||||
rpc->createNewZaddr(sapling, [=] (QJsonValue reply) {
|
||||
QString myAddr = reply.toArray()[0].toString();
|
||||
QString message = QString("New Chat Address for your partner: ") + myAddr;
|
||||
QString cid = QUuid::createUuid().toString(QUuid::WithoutBraces);
|
||||
|
||||
|
||||
@@ -696,97 +696,85 @@ void::MainWindow::addContact()
|
||||
request.setupUi(&dialog);
|
||||
Settings::saveRestore(&dialog);
|
||||
|
||||
|
||||
try
|
||||
try
|
||||
{
|
||||
bool sapling = true;
|
||||
rpc->createNewZaddr(sapling, [=] (json reply) {
|
||||
QString myAddr = QString::fromStdString(reply.get<json::array_t>()[0]);
|
||||
rpc->refreshAddresses();
|
||||
request.myzaddr->setText(myAddr);
|
||||
ui->listReceiveAddresses->insertItem(0, myAddr);
|
||||
ui->listReceiveAddresses->setCurrentIndex(0);
|
||||
DataStore::getChatDataStore()->setSendZaddr(myAddr);
|
||||
bool sapling = true;
|
||||
rpc->createNewZaddr(sapling, [=] (QJsonValue reply) {
|
||||
QString myAddr = reply.toArray()[0].toString();
|
||||
rpc->refreshAddresses();
|
||||
request.myzaddr->setText(myAddr);
|
||||
ui->listReceiveAddresses->insertItem(0, myAddr);
|
||||
ui->listReceiveAddresses->setCurrentIndex(0);
|
||||
DataStore::getChatDataStore()->setSendZaddr(myAddr);
|
||||
|
||||
qDebug()<<"Zaddr: "<<myAddr;
|
||||
});
|
||||
qDebug()<<"Zaddr: "<<myAddr;
|
||||
});
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
qDebug() << QString("Caught something nasty with myZaddr Contact");
|
||||
}
|
||||
|
||||
}catch(...)
|
||||
{
|
||||
QString cid = QUuid::createUuid().toString(QUuid::WithoutBraces);
|
||||
|
||||
|
||||
qDebug() << QString("Caught something nasty with myZaddr Contact");
|
||||
}
|
||||
QObject::connect(request.sendRequestButton, &QPushButton::clicked, this, &MainWindow::saveandsendContact);
|
||||
|
||||
|
||||
QString cid = QUuid::createUuid().toString(QUuid::WithoutBraces);
|
||||
|
||||
QObject::connect(request.sendRequestButton, &QPushButton::clicked, this, &MainWindow::saveandsendContact);
|
||||
|
||||
|
||||
|
||||
// QObject::connect(request.onlyAdd, &QPushButton::clicked, this, &MainWindow::saveContact);
|
||||
// QObject::connect(request.onlyAdd, &QPushButton::clicked, this, &MainWindow::saveContact);
|
||||
|
||||
dialog.exec();
|
||||
|
||||
rpc->refreshContacts(ui->listContactWidget);
|
||||
|
||||
}
|
||||
|
||||
void MainWindow::saveandsendContact()
|
||||
{
|
||||
this->ContactRequest();
|
||||
|
||||
this->ContactRequest();
|
||||
}
|
||||
|
||||
// Create a Tx for a contact Request
|
||||
Tx MainWindow::createTxForSafeContactRequest()
|
||||
{
|
||||
Tx tx;
|
||||
{
|
||||
CAmount totalAmt;
|
||||
QString amtStr = "0";
|
||||
CAmount amt;
|
||||
QString headerbytes = "";
|
||||
amt = CAmount::fromDecimalString("0");
|
||||
totalAmt = totalAmt + amt;
|
||||
{
|
||||
CAmount totalAmt;
|
||||
QString amtStr = "0";
|
||||
CAmount amt;
|
||||
QString headerbytes = "";
|
||||
amt = CAmount::fromDecimalString("0");
|
||||
totalAmt = totalAmt + amt;
|
||||
|
||||
QString cid = contactRequest.getCid();
|
||||
QString myAddr = DataStore::getChatDataStore()->getSendZaddr();
|
||||
QString type = "Cont";
|
||||
QString addr = contactRequest.getReceiverAddress();
|
||||
QString cid = contactRequest.getCid();
|
||||
QString myAddr = DataStore::getChatDataStore()->getSendZaddr();
|
||||
QString type = "Cont";
|
||||
QString addr = contactRequest.getReceiverAddress();
|
||||
|
||||
|
||||
QString memo = contactRequest.getMemo();
|
||||
QString passphrase = DataStore::getChatDataStore()->getPassword();
|
||||
int length = passphrase.length();
|
||||
|
||||
////////////////Generate the secretkey for our message encryption
|
||||
char *hashEncryptionKeyraw = NULL;
|
||||
hashEncryptionKeyraw = new char[length+1];
|
||||
strncpy(hashEncryptionKeyraw, passphrase.toUtf8(), length +1);
|
||||
QString memo = contactRequest.getMemo();
|
||||
QString passphrase = DataStore::getChatDataStore()->getPassword();
|
||||
int length = passphrase.length();
|
||||
|
||||
////////////////Generate the secretkey for our message encryption
|
||||
char *hashEncryptionKeyraw = NULL;
|
||||
hashEncryptionKeyraw = new char[length+1];
|
||||
strncpy(hashEncryptionKeyraw, passphrase.toUtf8(), length +1);
|
||||
|
||||
#define MESSAGEAS1 ((const unsigned char *) hashEncryptionKeyraw)
|
||||
#define MESSAGEAS1_LEN length
|
||||
|
||||
unsigned char sk[crypto_kx_SECRETKEYBYTES];
|
||||
unsigned char pk[crypto_kx_PUBLICKEYBYTES];
|
||||
|
||||
if (crypto_kx_seed_keypair(pk,sk,
|
||||
MESSAGEAS1) !=0) {
|
||||
}
|
||||
unsigned char sk[crypto_kx_SECRETKEYBYTES];
|
||||
unsigned char pk[crypto_kx_PUBLICKEYBYTES];
|
||||
|
||||
QString publicKey = QByteArray(reinterpret_cast<const char*>(pk), crypto_kx_PUBLICKEYBYTES).toHex();
|
||||
if (crypto_kx_seed_keypair(pk, sk, MESSAGEAS1) !=0) {
|
||||
//
|
||||
}
|
||||
|
||||
QString hmemo= createHeaderMemo(type,cid,myAddr,"", publicKey);
|
||||
QString publicKey = QByteArray(reinterpret_cast<const char*>(pk), crypto_kx_PUBLICKEYBYTES).toHex();
|
||||
QString hmemo= createHeaderMemo(type,cid,myAddr,"", publicKey);
|
||||
|
||||
tx.toAddrs.push_back(ToFields{addr, amt, hmemo});
|
||||
tx.toAddrs.push_back(ToFields{addr, amt, memo});
|
||||
tx.fee = Settings::getMinerFee();
|
||||
}
|
||||
|
||||
|
||||
tx.toAddrs.push_back(ToFields{addr, amt, hmemo});
|
||||
tx.toAddrs.push_back(ToFields{addr, amt, memo});
|
||||
tx.fee = Settings::getMinerFee();
|
||||
|
||||
}
|
||||
|
||||
return tx;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
#include "../lib/silentdragonlitelib.h"
|
||||
#include "precompiled.h"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
ConnectionLoader::ConnectionLoader(MainWindow* main, Controller* rpc)
|
||||
{
|
||||
this->main = main;
|
||||
@@ -93,17 +91,17 @@ void ConnectionLoader::doAutoConnect()
|
||||
auto me = this;
|
||||
|
||||
// After the lib is initialized, try to do get info
|
||||
connection->doRPC("info", "", [=](auto reply) {
|
||||
connection->doRPC("info", "", [=](QJsonValue reply) {
|
||||
// If success, set the connection
|
||||
main->logger->write("Connection is online.");
|
||||
connection->setInfo(reply);
|
||||
isSyncing = new QAtomicInteger<bool>();
|
||||
isSyncing->store(true);
|
||||
isSyncing->storeRelaxed(true);
|
||||
|
||||
// Do a sync at startup
|
||||
syncTimer = new QTimer(main);
|
||||
connection->doRPCWithDefaultErrorHandling("sync", "", [=](auto) {
|
||||
isSyncing->store(false);
|
||||
connection->doRPCWithDefaultErrorHandling("sync", "", [=](QJsonValue) {
|
||||
isSyncing->storeRelaxed(false);
|
||||
// Cancel the timer
|
||||
syncTimer->deleteLater();
|
||||
// When sync is done, set the connection
|
||||
@@ -113,13 +111,13 @@ void ConnectionLoader::doAutoConnect()
|
||||
// While it is syncing, we'll show the status updates while it is alive.
|
||||
QObject::connect(syncTimer, &QTimer::timeout, [=]() {
|
||||
// Check the sync status
|
||||
if (isSyncing != nullptr && isSyncing->load()) {
|
||||
if (isSyncing != nullptr && isSyncing->loadRelaxed()) {
|
||||
// Get the sync status
|
||||
connection->doRPC("syncstatus", "", [=](json reply) {
|
||||
if (isSyncing != nullptr && reply.find("synced_blocks") != reply.end())
|
||||
connection->doRPC("syncstatus", "", [=](QJsonValue reply) {
|
||||
if (isSyncing != nullptr && !reply.toObject()["synced_blocks"].isUndefined())
|
||||
{
|
||||
qint64 synced = reply["synced_blocks"].get<json::number_unsigned_t>();
|
||||
qint64 total = reply["total_blocks"].get<json::number_unsigned_t>();
|
||||
qint64 synced = reply["synced_blocks"].toInt();
|
||||
qint64 total = reply["total_blocks"].toInt();
|
||||
me->showInformation(
|
||||
"Synced " + QString::number(synced) + " / " + QString::number(total)
|
||||
);
|
||||
@@ -202,21 +200,26 @@ void Executor::run()
|
||||
{
|
||||
char* resp = litelib_execute(this->cmd.toStdString().c_str(), this->args.toStdString().c_str());
|
||||
QString reply = litelib_process_response(resp);
|
||||
//qDebug() << "RPC Reply=" << reply;
|
||||
auto parsed = json::parse(
|
||||
reply.toStdString().c_str(),
|
||||
nullptr,
|
||||
false
|
||||
);
|
||||
if (parsed.is_discarded() || parsed.is_null())
|
||||
QJsonDocument parsed = QJsonDocument::fromJson(reply.toUtf8());
|
||||
|
||||
if (parsed.isEmpty() || parsed.isNull())
|
||||
emit handleError(reply);
|
||||
|
||||
else
|
||||
emit responseReady(parsed);
|
||||
{
|
||||
QJsonValue retval;
|
||||
|
||||
if (parsed.isObject())
|
||||
retval = QJsonValue(parsed.object());
|
||||
else if (parsed.isArray())
|
||||
retval = QJsonValue(parsed.array());
|
||||
|
||||
emit responseReady(retval);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Callback::processRPCCallback(json resp)
|
||||
void Callback::processRPCCallback(QJsonValue resp)
|
||||
{
|
||||
this->cb(resp);
|
||||
// Destroy self
|
||||
@@ -235,10 +238,10 @@ Connection::Connection(MainWindow* m, std::shared_ptr<ConnectionConfig> conf)
|
||||
this->config = conf;
|
||||
this->main = m;
|
||||
// Register the JSON type as a type that can be passed between signals and slots.
|
||||
qRegisterMetaType<json>("json");
|
||||
qRegisterMetaType<QJsonValue>("QJsonValue");
|
||||
}
|
||||
|
||||
void Connection::doRPC(const QString cmd, const QString args, const std::function<void(json)>& cb, const std::function<void(QString)>& errCb)
|
||||
void Connection::doRPC(const QString cmd, const QString args, const std::function<void(QJsonValue)>& cb, const std::function<void(QString)>& errCb)
|
||||
{
|
||||
if (shutdownInProgress)
|
||||
// Ignoring RPC because shutdown in progress
|
||||
@@ -257,14 +260,14 @@ void Connection::doRPC(const QString cmd, const QString args, const std::functio
|
||||
QThreadPool::globalInstance()->start(runner);
|
||||
}
|
||||
|
||||
void Connection::doRPCWithDefaultErrorHandling(const QString cmd, const QString args, const std::function<void(json)>& cb)
|
||||
void Connection::doRPCWithDefaultErrorHandling(const QString cmd, const QString args, const std::function<void(QJsonValue)>& cb)
|
||||
{
|
||||
doRPC(cmd, args, cb, [=] (QString err) {
|
||||
this->showTxError(err);
|
||||
});
|
||||
}
|
||||
|
||||
void Connection::doRPCIgnoreError(const QString cmd, const QString args, const std::function<void(json)>& cb)
|
||||
void Connection::doRPCIgnoreError(const QString cmd, const QString args, const std::function<void(QJsonValue)>& cb)
|
||||
{
|
||||
doRPC(cmd, args, cb, [=] (auto) {
|
||||
// Ignored error handling
|
||||
|
||||
@@ -6,8 +6,6 @@
|
||||
#include "precompiled.h"
|
||||
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
class Controller;
|
||||
|
||||
struct ConnectionConfig {
|
||||
@@ -57,15 +55,15 @@ private:
|
||||
class Callback: public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Callback(const std::function<void(json)> cb, const std::function<void(QString)> errCb) { this->cb = cb; this->errCb = errCb;}
|
||||
Callback(const std::function<void(QJsonValue)> cb, const std::function<void(QString)> errCb) { this->cb = cb; this->errCb = errCb;}
|
||||
~Callback() = default;
|
||||
|
||||
public slots:
|
||||
void processRPCCallback(json resp);
|
||||
void processRPCCallback(QJsonValue resp);
|
||||
void processError(QString error);
|
||||
|
||||
private:
|
||||
std::function<void(json)> cb;
|
||||
private:
|
||||
std::function<void(QJsonValue)> cb;
|
||||
std::function<void(QString)> errCb;
|
||||
|
||||
};
|
||||
@@ -73,14 +71,14 @@ private:
|
||||
/**
|
||||
* A runnable that runs some lightclient Command in a non-UI thread.
|
||||
* It emits the "responseReady" signal, which should be processed in a GUI thread.
|
||||
*
|
||||
*
|
||||
* Since the autoDelete flag is ON, the runnable should be destroyed automatically
|
||||
* by the threadpool.
|
||||
* by the threadpool.
|
||||
*/
|
||||
class Executor : public QObject, public QRunnable {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
public:
|
||||
Executor(QString cmd, QString args) {
|
||||
this->cmd = cmd;
|
||||
this->args = args;
|
||||
@@ -92,12 +90,12 @@ public:
|
||||
virtual void run();
|
||||
|
||||
signals:
|
||||
void responseReady(json);
|
||||
void responseReady(QJsonValue);
|
||||
void handleError(QString);
|
||||
|
||||
private:
|
||||
QString cmd;
|
||||
QString args;
|
||||
QString args;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -116,20 +114,20 @@ public:
|
||||
|
||||
void shutdown();
|
||||
|
||||
|
||||
void doRPC(const QString cmd, const QString args, const std::function<void(json)>& cb,
|
||||
|
||||
void doRPC(const QString cmd, const QString args, const std::function<void(QJsonValue)>& cb,
|
||||
const std::function<void(QString)>& errCb);
|
||||
void doRPCWithDefaultErrorHandling(const QString cmd, const QString args, const std::function<void(json)>& cb);
|
||||
void doRPCIgnoreError(const QString cmd, const QString args, const std::function<void(json)>& cb) ;
|
||||
void doRPCWithDefaultErrorHandling(const QString cmd, const QString args, const std::function<void(QJsonValue)>& cb);
|
||||
void doRPCIgnoreError(const QString cmd, const QString args, const std::function<void(QJsonValue)>& cb) ;
|
||||
|
||||
void showTxError(const QString& error);
|
||||
|
||||
json getInfo() { return serverInfo; }
|
||||
void setInfo(const json& info) { serverInfo = info; }
|
||||
QJsonValue getInfo() { return serverInfo; }
|
||||
void setInfo(const QJsonValue& info) { serverInfo = info; }
|
||||
|
||||
private:
|
||||
bool shutdownInProgress = false;
|
||||
json serverInfo;
|
||||
QJsonValue serverInfo;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
1210
src/controller.cpp
1210
src/controller.cpp
File diff suppressed because it is too large
Load Diff
@@ -19,7 +19,6 @@
|
||||
#include "Model/ContactRequestChatItem.h"
|
||||
#include "Model/ContactItem.h"
|
||||
#include "contactmodel.h"
|
||||
using json = nlohmann::json;
|
||||
|
||||
struct WatchedTx {
|
||||
QString opid;
|
||||
@@ -40,7 +39,7 @@ public:
|
||||
Connection* getConnection() { return zrpc->getConnection(); }
|
||||
void setConnection(Connection* c);
|
||||
void refresh(bool force = false);
|
||||
void refreshAddresses();
|
||||
void refreshAddresses();
|
||||
int getLag();
|
||||
void setLag(int lag);
|
||||
int _lag;
|
||||
@@ -91,7 +90,7 @@ public:
|
||||
const std::function<void(QString txid)> submitted,
|
||||
const std::function<void(QString txid, QString errStr)> error);
|
||||
|
||||
void fillTxJsonParams(json& params, Tx tx);
|
||||
void fillTxJsonParams(QJsonArray ¶ms, Tx tx);
|
||||
|
||||
const TxTableModel* getTransactionsModel() { return transactionsTableModel; }
|
||||
|
||||
@@ -99,58 +98,58 @@ public:
|
||||
void noConnection();
|
||||
bool isEmbedded() { return ehushd != nullptr; }
|
||||
|
||||
void encryptWallet(QString password, const std::function<void(json)>& cb) {
|
||||
void encryptWallet(QString password, const std::function<void(QJsonValue)>& cb) {
|
||||
zrpc->encryptWallet(password, cb);
|
||||
}
|
||||
|
||||
void removeWalletEncryption(QString password, const std::function<void(json)>& cb) {
|
||||
void removeWalletEncryption(QString password, const std::function<void(QJsonValue)>& cb) {
|
||||
zrpc->removeWalletEncryption(password, cb); }
|
||||
|
||||
void saveWallet(const std::function<void(json)>& cb) { zrpc->saveWallet(cb); }
|
||||
void saveWallet(const std::function<void(QJsonValue)>& cb) { zrpc->saveWallet(cb); }
|
||||
|
||||
void clearWallet(const std::function<void(json)>& cb) { zrpc->clearWallet(cb); }
|
||||
void clearWallet(const std::function<void(QJsonValue)>& cb) { zrpc->clearWallet(cb); }
|
||||
|
||||
void createNewZaddr(bool sapling, const std::function<void(json)>& cb) {
|
||||
void createNewZaddr(bool sapling, const std::function<void(QJsonValue)>& cb) {
|
||||
unlockIfEncrypted([=] () {
|
||||
zrpc->createNewZaddr(sapling, cb);
|
||||
}, [=](){});
|
||||
}
|
||||
|
||||
|
||||
void createNewTaddr(const std::function<void(json)>& cb) {
|
||||
void createNewTaddr(const std::function<void(QJsonValue)>& cb) {
|
||||
unlockIfEncrypted([=] () {
|
||||
zrpc->createNewTaddr(cb);
|
||||
}, [=](){});
|
||||
}
|
||||
void createNewSietchZaddr(const std::function<void(json)>& cb) {
|
||||
void createNewSietchZaddr(const std::function<void(QJsonValue)>& cb) {
|
||||
unlockIfEncrypted([=] () {
|
||||
zrpc->createNewSietchZaddr(cb);
|
||||
}, [=](){});
|
||||
}
|
||||
void fetchPrivKey(QString addr, const std::function<void(json)>& cb) {
|
||||
void fetchPrivKey(QString addr, const std::function<void(QJsonValue)>& cb) {
|
||||
unlockIfEncrypted([=] () {
|
||||
zrpc->fetchPrivKey(addr, cb);
|
||||
},
|
||||
[=]() {
|
||||
cb({ {"error", "Failed to unlock wallet"} });
|
||||
cb(QJsonObject({ {"error", "Failed to unlock wallet"} }) );
|
||||
});
|
||||
}
|
||||
|
||||
void fetchAllPrivKeys(const std::function<void(json)> cb) {
|
||||
void fetchAllPrivKeys(const std::function<void(QJsonValue)> cb) {
|
||||
unlockIfEncrypted([=] () {
|
||||
zrpc->fetchAllPrivKeys(cb);
|
||||
},
|
||||
[=]() {
|
||||
cb({ {"error", "Failed to unlock wallet"} });
|
||||
cb(QJsonObject({ {"error", "Failed to unlock wallet"} }));
|
||||
});
|
||||
}
|
||||
|
||||
void fetchSeed(const std::function<void(json)> cb) {
|
||||
void fetchSeed(const std::function<void(QJsonValue)> cb) {
|
||||
unlockIfEncrypted([=] () {
|
||||
zrpc->fetchSeed(cb);
|
||||
},
|
||||
[=]() {
|
||||
cb({ {"error", "Failed to unlock wallet"} });
|
||||
cb(QJsonObject({ {"error", "Failed to unlock wallet"} }));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -163,12 +162,12 @@ public:
|
||||
|
||||
|
||||
private:
|
||||
void processInfo(const json&);
|
||||
void processInfo(const QJsonValue&);
|
||||
void refreshBalances();
|
||||
|
||||
void refreshTransactions();
|
||||
|
||||
void processUnspent (const json& reply, QMap<QString, CAmount>* newBalances, QList<UnspentOutput>* newUnspentOutputs);
|
||||
void processUnspent (const QJsonValue& reply, QMap<QString, CAmount>* newBalances, QList<UnspentOutput>* newUnspentOutputs);
|
||||
void updateUI (bool anyUnconfirmed);
|
||||
void updateUIBalances ();
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
|
||||
#include "../lib/silentdragonlitelib.h"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
FirstTimeWizard::FirstTimeWizard(bool dangerous, QString server)
|
||||
{
|
||||
@@ -173,14 +172,15 @@ void NewSeedPage::initializePage() {
|
||||
char* resp = litelib_initialize_new(parent->dangerous, parent->server.toStdString().c_str());
|
||||
QString reply = litelib_process_response(resp);
|
||||
|
||||
auto parsed = json::parse(reply.toStdString().c_str(), nullptr, false);
|
||||
if (parsed.is_discarded() || parsed.is_null() || parsed.find("seed") == parsed.end()) {
|
||||
QByteArray ba_reply = reply.toUtf8();
|
||||
QJsonDocument jd_reply = QJsonDocument::fromJson(ba_reply);
|
||||
QJsonObject parsed = jd_reply.object();
|
||||
|
||||
if (parsed.isEmpty() || parsed["seed"].isNull()) {
|
||||
form.txtSeed->setPlainText(tr("Error creating a wallet") + "\n" + reply);
|
||||
} else {
|
||||
QString seed = QString::fromStdString(parsed["seed"].get<json::string_t>());
|
||||
QString seed = parsed["seed"].toString();
|
||||
form.txtSeed->setPlainText(seed);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -192,8 +192,11 @@ bool NewSeedPage::validatePage() {
|
||||
char* resp = litelib_execute("save", "");
|
||||
QString reply = litelib_process_response(resp);
|
||||
|
||||
auto parsed = json::parse(reply.toStdString().c_str(), nullptr, false);
|
||||
if (parsed.is_discarded() || parsed.is_null() || parsed.find("result") == parsed.end()) {
|
||||
QByteArray ba_reply = reply.toUtf8();
|
||||
QJsonDocument jd_reply = QJsonDocument::fromJson(ba_reply);
|
||||
QJsonObject parsed = jd_reply.object();
|
||||
|
||||
if (parsed.isEmpty() || parsed["result"].isNull()) {
|
||||
QMessageBox::warning(this, tr("Failed to save wallet"),
|
||||
tr("Couldn't save the wallet") + "\n" + reply,
|
||||
QMessageBox::Ok);
|
||||
@@ -258,8 +261,11 @@ bool RestoreSeedPage::validatePage() {
|
||||
char* resp = litelib_execute("save", "");
|
||||
QString reply = litelib_process_response(resp);
|
||||
|
||||
auto parsed = json::parse(reply.toStdString().c_str(), nullptr, false);
|
||||
if (parsed.is_discarded() || parsed.is_null() || parsed.find("result") == parsed.end()) {
|
||||
QByteArray ba_reply = reply.toUtf8();
|
||||
QJsonDocument jd_reply = QJsonDocument::fromJson(ba_reply);
|
||||
QJsonObject parsed = jd_reply.object();
|
||||
|
||||
if (parsed.isEmpty() || parsed["result"].isNull()) {
|
||||
QMessageBox::warning(this, tr("Failed to save wallet"),
|
||||
tr("Couldn't save the wallet") + "\n" + reply,
|
||||
QMessageBox::Ok);
|
||||
|
||||
@@ -20,7 +20,7 @@ bool LiteInterface::haveConnection() {
|
||||
return conn != nullptr;
|
||||
}
|
||||
|
||||
void LiteInterface::fetchAddresses(const std::function<void(json)>& cb) {
|
||||
void LiteInterface::fetchAddresses(const std::function<void(QJsonValue)>& cb) {
|
||||
if (conn == nullptr)
|
||||
return;
|
||||
|
||||
@@ -28,21 +28,21 @@ void LiteInterface::fetchAddresses(const std::function<void(json)>& cb) {
|
||||
}
|
||||
|
||||
|
||||
void LiteInterface::fetchUnspent(const std::function<void(json)>& cb) {
|
||||
void LiteInterface::fetchUnspent(const std::function<void(QJsonValue)>& cb) {
|
||||
if (conn == nullptr)
|
||||
return;
|
||||
|
||||
conn->doRPCWithDefaultErrorHandling("notes", "", cb);
|
||||
}
|
||||
|
||||
void LiteInterface::createNewZaddr(bool, const std::function<void(json)>& cb) {
|
||||
void LiteInterface::createNewZaddr(bool, const std::function<void(QJsonValue)>& cb) {
|
||||
if (conn == nullptr)
|
||||
return;
|
||||
|
||||
conn->doRPCWithDefaultErrorHandling("new", "zs", cb);
|
||||
}
|
||||
|
||||
void LiteInterface::createNewSietchZaddr(const std::function<void(json)>& cb) {
|
||||
void LiteInterface::createNewSietchZaddr(const std::function<void(QJsonValue)>& cb) {
|
||||
if (conn == nullptr)
|
||||
return;
|
||||
|
||||
@@ -50,70 +50,70 @@ void LiteInterface::createNewSietchZaddr(const std::function<void(json)>& cb) {
|
||||
|
||||
}
|
||||
|
||||
void LiteInterface::createNewTaddr(const std::function<void(json)>& cb) {
|
||||
void LiteInterface::createNewTaddr(const std::function<void(QJsonValue)>& cb) {
|
||||
if (conn == nullptr)
|
||||
return;
|
||||
|
||||
conn->doRPCWithDefaultErrorHandling("new", "R", cb);
|
||||
}
|
||||
|
||||
void LiteInterface::fetchPrivKey(QString addr, const std::function<void(json)>& cb) {
|
||||
void LiteInterface::fetchPrivKey(QString addr, const std::function<void(QJsonValue)>& cb) {
|
||||
if (conn == nullptr)
|
||||
return;
|
||||
|
||||
conn->doRPCWithDefaultErrorHandling("export", addr, cb);
|
||||
}
|
||||
|
||||
void LiteInterface::fetchSeed(const std::function<void(json)>& cb) {
|
||||
void LiteInterface::fetchSeed(const std::function<void(QJsonValue)>& cb) {
|
||||
if (conn == nullptr)
|
||||
return;
|
||||
|
||||
conn->doRPCWithDefaultErrorHandling("seed", "", cb);
|
||||
}
|
||||
|
||||
void LiteInterface::fetchBalance(const std::function<void(json)>& cb) {
|
||||
void LiteInterface::fetchBalance(const std::function<void(QJsonValue)>& cb) {
|
||||
if (conn == nullptr)
|
||||
return;
|
||||
|
||||
conn->doRPCWithDefaultErrorHandling("balance", "", cb);
|
||||
}
|
||||
|
||||
void LiteInterface::fetchTransactions(const std::function<void(json)>& cb) {
|
||||
void LiteInterface::fetchTransactions(const std::function<void(QJsonValue)>& cb) {
|
||||
if (conn == nullptr)
|
||||
return;
|
||||
|
||||
conn->doRPCWithDefaultErrorHandling("list", "", cb);
|
||||
}
|
||||
|
||||
void LiteInterface::saveWallet(const std::function<void(json)>& cb) {
|
||||
void LiteInterface::saveWallet(const std::function<void(QJsonValue)>& cb) {
|
||||
if (conn == nullptr)
|
||||
return;
|
||||
|
||||
conn->doRPCWithDefaultErrorHandling("save", "", cb);
|
||||
}
|
||||
|
||||
void LiteInterface::clearWallet(const std::function<void(json)>& cb) {
|
||||
void LiteInterface::clearWallet(const std::function<void(QJsonValue)>& cb) {
|
||||
if (conn == nullptr)
|
||||
return;
|
||||
|
||||
conn->doRPCWithDefaultErrorHandling("clear", "", cb);
|
||||
}
|
||||
|
||||
void LiteInterface::unlockWallet(QString password, const std::function<void(json)>& cb) {
|
||||
void LiteInterface::unlockWallet(QString password, const std::function<void(QJsonValue)>& cb) {
|
||||
if (conn == nullptr)
|
||||
return;
|
||||
|
||||
conn->doRPCWithDefaultErrorHandling("unlock", password, cb);
|
||||
}
|
||||
|
||||
void LiteInterface::fetchWalletEncryptionStatus(const std::function<void(json)>& cb) {
|
||||
void LiteInterface::fetchWalletEncryptionStatus(const std::function<void(QJsonValue)>& cb) {
|
||||
if (conn == nullptr)
|
||||
return;
|
||||
|
||||
conn->doRPCWithDefaultErrorHandling("encryptionstatus", "", cb);
|
||||
}
|
||||
|
||||
void LiteInterface::encryptWallet(QString password, const std::function<void(json)>& cb) {
|
||||
void LiteInterface::encryptWallet(QString password, const std::function<void(QJsonValue)>& cb) {
|
||||
if (conn == nullptr)
|
||||
return;
|
||||
|
||||
@@ -121,7 +121,7 @@ void LiteInterface::encryptWallet(QString password, const std::function<void(jso
|
||||
}
|
||||
|
||||
|
||||
void LiteInterface::removeWalletEncryption(QString password, const std::function<void(json)>& cb) {
|
||||
void LiteInterface::removeWalletEncryption(QString password, const std::function<void(QJsonValue)>& cb) {
|
||||
if (conn == nullptr)
|
||||
return;
|
||||
|
||||
@@ -129,7 +129,7 @@ void LiteInterface::removeWalletEncryption(QString password, const std::function
|
||||
}
|
||||
|
||||
|
||||
void LiteInterface::sendTransaction(QString params, const std::function<void(json)>& cb,
|
||||
void LiteInterface::sendTransaction(QString params, const std::function<void(QJsonValue)>& cb,
|
||||
const std::function<void(QString)>& err) {
|
||||
if (conn == nullptr)
|
||||
return;
|
||||
@@ -137,7 +137,7 @@ void LiteInterface::sendTransaction(QString params, const std::function<void(jso
|
||||
conn->doRPC("send", params, cb, err);
|
||||
}
|
||||
|
||||
void LiteInterface::fetchInfo(const std::function<void(json)>& cb,
|
||||
void LiteInterface::fetchInfo(const std::function<void(QJsonValue)>& cb,
|
||||
const std::function<void(QString)>& err) {
|
||||
if (conn == nullptr)
|
||||
return;
|
||||
@@ -145,7 +145,7 @@ void LiteInterface::fetchInfo(const std::function<void(json)>& cb,
|
||||
conn->doRPC("info", "", cb, err);
|
||||
}
|
||||
|
||||
void LiteInterface::fetchSupply(const std::function<void(json)>& cb) {
|
||||
void LiteInterface::fetchSupply(const std::function<void(QJsonValue)>& cb) {
|
||||
if (conn == nullptr)
|
||||
return;
|
||||
|
||||
@@ -153,7 +153,7 @@ void LiteInterface::fetchSupply(const std::function<void(json)>& cb) {
|
||||
}
|
||||
|
||||
|
||||
void LiteInterface::fetchLatestBlock(const std::function<void(json)>& cb,
|
||||
void LiteInterface::fetchLatestBlock(const std::function<void(QJsonValue)>& cb,
|
||||
const std::function<void(QString)>& err) {
|
||||
if (conn == nullptr)
|
||||
return;
|
||||
@@ -166,7 +166,7 @@ void LiteInterface::fetchLatestBlock(const std::function<void(json)>& cb,
|
||||
* combine the result, and call the callback with a single list containing both the t-addr and z-addr
|
||||
* private keys
|
||||
*/
|
||||
void LiteInterface::fetchAllPrivKeys(const std::function<void(json)> cb) {
|
||||
void LiteInterface::fetchAllPrivKeys(const std::function<void(QJsonValue)> cb) {
|
||||
if (conn == nullptr) {
|
||||
// No connection, just return
|
||||
return;
|
||||
|
||||
@@ -6,8 +6,6 @@
|
||||
#include "camount.h"
|
||||
#include "connection.h"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
// Since each transaction can contain multiple outputs, we separate them out individually
|
||||
// into a struct with address, amount, memo
|
||||
struct TransactionItemDetail {
|
||||
@@ -38,43 +36,43 @@ public:
|
||||
void setConnection(Connection* c);
|
||||
Connection* getConnection() { return conn; }
|
||||
|
||||
void fetchUnspent (const std::function<void(json)>& cb);
|
||||
void fetchTransactions (const std::function<void(json)>& cb);
|
||||
void fetchAddresses (const std::function<void(json)>& cb);
|
||||
void fetchUnspent (const std::function<void(QJsonValue)>& cb);
|
||||
void fetchTransactions (const std::function<void(QJsonValue)>& cb);
|
||||
void fetchAddresses (const std::function<void(QJsonValue)>& cb);
|
||||
|
||||
void fetchInfo(const std::function<void(json)>& cb,
|
||||
void fetchInfo(const std::function<void(QJsonValue)>& cb,
|
||||
const std::function<void(QString)>& err);
|
||||
|
||||
|
||||
|
||||
void fetchLatestBlock(const std::function<void(json)>& cb,
|
||||
void fetchLatestBlock(const std::function<void(QJsonValue)>& cb,
|
||||
const std::function<void(QString)>& err);
|
||||
|
||||
void fetchBalance(const std::function<void(json)>& cb);
|
||||
void fetchBalance(const std::function<void(QJsonValue)>& cb);
|
||||
|
||||
|
||||
void createNewZaddr(bool sapling, const std::function<void(json)>& cb);
|
||||
void createNewTaddr(const std::function<void(json)>& cb);
|
||||
void createNewSietchZaddr(const std::function<void(json)>& cb);
|
||||
void createNewZaddr(bool sapling, const std::function<void(QJsonValue)>& cb);
|
||||
void createNewTaddr(const std::function<void(QJsonValue)>& cb);
|
||||
void createNewSietchZaddr(const std::function<void(QJsonValue)>& cb);
|
||||
|
||||
void fetchPrivKey(QString addr, const std::function<void(json)>& cb);
|
||||
void fetchAllPrivKeys(const std::function<void(json)>);
|
||||
void fetchSeed(const std::function<void(json)>&);
|
||||
void fetchPrivKey(QString addr, const std::function<void(QJsonValue)>& cb);
|
||||
void fetchAllPrivKeys(const std::function<void(QJsonValue)>);
|
||||
void fetchSeed(const std::function<void(QJsonValue)>&);
|
||||
|
||||
void saveWallet(const std::function<void(json)>& cb);
|
||||
void clearWallet(const std::function<void(json)>& cb);
|
||||
void saveWallet(const std::function<void(QJsonValue)>& cb);
|
||||
void clearWallet(const std::function<void(QJsonValue)>& cb);
|
||||
|
||||
void fetchWalletEncryptionStatus(const std::function<void(json)>& cb);
|
||||
void fetchSupply(const std::function<void(json)>& cb);
|
||||
void encryptWallet(QString password, const std::function<void(json)>& cb);
|
||||
void unlockWallet(QString password, const std::function<void(json)>& cb);
|
||||
void removeWalletEncryption(QString password, const std::function<void(json)>& cb);
|
||||
void fetchWalletEncryptionStatus(const std::function<void(QJsonValue)>& cb);
|
||||
void fetchSupply(const std::function<void(QJsonValue)>& cb);
|
||||
void encryptWallet(QString password, const std::function<void(QJsonValue)>& cb);
|
||||
void unlockWallet(QString password, const std::function<void(QJsonValue)>& cb);
|
||||
void removeWalletEncryption(QString password, const std::function<void(QJsonValue)>& cb);
|
||||
|
||||
//void importZPrivKey(QString addr, bool rescan, const std::function<void(json)>& cb);
|
||||
//void importTPrivKey(QString addr, bool rescan, const std::function<void(json)>& cb);
|
||||
|
||||
|
||||
void sendTransaction(QString params, const std::function<void(json)>& cb, const std::function<void(QString)>& err);
|
||||
void sendTransaction(QString params, const std::function<void(QJsonValue)>& cb, const std::function<void(QString)>& err);
|
||||
|
||||
private:
|
||||
Connection* conn = nullptr;
|
||||
|
||||
@@ -35,9 +35,6 @@
|
||||
#include "firsttimewizard.h"
|
||||
#include "../lib/silentdragonlitelib.h"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
auto dirwallet = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)).filePath("silentdragonlite/silentdragonlite-wallet.dat");
|
||||
@@ -989,7 +986,7 @@ void MainWindow::exportSeed() {
|
||||
|
||||
|
||||
|
||||
rpc->fetchSeed([=](json reply) {
|
||||
rpc->fetchSeed([=](QJsonValue reply) {
|
||||
if (isJsonError(reply)) {
|
||||
return;
|
||||
}
|
||||
@@ -1007,7 +1004,7 @@ void MainWindow::exportSeed() {
|
||||
|
||||
pui.privKeyTxt->setReadOnly(true);
|
||||
pui.privKeyTxt->setLineWrapMode(QPlainTextEdit::LineWrapMode::NoWrap);
|
||||
pui.privKeyTxt->setPlainText(QString::fromStdString(reply.dump()));
|
||||
pui.privKeyTxt->setPlainText(QLatin1String(QJsonDocument(reply.toObject()).toJson(QJsonDocument::Compact)));
|
||||
|
||||
pui.helpLbl->setText(tr("This is your wallet seed. Please back it up carefully and safely."));
|
||||
|
||||
@@ -1061,14 +1058,14 @@ void MainWindow::exportKeys(QString addr) {
|
||||
|
||||
bool allKeys = addr.isEmpty() ? true : false;
|
||||
|
||||
auto fnUpdateUIWithKeys = [=](json reply) {
|
||||
auto fnUpdateUIWithKeys = [=](QJsonValue reply) {
|
||||
if (isJsonError(reply)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (reply.is_discarded() || !reply.is_array()) {
|
||||
if (reply.isNull() || !reply.isArray()) {
|
||||
QMessageBox::critical(this, tr("Error getting private keys"),
|
||||
tr("Error loading private keys: ") + QString::fromStdString(reply.dump()),
|
||||
tr("Error loading private keys: ") + QLatin1String(QJsonDocument(reply.toObject()).toJson(QJsonDocument::Compact)),
|
||||
QMessageBox::Ok);
|
||||
return;
|
||||
}
|
||||
@@ -1107,8 +1104,8 @@ void MainWindow::exportKeys(QString addr) {
|
||||
});
|
||||
|
||||
QString allKeysTxt;
|
||||
for (auto i : reply.get<json::array_t>()) {
|
||||
allKeysTxt = allKeysTxt % QString::fromStdString(i["private_key"]) % " # addr=" % QString::fromStdString(i["address"]) % "\n";
|
||||
for (auto i : reply.toArray()) {
|
||||
allKeysTxt = allKeysTxt % i.toObject()["private_key"].toString() % " # addr=" % i.toObject()["address"].toString() % "\n";
|
||||
}
|
||||
|
||||
pui.privKeyTxt->setPlainText(allKeysTxt);
|
||||
@@ -1565,8 +1562,8 @@ void MainWindow::updateContacts()
|
||||
}
|
||||
|
||||
void MainWindow::addNewZaddr(bool sapling) {
|
||||
rpc->createNewZaddr(sapling, [=] (json reply) {
|
||||
QString addr = QString::fromStdString(reply.get<json::array_t>()[0]);
|
||||
rpc->createNewZaddr(sapling, [=] (QJsonValue reply) {
|
||||
QString addr = reply.toArray()[0].toString();
|
||||
// Make sure the RPC class reloads the z-addrs for future use
|
||||
rpc->refreshAddresses();
|
||||
|
||||
@@ -1616,8 +1613,8 @@ std::function<void(bool)> MainWindow::addZAddrsToComboList(bool sapling) {
|
||||
|
||||
void MainWindow::setupReceiveTab() {
|
||||
auto addNewTAddr = [=] () {
|
||||
rpc->createNewTaddr([=] (json reply) {
|
||||
QString addr = QString::fromStdString(reply.get<json::array_t>()[0]);
|
||||
rpc->createNewTaddr([=] (QJsonValue reply) {
|
||||
QString addr = reply.toArray()[0].toString();
|
||||
// Make sure the RPC class reloads the t-addrs for future use
|
||||
rpc->refreshAddresses();
|
||||
|
||||
@@ -1992,8 +1989,8 @@ void MainWindow::on_givemeZaddr_clicked()
|
||||
{
|
||||
|
||||
bool sapling = true;
|
||||
rpc->createNewZaddr(sapling, [=] (json reply) {
|
||||
QString hushchataddr = QString::fromStdString(reply.get<json::array_t>()[0]);
|
||||
rpc->createNewZaddr(sapling, [=] (QJsonValue reply) {
|
||||
QString hushchataddr = reply.toArray()[0].toString();
|
||||
QClipboard *zaddr_Clipboard = QApplication::clipboard();
|
||||
zaddr_Clipboard ->setText(hushchataddr);
|
||||
QMessageBox::information(this, "Your new HushChat address was copied to your clipboard!",hushchataddr);
|
||||
|
||||
@@ -14,7 +14,6 @@ class WSServer;
|
||||
class WormholeClient;
|
||||
class ChatModel;
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
// Struct used to hold destination info when sending a Tx.
|
||||
struct ToFields {
|
||||
|
||||
@@ -71,8 +71,8 @@
|
||||
#include <QObject>
|
||||
#include <QApplication>
|
||||
#include <QDesktopWidget>
|
||||
#include <QPainterPath>
|
||||
|
||||
#include "3rdparty/json/json.hpp"
|
||||
#include "3rdparty/qrcode/QrCode.hpp"
|
||||
|
||||
#define SODIUM_STATIC
|
||||
|
||||
@@ -9,8 +9,6 @@
|
||||
#include "recurring.h"
|
||||
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
void MainWindow::setupSendTab() {
|
||||
// Create the validator for send to/amount fields
|
||||
amtValidator = new QRegExpValidator(QRegExp("[0-9]{0,8}\\.?[0-9]{0,8}"));
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
#include "precompiled.h"
|
||||
#include "camount.h"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
struct Config {
|
||||
QString server;
|
||||
};
|
||||
@@ -67,8 +65,6 @@ public:
|
||||
void set_currency_name(QString currency_name);
|
||||
|
||||
|
||||
|
||||
|
||||
bool isSaplingActive();
|
||||
|
||||
void setZECPrice(double p) { ZECPrice = p; }
|
||||
@@ -225,13 +221,12 @@ private:
|
||||
};
|
||||
|
||||
|
||||
inline bool isJsonResultSuccess(const json& res) {
|
||||
return res.find("result") != res.end() &&
|
||||
QString::fromStdString(res["result"].get<json::string_t>()) == "success";
|
||||
inline bool isJsonResultSuccess(const QJsonValue& res) {
|
||||
return res.toObject()["result"].toString() == "success";
|
||||
}
|
||||
|
||||
inline bool isJsonError(const json& res) {
|
||||
return res.find("error") != res.end();
|
||||
inline bool isJsonError(const QJsonValue& res) {
|
||||
return !res.toObject()["error"].isNull();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -735,9 +735,9 @@ void AppDataServer::processSendTx(QJsonObject sendTx, MainWindow* mainwindow, st
|
||||
return;
|
||||
}
|
||||
|
||||
json params = json::array();
|
||||
QJsonArray params;
|
||||
mainwindow->getRPC()->fillTxJsonParams(params, tx);
|
||||
std::cout << std::setw(2) << params << std::endl;
|
||||
//std::cout << std::setw(2) << params << std::endl;
|
||||
|
||||
// And send the Tx
|
||||
mainwindow->getRPC()->executeTransaction(tx,
|
||||
@@ -835,9 +835,9 @@ void AppDataServer::processSendManyTx(QJsonObject sendmanyTx, MainWindow* mainwi
|
||||
return;
|
||||
}
|
||||
|
||||
json params = json::array();
|
||||
QJsonArray params;
|
||||
mainwindow->getRPC()->fillTxJsonParams(params, tx);
|
||||
std::cout << std::setw(2) << params << std::endl;
|
||||
//std::cout << std::setw(2) << params << std::endl;
|
||||
|
||||
// And send the Tx
|
||||
mainwindow->getRPC()->executeTransaction(tx,
|
||||
|
||||
Reference in New Issue
Block a user