From d8b43896de53ef5d3fdff5331b1d824098f01bb2 Mon Sep 17 00:00:00 2001 From: Aditya Kulkarni Date: Tue, 7 May 2019 11:33:00 -0700 Subject: [PATCH] Refactor address lookups --- src/mainwindow.cpp | 4 ++-- src/rpc.cpp | 2 +- src/sendtab.cpp | 8 ++++---- src/senttxstore.cpp | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 54acf14..52c57ce 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1082,7 +1082,7 @@ void MainWindow::setupBalancesTab() { fnDoSendFrom(addr); }); - if (addr.startsWith("t")) { + if (Settings::isTAddress(addr)) { auto defaultSapling = rpc->getDefaultSaplingAddress(); if (!defaultSapling.isEmpty()) { menu.addAction(tr("Shield balance to Sapling"), [=] () { @@ -1402,7 +1402,7 @@ void MainWindow::updateTAddrCombo(bool checked) { std::for_each(utxos->begin(), utxos->end(), [=](auto& utxo) { auto addr = utxo.address; - if (addr.startsWith("t") && ui->listRecieveAddresses->findText(addr) < 0) { + if (Settings::isTAddress(addr) && ui->listRecieveAddresses->findText(addr) < 0) { auto bal = rpc->getAllBalances()->value(addr); ui->listRecieveAddresses->addItem(addr, bal); } diff --git a/src/rpc.cpp b/src/rpc.cpp index 1a4fb33..5c0d85c 100644 --- a/src/rpc.cpp +++ b/src/rpc.cpp @@ -355,7 +355,7 @@ void RPC::fillTxJsonParams(json& params, Tx tx) { // Force it through string for rounding. Without this, decimal points beyond 8 places // will appear, causing an "invalid amount" error rec["amount"] = Settings::getDecimalString(toAddr.amount).toStdString(); //.toDouble(); - if (toAddr.addr.startsWith("z") && !toAddr.encodedMemo.trimmed().isEmpty()) + if (Settings::isZAddress(toAddr.addr) && !toAddr.encodedMemo.trimmed().isEmpty()) rec["memo"] = toAddr.encodedMemo.toStdString(); allRecepients.push_back(rec); diff --git a/src/sendtab.cpp b/src/sendtab.cpp index 13f7613..fb005df 100644 --- a/src/sendtab.cpp +++ b/src/sendtab.cpp @@ -292,7 +292,7 @@ void MainWindow::addAddressSection() { void MainWindow::addressChanged(int itemNumber, const QString& text) { auto addr = AddressBook::addressFromAddressLabel(text); - setMemoEnabled(itemNumber, addr.startsWith("z")); + setMemoEnabled(itemNumber, Settings::isZAddress(addr)); } void MainWindow::amountChanged(int item, const QString& text) { @@ -314,7 +314,7 @@ void MainWindow::setMemoEnabled(int number, bool enabled) { void MainWindow::memoButtonClicked(int number, bool includeReplyTo) { // Memos can only be used with zAddrs. So check that first auto addr = ui->sendToWidgets->findChild(QString("Address") + QString::number(number)); - if (!AddressBook::addressFromAddressLabel(addr->text()).startsWith("z")) { + if (! Settings::isZAddress(AddressBook::addressFromAddressLabel(addr->text()))) { QMessageBox msg(QMessageBox::Critical, tr("Memos can only be used with z-addresses"), tr("The memo field can only be used with a z-address.\n") + addr->text() + tr("\ndoesn't look like a z-address"), QMessageBox::Ok, this); @@ -500,7 +500,7 @@ Tx MainWindow::createTxFromSendPage() { bool MainWindow::confirmTx(Tx tx) { auto fnSplitAddressForWrap = [=] (const QString& a) -> QString { - if (!a.startsWith("z")) return a; + if (! Settings::isZAddress(a)) return a; auto half = a.length() / 2; auto splitted = a.left(half) + "\n" + a.right(a.length() - half); @@ -566,7 +566,7 @@ bool MainWindow::confirmTx(Tx tx) { confirm.gridLayout->addWidget(AmtUSD, row, 2, 1, 1); // Memo - if (toAddr.addr.startsWith("z") && !toAddr.txtMemo.isEmpty()) { + if (Settings::isZAddress(toAddr.addr) && !toAddr.txtMemo.isEmpty()) { row++; auto Memo = new QLabel(confirm.sendToAddrs); Memo->setObjectName(QStringLiteral("Memo") % QString::number(i + 1)); diff --git a/src/senttxstore.cpp b/src/senttxstore.cpp index 3fc66ac..5341664 100644 --- a/src/senttxstore.cpp +++ b/src/senttxstore.cpp @@ -57,7 +57,7 @@ void SentTxStore::addToSentTx(Tx tx, QString txid) { // Also, only store outgoing txs where the from address is a z-Addr. Else, regular zcashd // stores it just fine - if (!tx.fromAddr.startsWith("z")) + if (! Settings::isZAddress(tx.fromAddr)) return; QFile data(writeableFile());