diff --git a/lib/Cargo.lock b/lib/Cargo.lock index 55a869b..2a9ad8f 100644 --- a/lib/Cargo.lock +++ b/lib/Cargo.lock @@ -1051,7 +1051,7 @@ version = "0.1.0" dependencies = [ "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", - "zecwalletlitelib 0.1.0 (git+https://github.com/adityapk00/zecwallet-light-cli?rev=af0e0b9b2bcc131804d5e940f94d45c6fef74481)", + "zecwalletlitelib 0.1.0 (git+https://github.com/adityapk00/zecwallet-light-cli?rev=61dc063fe155d1510e9a074e5a3577a0621f8c3a)", ] [[package]] @@ -2266,7 +2266,7 @@ dependencies = [ [[package]] name = "zecwalletlitelib" version = "0.1.0" -source = "git+https://github.com/adityapk00/zecwallet-light-cli?rev=af0e0b9b2bcc131804d5e940f94d45c6fef74481#af0e0b9b2bcc131804d5e940f94d45c6fef74481" +source = "git+https://github.com/adityapk00/zecwallet-light-cli?rev=61dc063fe155d1510e9a074e5a3577a0621f8c3a#61dc063fe155d1510e9a074e5a3577a0621f8c3a" dependencies = [ "base58 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "bellman 0.1.0 (git+https://github.com/adityapk00/librustzcash.git?rev=188537ea025fcb7fbdfc11266f307a084a5451e4)", @@ -2562,4 +2562,4 @@ dependencies = [ "checksum zcash_client_backend 0.0.0 (git+https://github.com/adityapk00/librustzcash.git?rev=188537ea025fcb7fbdfc11266f307a084a5451e4)" = "" "checksum zcash_primitives 0.0.0 (git+https://github.com/adityapk00/librustzcash.git?rev=188537ea025fcb7fbdfc11266f307a084a5451e4)" = "" "checksum zcash_proofs 0.0.0 (git+https://github.com/adityapk00/librustzcash.git?rev=188537ea025fcb7fbdfc11266f307a084a5451e4)" = "" -"checksum zecwalletlitelib 0.1.0 (git+https://github.com/adityapk00/zecwallet-light-cli?rev=af0e0b9b2bcc131804d5e940f94d45c6fef74481)" = "" +"checksum zecwalletlitelib 0.1.0 (git+https://github.com/adityapk00/zecwallet-light-cli?rev=61dc063fe155d1510e9a074e5a3577a0621f8c3a)" = "" diff --git a/lib/Cargo.toml b/lib/Cargo.toml index bec009e..a2f32a9 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -11,4 +11,4 @@ crate-type = ["staticlib"] [dependencies] libc = "0.2.58" lazy_static = "1.4.0" -zecwalletlitelib = { git = "https://github.com/adityapk00/zecwallet-light-cli", rev = "af0e0b9b2bcc131804d5e940f94d45c6fef74481" } +zecwalletlitelib = { git = "https://github.com/adityapk00/zecwallet-light-cli", rev = "61dc063fe155d1510e9a074e5a3577a0621f8c3a" } diff --git a/src/connection.cpp b/src/connection.cpp index a2a882d..41ea1d6 100644 --- a/src/connection.cpp +++ b/src/connection.cpp @@ -49,7 +49,7 @@ void ConnectionLoader::doAutoConnect() { main->logger->write(QObject::tr("Attempting to initialize library with ") + config->server); // Check to see if there's an existing wallet - if (litelib_wallet_exists(Settings::getChainName().toStdString().c_str())) { + if (litelib_wallet_exists(Settings::getDefaultChainName().toStdString().c_str())) { main->logger->write(QObject::tr("Using existing wallet.")); char* resp = litelib_initialize_existing(config->dangerous, config->server.toStdString().c_str()); QString response = litelib_process_response(resp); @@ -68,9 +68,10 @@ void ConnectionLoader::doAutoConnect() { auto me = this; // After the lib is initialized, try to do get info - connection->doRPC("info", "", [=](auto) { + connection->doRPC("info", "", [=](auto reply) { // If success, set the connection main->logger->write("Connection is online."); + connection->setInfo(reply); isSyncing = new QAtomicInteger(); isSyncing->store(true); diff --git a/src/connection.h b/src/connection.h index 7ea28b1..636dd73 100644 --- a/src/connection.h +++ b/src/connection.h @@ -123,8 +123,12 @@ public: void showTxError(const QString& error); + json getInfo() { return serverInfo; } + void setInfo(const json& info) { serverInfo = info; } + private: - bool shutdownInProgress = false; + bool shutdownInProgress = false; + json serverInfo; }; #endif diff --git a/src/controller.cpp b/src/controller.cpp index d482f38..8459236 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -67,6 +67,8 @@ void Controller::setConnection(Connection* c) { ui->statusBar->showMessage("Ready!"); + processInfo(c->getInfo()); + // If we're allowed to get the Zec Price, get the prices if (Settings::getInstance()->getAllowFetchPrices()) refreshZECPrice(); @@ -137,42 +139,46 @@ void Controller::refresh(bool force) { getInfoThenRefresh(force); } +void Controller::processInfo(const json& info) { + // Testnet? + QString chainName; + if (!info["chain_name"].is_null()) { + chainName = QString::fromStdString(info["chain_name"].get()); + Settings::getInstance()->setTestnet(chainName == "test"); + }; + + + QString version = QString::fromStdString(info["version"].get()); + Settings::getInstance()->setZcashdVersion(version); + + // Recurring pamynets are testnet only + if (!Settings::getInstance()->isTestnet()) + main->disableRecurring(); +} + void Controller::getInfoThenRefresh(bool force) { if (!zrpc->haveConnection()) return noConnection(); static bool prevCallSucceeded = false; - zrpc->fetchInfo([=] (const json& reply) { - prevCallSucceeded = true; - - // Testnet? - QString chainName; - if (!reply["chain_name"].is_null()) { - chainName = QString::fromStdString(reply["chain_name"].get()); - Settings::getInstance()->setTestnet(chainName == "test"); - }; + zrpc->fetchLatestBlock([=] (const json& reply) { + prevCallSucceeded = true; - // Recurring pamynets are testnet only - if (!Settings::getInstance()->isTestnet()) - main->disableRecurring(); - - int curBlock = reply["latest_block_height"].get(); + int curBlock = reply["height"].get(); bool doUpdate = force || (model->getLatestBlock() != curBlock); model->setLatestBlock(curBlock); // Connected, so display checkmark. - auto tooltip = Settings::getInstance()->getSettings().server + "\n" + QString::fromStdString(reply.dump()); + auto tooltip = Settings::getInstance()->getSettings().server + "\n" + + QString::fromStdString(zrpc->getConnection()->getInfo().dump()); QIcon i(":/icons/res/connected.gif"); + QString chainName = Settings::getInstance()->isTestnet() ? "test" : "main"; main->statusLabel->setText(chainName + "(" + QString::number(curBlock) + ")"); main->statusLabel->setToolTip(tooltip); main->statusIcon->setPixmap(i.pixmap(16, 16)); main->statusIcon->setToolTip(tooltip); - //int version = reply["version"].get(); - int version = 1; - Settings::getInstance()->setZcashdVersion(version); - // See if recurring payments needs anything Recurring::getInstance()->processPending(main); diff --git a/src/controller.h b/src/controller.h index 1394fad..981730d 100644 --- a/src/controller.h +++ b/src/controller.h @@ -107,6 +107,7 @@ public: QString getDefaultTAddress(); private: + void processInfo(const json&); void refreshBalances(); void refreshTransactions(); diff --git a/src/liteinterface.cpp b/src/liteinterface.cpp index 30f1a0b..0f4bfe9 100644 --- a/src/liteinterface.cpp +++ b/src/liteinterface.cpp @@ -130,6 +130,15 @@ void LiteInterface::fetchInfo(const std::function& cb, conn->doRPC("info", "", cb, err); } + +void LiteInterface::fetchLatestBlock(const std::function& cb, + const std::function& err) { + if (conn == nullptr) + return; + + conn->doRPC("height", "", cb, err); +} + /** * Method to get all the private keys for both z and t addresses. It will make 2 batch calls, * combine the result, and call the callback with a single list containing both the t-addr and z-addr diff --git a/src/liteinterface.h b/src/liteinterface.h index 203967f..70b5732 100644 --- a/src/liteinterface.h +++ b/src/liteinterface.h @@ -44,6 +44,9 @@ public: void fetchInfo(const std::function& cb, const std::function& err); + + void fetchLatestBlock(const std::function& cb, + const std::function& err); void fetchBalance(const std::function& cb); diff --git a/src/settings.cpp b/src/settings.cpp index a96b7af..ed1891f 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -74,11 +74,11 @@ bool Settings::isTAddress(QString addr) { return addr.startsWith("t"); } -int Settings::getZcashdVersion() { +QString Settings::getZcashdVersion() { return _zcashdVersion; } -void Settings::setZcashdVersion(int version) { +void Settings::setZcashdVersion(QString version) { _zcashdVersion = version; } diff --git a/src/settings.h b/src/settings.h index d2cbfbf..a031d89 100644 --- a/src/settings.h +++ b/src/settings.h @@ -42,8 +42,8 @@ public: bool isSyncing(); void setSyncing(bool syncing); - int getZcashdVersion(); - void setZcashdVersion(int version); + QString getZcashdVersion(); + void setZcashdVersion(QString version); void setUseEmbedded(bool r) { _useEmbedded = r; } bool useEmbedded() { return _useEmbedded; } @@ -95,12 +95,11 @@ public: static bool isValidAddress(QString addr); - static QString getChainName() { return QString("main"); } + static QString getDefaultChainName() { return QString("main"); } static const QString labelRegExp; - static const int updateSpeed = 20 * 1000; // 20 sec - static const int quickUpdateSpeed = 5 * 1000; // 5 sec + static const int updateSpeed = 60 * 1000; // 60 sec static const int priceRefreshSpeed = 60 * 60 * 1000; // 1 hr private: @@ -114,7 +113,7 @@ private: bool _isTestnet = false; bool _isSyncing = false; int _blockNumber = 0; - int _zcashdVersion = 0; + QString _zcashdVersion = 0; bool _useEmbedded = false; bool _headless = false; diff --git a/src/txtablemodel.cpp b/src/txtablemodel.cpp index 9df59e4..07815dc 100644 --- a/src/txtablemodel.cpp +++ b/src/txtablemodel.cpp @@ -70,15 +70,18 @@ bool TxTableModel::exportToCsv(QString fileName) const { } QString TxTableModel::concatMultipleMemos(const TransactionItem& dat) const { - // Concat all the memos - QString memo; - for (auto item : dat.items) { - if (!item.memo.trimmed().isEmpty()) { - memo += item.address + ": \"" + item.memo + "\"\n"; + if (dat.items.length() == 1) { + return dat.items[0].memo; + } else { + // Concat all the memos + QString memo; + for (auto item : dat.items) { + if (!item.memo.trimmed().isEmpty()) { + memo += item.address + ": \"" + item.memo + "\"\n"; + } } + return memo; } - - return memo; }; QVariant TxTableModel::data(const QModelIndex &index, int role) const {