From 46ff75b109ea55efa2098907ac0d129106b4500b Mon Sep 17 00:00:00 2001 From: Aditya Kulkarni Date: Tue, 16 Oct 2018 13:21:24 -0700 Subject: [PATCH] Add support for testnet --- README.md | 2 ++ src/balancestablemodel.cpp | 6 +++++- src/main.cpp | 3 ++- src/rpc.cpp | 19 ++++++++----------- src/sendtab.cpp | 6 ++++-- src/settings.cpp | 3 +++ src/settings.h | 7 ++++++- 7 files changed, 30 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index a3063d0..386a4c3 100644 --- a/README.md +++ b/README.md @@ -51,3 +51,5 @@ ssh -L8232:127.0.0.1:8232 user@remotehost ### 2. "Not enough balance" when sending transactions The most likely cause for this is that you are trying to spend unconfirmed funds. Unlike bitcoin, the zcash protocol doesn't let you spent unconfirmed funds yet. Please wait for 1-2 blocks for the funds to confirm and retry the transaction. + +PS: zcash-qt-wallet is NOT an official wallet, and is not affiliated with the ZCash Company in any way. \ No newline at end of file diff --git a/src/balancestablemodel.cpp b/src/balancestablemodel.cpp index 246d028..0ebaad8 100644 --- a/src/balancestablemodel.cpp +++ b/src/balancestablemodel.cpp @@ -8,6 +8,7 @@ BalancesTableModel::BalancesTableModel(QObject *parent) void BalancesTableModel::setNewData(const QMap* balances, const QList* outputs) { + int currentRows = rowCount(QModelIndex()); // Copy over the utxos for our use delete utxos; utxos = new QList(); @@ -23,7 +24,10 @@ void BalancesTableModel::setNewData(const QMap* balances, // And then update the data dataChanged(index(0, 0), index(modeldata->size()-1, columnCount(index(0,0))-1)); - layoutChanged(); + + // Change the layout only if the number of rows changed + if (modeldata && modeldata->size() != currentRows) + layoutChanged(); } BalancesTableModel::~BalancesTableModel() { diff --git a/src/main.cpp b/src/main.cpp index 60c1b7b..c9b79c9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,4 +1,5 @@ #include "mainwindow.h" +#include "settings.h" #include "precompiled.h" int main(int argc, char *argv[]) @@ -21,7 +22,7 @@ int main(int argc, char *argv[]) MainWindow w; - + w.setWindowTitle("zcash-qt-wallet v" + QString(APP_VERSION)); w.show(); return QApplication::exec(); diff --git a/src/rpc.cpp b/src/rpc.cpp index 30b35e8..8245bc4 100644 --- a/src/rpc.cpp +++ b/src/rpc.cpp @@ -240,7 +240,8 @@ void RPC::handleConnectionError(const QString& error) { % "\n\nThis is most likely an internal error. Are you using zcashd v2.0 or higher? You might " % "need to file a bug report here: https://github.com/adityapk00/zcash-qt-wallet/issues"; } else if (error.contains("internal server error", Qt::CaseInsensitive) || - error.contains("rewinding")) { + error.contains("rewinding", Qt::CaseInsensitive) || + error.contains("loading", Qt::CaseInsensitive)) { explanation = QString() % "\n\nIf you just started zcashd, then it's still loading and you might have to wait a while. If zcashd is ready, then you've run into " % "something unexpected, and might need to file a bug report here: https://github.com/adityapk00/zcash-qt-wallet/issues"; @@ -312,9 +313,7 @@ void RPC::refreshAddresses() { }); } -void RPC::refreshBalances() { - ui->unconfirmedWarning->setVisible(false); - +void RPC::refreshBalances() { // 1. Get the Balances getBalance([=] (json reply) { ui->balSheilded ->setText(QString::fromStdString(reply["private"]) % " ZEC"); @@ -331,11 +330,12 @@ void RPC::refreshBalances() { // Function to process reply of the listunspent and z_listunspent API calls, used below. auto processUnspent = [=] (const json& reply) { + bool anyUnconfirmed = false; for (auto& it : reply.get()) { QString qsAddr = QString::fromStdString(it["address"]); auto confirmations = it["confirmations"].get(); if (confirmations == 0) { - ui->unconfirmedWarning->setVisible(true); + anyUnconfirmed = true; } utxos->push_back( @@ -348,6 +348,7 @@ void RPC::refreshBalances() { ); (*allBalances)[qsAddr] = (*allBalances)[qsAddr] + it["amount"].get(); + ui->unconfirmedWarning->setVisible(anyUnconfirmed); } }; @@ -406,7 +407,6 @@ void RPC::refreshTransactions() { void RPC::refreshTxStatus(const QString& newOpid) { if (!newOpid.isEmpty()) { - qDebug() << QString::fromStdString("Adding opid ") % newOpid; watchingOps.insert(newOpid); } @@ -418,8 +418,6 @@ void RPC::refreshTxStatus(const QString& newOpid) { }; doRPC(payload, [=] (const json& reply) { - int numExecuting = 0; - // There's an array for each item in the status for (auto& it : reply.get()) { // If we were watching this Tx and it's status became "success", then we'll show a status bar alert @@ -457,17 +455,16 @@ void RPC::refreshTxStatus(const QString& newOpid) { } else if (status == "executing") { // If the operation is executing, then watch every second. txTimer->start(1 * 1000); - numExecuting++; } } } // If there is some op that we are watching, then show the loading bar, otherwise hide it - if (numExecuting == 0) { + if (watchingOps.size() == 0) { main->loadingLabel->setVisible(false); } else { main->loadingLabel->setVisible(true); - main->loadingLabel->setToolTip(QString::number(numExecuting) + " tx computing. This can take several minutes."); + main->loadingLabel->setToolTip(QString::number(watchingOps.size()) + " tx computing. This can take several minutes."); } }); } diff --git a/src/sendtab.cpp b/src/sendtab.cpp index 8027b4d..25708db 100644 --- a/src/sendtab.cpp +++ b/src/sendtab.cpp @@ -278,13 +278,15 @@ void MainWindow::sendButton() { QString MainWindow::doSendTxValidations(QString fromAddr, QList> toAddrs) { // 1. Addresses are valid format. - QRegExp zcexp("^zc[a-z0-9]{93}$", Qt::CaseInsensitive); - QRegExp zsexp("^zc[a-z0-9]{76}$", Qt::CaseInsensitive); + QRegExp zcexp("^z[a-z0-9]{94}$", Qt::CaseInsensitive); + QRegExp zsexp("^z[a-z0-9]{77}$", Qt::CaseInsensitive); + QRegExp ztsexp("^ztestsapling[a-z0-9]{76}", Qt::CaseInsensitive); QRegExp texp("^t[a-z0-9]{34}$", Qt::CaseInsensitive); auto matchesAnyAddr = [&] (QString addr) { return zcexp.exactMatch(addr) || texp.exactMatch(addr) || + ztsexp.exactMatch(addr) || zsexp.exactMatch(addr); }; diff --git a/src/settings.cpp b/src/settings.cpp index b625518..97ee2ae 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -13,6 +13,9 @@ QString Settings::getHost() { } QString Settings::getPort() { + // If the override port is set, we'll always return it + if (!overridePort.isEmpty()) return overridePort; + if (port.isNull() || port == "") return "8232"; return port; } diff --git a/src/settings.h b/src/settings.h index e75fdec..6581fed 100644 --- a/src/settings.h +++ b/src/settings.h @@ -1,6 +1,7 @@ #ifndef SETTINGS_H #define SETTINGS_H +#include "precompiled.h" class Settings { @@ -11,6 +12,8 @@ public: QString getHost(); QString getPort(); + void setDefaultPort(int port) {overridePort = QString::number(port);} + double fees() { return 0.0001; } void refresh(); private: @@ -18,7 +21,9 @@ private: QString host; QString port; QString username; - QString password; + QString password; + + QString overridePort; }; #endif // SETTINGS_H \ No newline at end of file