Browse Source

Refactor address lookups

Aditya Kulkarni 5 years ago
parent
commit
d8b43896de
  1. 4
      src/mainwindow.cpp
  2. 2
      src/rpc.cpp
  3. 8
      src/sendtab.cpp
  4. 2
      src/senttxstore.cpp

4
src/mainwindow.cpp

@ -1082,7 +1082,7 @@ void MainWindow::setupBalancesTab() {
fnDoSendFrom(addr); fnDoSendFrom(addr);
}); });
if (addr.startsWith("t")) { if (Settings::isTAddress(addr)) {
auto defaultSapling = rpc->getDefaultSaplingAddress(); auto defaultSapling = rpc->getDefaultSaplingAddress();
if (!defaultSapling.isEmpty()) { if (!defaultSapling.isEmpty()) {
menu.addAction(tr("Shield balance to Sapling"), [=] () { 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) { std::for_each(utxos->begin(), utxos->end(), [=](auto& utxo) {
auto addr = utxo.address; 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); auto bal = rpc->getAllBalances()->value(addr);
ui->listRecieveAddresses->addItem(addr, bal); ui->listRecieveAddresses->addItem(addr, bal);
} }

2
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 // Force it through string for rounding. Without this, decimal points beyond 8 places
// will appear, causing an "invalid amount" error // will appear, causing an "invalid amount" error
rec["amount"] = Settings::getDecimalString(toAddr.amount).toStdString(); //.toDouble(); 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(); rec["memo"] = toAddr.encodedMemo.toStdString();
allRecepients.push_back(rec); allRecepients.push_back(rec);

8
src/sendtab.cpp

@ -292,7 +292,7 @@ void MainWindow::addAddressSection() {
void MainWindow::addressChanged(int itemNumber, const QString& text) { void MainWindow::addressChanged(int itemNumber, const QString& text) {
auto addr = AddressBook::addressFromAddressLabel(text); auto addr = AddressBook::addressFromAddressLabel(text);
setMemoEnabled(itemNumber, addr.startsWith("z")); setMemoEnabled(itemNumber, Settings::isZAddress(addr));
} }
void MainWindow::amountChanged(int item, const QString& text) { 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) { void MainWindow::memoButtonClicked(int number, bool includeReplyTo) {
// Memos can only be used with zAddrs. So check that first // Memos can only be used with zAddrs. So check that first
auto addr = ui->sendToWidgets->findChild<QLineEdit*>(QString("Address") + QString::number(number)); auto addr = ui->sendToWidgets->findChild<QLineEdit*>(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"), 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"), 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); QMessageBox::Ok, this);
@ -500,7 +500,7 @@ Tx MainWindow::createTxFromSendPage() {
bool MainWindow::confirmTx(Tx tx) { bool MainWindow::confirmTx(Tx tx) {
auto fnSplitAddressForWrap = [=] (const QString& a) -> QString { auto fnSplitAddressForWrap = [=] (const QString& a) -> QString {
if (!a.startsWith("z")) return a; if (! Settings::isZAddress(a)) return a;
auto half = a.length() / 2; auto half = a.length() / 2;
auto splitted = a.left(half) + "\n" + a.right(a.length() - half); 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); confirm.gridLayout->addWidget(AmtUSD, row, 2, 1, 1);
// Memo // Memo
if (toAddr.addr.startsWith("z") && !toAddr.txtMemo.isEmpty()) { if (Settings::isZAddress(toAddr.addr) && !toAddr.txtMemo.isEmpty()) {
row++; row++;
auto Memo = new QLabel(confirm.sendToAddrs); auto Memo = new QLabel(confirm.sendToAddrs);
Memo->setObjectName(QStringLiteral("Memo") % QString::number(i + 1)); Memo->setObjectName(QStringLiteral("Memo") % QString::number(i + 1));

2
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 // Also, only store outgoing txs where the from address is a z-Addr. Else, regular zcashd
// stores it just fine // stores it just fine
if (!tx.fromAddr.startsWith("z")) if (! Settings::isZAddress(tx.fromAddr))
return; return;
QFile data(writeableFile()); QFile data(writeableFile());

Loading…
Cancel
Save