From 683718008c930a1226bce393bdf0350726dde2c5 Mon Sep 17 00:00:00 2001 From: lucretius Date: Mon, 22 Jan 2024 14:11:02 +0100 Subject: [PATCH 1/3] use note automation only for chat related txs --- src/chatmodel.cpp | 4 ++-- src/controller.cpp | 11 ++++++----- src/controller.h | 4 ++-- src/mainwindow.cpp | 4 ++-- src/recurring.cpp | 2 +- src/sendtab.cpp | 2 +- 6 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/chatmodel.cpp b/src/chatmodel.cpp index 5f4a601..f84b8de 100644 --- a/src/chatmodel.cpp +++ b/src/chatmodel.cpp @@ -596,7 +596,7 @@ void MainWindow::sendChat() { ui->memoTxtChat->clear(); // And send the Tx - rpc->executeTransaction(tx, + rpc->executeTransaction(tx, true, [=] (QString txid) { ui->statusBar->showMessage(Settings::txidStatusMessage + " " + txid); @@ -887,7 +887,7 @@ void MainWindow::ContactRequest() { ui->memoTxtChat->clear(); // And send the Tx - rpc->executeTransaction(tx, + rpc->executeTransaction(tx, true, [=] (QString txid) { ui->statusBar->showMessage(Settings::txidStatusMessage + " " + txid); diff --git a/src/controller.cpp b/src/controller.cpp index 89fc73f..f419485 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -132,7 +132,7 @@ void Controller::setConnection(Connection* c) } // Build the RPC JSON Parameters for this tx -void Controller::fillTxJsonParams(json& allRecepients, Tx tx) +void Controller::fillTxJsonParams(json& allRecepients, Tx tx, bool isChatMessage) { Q_ASSERT(allRecepients.is_array()); @@ -194,7 +194,8 @@ void Controller::fillTxJsonParams(json& allRecepients, Tx tx) if (spendableNotesCount < 30 && balanceAvailable.toDecimalString().toDouble() > (dustTransactions.size() * 0.0001) && - isNoteAutomationEnabled) { + isNoteAutomationEnabled && + isChatMessage) { // Create extra transaction for (size_t i = 0; i < dustTransactions.size(); ++i) { // Generate random memo @@ -1506,7 +1507,7 @@ void Controller::unlockIfEncrypted(std::function cb, std::functionstatusBar->showMessage(Settings::txidStatusMessage + " " + txid); }, [=] (QString opid, QString errStr) { @@ -1528,7 +1529,7 @@ void Controller::executeStandardUITransaction(Tx tx) } // Execute a transaction! -void Controller::executeTransaction(Tx tx, +void Controller::executeTransaction(Tx tx, bool isChatMessage, const std::function submitted, const std::function error) { @@ -1538,7 +1539,7 @@ void Controller::executeTransaction(Tx tx, unlockIfEncrypted([=] () { // First, create the json params json params = json::array(); - fillTxJsonParams(params, tx); + fillTxJsonParams(params, tx, isChatMessage); std::cout << std::setw(2) << params << std::endl; zrpc->sendTransaction(QString::fromStdString(params.dump()), [=](const json& reply) { diff --git a/src/controller.h b/src/controller.h index debc699..d9b98f2 100644 --- a/src/controller.h +++ b/src/controller.h @@ -86,11 +86,11 @@ public: void executeStandardUITransaction(Tx tx); - void executeTransaction(Tx tx, + void executeTransaction(Tx tx, bool isChatMessage, const std::function submitted, const std::function error); - void fillTxJsonParams(json& params, Tx tx); + void fillTxJsonParams(json& params, Tx tx, bool isChatMessage); const TxTableModel* getTransactionsModel() { return transactionsTableModel; } diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 231dad7..38813bb 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -2032,7 +2032,7 @@ void MainWindow::sendMoneyChat() { ui->memoTxtChat->clear(); // And send the Tx - rpc->executeTransaction(tx, + rpc->executeTransaction(tx, true, [=] (QString txid) { ui->statusBar->showMessage(Settings::txidStatusMessage + " " + txid); @@ -2320,7 +2320,7 @@ void MainWindow::sendMoneyRequestChat() { ui->memoTxtChat->clear(); // And send the Tx - rpc->executeTransaction(tx, + rpc->executeTransaction(tx, true, [=] (QString txid) { ui->statusBar->showMessage(Settings::txidStatusMessage + " " + txid); diff --git a/src/recurring.cpp b/src/recurring.cpp index 88dcfe7..1089499 100644 --- a/src/recurring.cpp +++ b/src/recurring.cpp @@ -600,7 +600,7 @@ void Recurring::executeRecurringPayment(MainWindow* main, RecurringPaymentInfo r * Execute a send Tx */ void Recurring::doSendTx(MainWindow* mainwindow, Tx tx, std::function cb) { - mainwindow->getRPC()->executeTransaction(tx, + mainwindow->getRPC()->executeTransaction(tx, false, [=] (QString txid) { mainwindow->ui->statusBar->showMessage(Settings::txidStatusMessage + " " + txid); cb(txid, ""); diff --git a/src/sendtab.cpp b/src/sendtab.cpp index d32a987..2bd4fab 100644 --- a/src/sendtab.cpp +++ b/src/sendtab.cpp @@ -864,7 +864,7 @@ void MainWindow::sendButton() { d->show(); // And send the Tx - rpc->executeTransaction(tx, + rpc->executeTransaction(tx, false, [=] (QString txid) { ui->statusBar->showMessage(Settings::txidStatusMessage + " " + txid); From 4f0229a82354d8297b42ba05610897245d6f0b61 Mon Sep 17 00:00:00 2001 From: lucretius Date: Wed, 24 Jan 2024 13:27:42 +0100 Subject: [PATCH 2/3] fix for isOnline in getSettings() --- src/settings.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/settings.cpp b/src/settings.cpp index ec5c550..a8c0f31 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -40,7 +40,7 @@ Config Settings::getSettings() { bool isOnline = false; // make sure existing server in conf is alive, otherwise choose random one try { - bool isOnline = litelib_check_server_online(server.toStdString().c_str()); + isOnline = litelib_check_server_online(server.toStdString().c_str()); } catch (const std::exception& e) { qDebug() << __func__ << ": caught an exception, ignoring: " << e.what(); } From 49d587cd4290594d836c3cb8d3af1574ad1b47f7 Mon Sep 17 00:00:00 2001 From: lucretius Date: Wed, 24 Jan 2024 13:42:19 +0100 Subject: [PATCH 3/3] Add custom fee to gui --- lib/Cargo.lock | 18 +++++++-------- lib/Cargo.toml | 2 +- src/controller.cpp | 1 + src/mainwindow.h | 1 + src/mainwindow.ui | 55 ++++++++++++++++++++++++++-------------------- src/sendtab.cpp | 47 ++++++++++++++++++++++++++++++++------- 6 files changed, 82 insertions(+), 42 deletions(-) diff --git a/lib/Cargo.lock b/lib/Cargo.lock index b74002a..08604e5 100644 --- a/lib/Cargo.lock +++ b/lib/Cargo.lock @@ -172,7 +172,7 @@ checksum = "cdcf67bb7ba7797a081cd19009948ab533af7c355d5caf1d08c777582d351e9c" [[package]] name = "bellman" version = "0.1.0" -source = "git+https://git.hush.is/hush/librustzcash.git?rev=1a0204113d487cdaaf183c2967010e5214ff9e37#1a0204113d487cdaaf183c2967010e5214ff9e37" +source = "git+https://git.hush.is/hush/librustzcash.git?rev=acff1444ec373e9c3e37b47ca95bfd358e45255b#acff1444ec373e9c3e37b47ca95bfd358e45255b" dependencies = [ "bit-vec", "blake2s_simd", @@ -497,7 +497,7 @@ checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" [[package]] name = "ff" version = "0.4.0" -source = "git+https://git.hush.is/hush/librustzcash.git?rev=1a0204113d487cdaaf183c2967010e5214ff9e37#1a0204113d487cdaaf183c2967010e5214ff9e37" +source = "git+https://git.hush.is/hush/librustzcash.git?rev=acff1444ec373e9c3e37b47ca95bfd358e45255b#acff1444ec373e9c3e37b47ca95bfd358e45255b" dependencies = [ "byteorder", "ff_derive", @@ -507,7 +507,7 @@ dependencies = [ [[package]] name = "ff_derive" version = "0.3.0" -source = "git+https://git.hush.is/hush/librustzcash.git?rev=1a0204113d487cdaaf183c2967010e5214ff9e37#1a0204113d487cdaaf183c2967010e5214ff9e37" +source = "git+https://git.hush.is/hush/librustzcash.git?rev=acff1444ec373e9c3e37b47ca95bfd358e45255b#acff1444ec373e9c3e37b47ca95bfd358e45255b" dependencies = [ "num-bigint", "num-integer", @@ -665,7 +665,7 @@ dependencies = [ [[package]] name = "group" version = "0.1.0" -source = "git+https://git.hush.is/hush/librustzcash.git?rev=1a0204113d487cdaaf183c2967010e5214ff9e37#1a0204113d487cdaaf183c2967010e5214ff9e37" +source = "git+https://git.hush.is/hush/librustzcash.git?rev=acff1444ec373e9c3e37b47ca95bfd358e45255b#acff1444ec373e9c3e37b47ca95bfd358e45255b" dependencies = [ "ff", "rand 0.7.3", @@ -1132,7 +1132,7 @@ dependencies = [ [[package]] name = "pairing" version = "0.14.2" -source = "git+https://git.hush.is/hush/librustzcash.git?rev=1a0204113d487cdaaf183c2967010e5214ff9e37#1a0204113d487cdaaf183c2967010e5214ff9e37" +source = "git+https://git.hush.is/hush/librustzcash.git?rev=acff1444ec373e9c3e37b47ca95bfd358e45255b#acff1444ec373e9c3e37b47ca95bfd358e45255b" dependencies = [ "byteorder", "ff", @@ -1849,7 +1849,7 @@ dependencies = [ [[package]] name = "silentdragonlitelib" version = "0.1.0" -source = "git+https://git.hush.is/hush/silentdragonlite-cli?rev=1334c89e0f4ddd23725020e16753d0ea95c09bf5#1334c89e0f4ddd23725020e16753d0ea95c09bf5" +source = "git+https://git.hush.is/hush/silentdragonlite-cli?rev=8fc0dc539a3b29655f0538c671b42feee5205641#8fc0dc539a3b29655f0538c671b42feee5205641" dependencies = [ "base58", "bellman", @@ -2695,7 +2695,7 @@ dependencies = [ [[package]] name = "zcash_client_backend" version = "0.0.0" -source = "git+https://git.hush.is/hush/librustzcash.git?rev=1a0204113d487cdaaf183c2967010e5214ff9e37#1a0204113d487cdaaf183c2967010e5214ff9e37" +source = "git+https://git.hush.is/hush/librustzcash.git?rev=acff1444ec373e9c3e37b47ca95bfd358e45255b#acff1444ec373e9c3e37b47ca95bfd358e45255b" dependencies = [ "bech32", "bs58", @@ -2711,7 +2711,7 @@ dependencies = [ [[package]] name = "zcash_primitives" version = "0.0.0" -source = "git+https://git.hush.is/hush/librustzcash.git?rev=1a0204113d487cdaaf183c2967010e5214ff9e37#1a0204113d487cdaaf183c2967010e5214ff9e37" +source = "git+https://git.hush.is/hush/librustzcash.git?rev=acff1444ec373e9c3e37b47ca95bfd358e45255b#acff1444ec373e9c3e37b47ca95bfd358e45255b" dependencies = [ "aes", "blake2b_simd", @@ -2734,7 +2734,7 @@ dependencies = [ [[package]] name = "zcash_proofs" version = "0.0.0" -source = "git+https://git.hush.is/hush/librustzcash.git?rev=1a0204113d487cdaaf183c2967010e5214ff9e37#1a0204113d487cdaaf183c2967010e5214ff9e37" +source = "git+https://git.hush.is/hush/librustzcash.git?rev=acff1444ec373e9c3e37b47ca95bfd358e45255b#acff1444ec373e9c3e37b47ca95bfd358e45255b" dependencies = [ "bellman", "blake2b_simd", diff --git a/lib/Cargo.toml b/lib/Cargo.toml index c25ef8d..c2e044a 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -12,4 +12,4 @@ crate-type = ["staticlib"] libc = "0.2.58" lazy_static = "1.4.0" blake3 = "0.3.4" -silentdragonlitelib = { git = "https://git.hush.is/hush/silentdragonlite-cli", rev = "1334c89e0f4ddd23725020e16753d0ea95c09bf5" } +silentdragonlitelib = { git = "https://git.hush.is/hush/silentdragonlite-cli", rev = "8fc0dc539a3b29655f0538c671b42feee5205641" } diff --git a/src/controller.cpp b/src/controller.cpp index f419485..543a67c 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -221,6 +221,7 @@ void Controller::fillTxJsonParams(json& allRecepients, Tx tx, bool isChatMessage json rec = json::object(); rec["address"] = toAddr.addr.toStdString(); rec["amount"] = toAddr.amount.toqint64(); + rec["fee"] = tx.fee.toqint64(); if (Settings::isZAddress(toAddr.addr) && !toAddr.memo.trimmed().isEmpty()) rec["memo"] = toAddr.memo.toStdString(); diff --git a/src/mainwindow.h b/src/mainwindow.h index 31ab6e1..9ed7558 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -161,6 +161,7 @@ private: void addAddressSection(); void maxAmountChecked(int checked); + void toggleMinerFeeEditable(int state); void editSchedule(); diff --git a/src/mainwindow.ui b/src/mainwindow.ui index db12534..4a204dc 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -59,7 +59,7 @@ - 5 + 2 @@ -93,6 +93,7 @@ + 75 true @@ -737,6 +738,7 @@ + 75 true @@ -749,6 +751,7 @@ + 75 true @@ -877,8 +880,8 @@ Send - - + + false @@ -907,6 +910,7 @@ + 75 true @@ -945,7 +949,7 @@ - + Send To @@ -979,8 +983,8 @@ 0 0 - 1301 - 493 + 1331 + 527 @@ -1163,24 +1167,27 @@ - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - + + + + Use custom Fee + + - + + + + Qt::Horizontal + + + + 1198 + 20 + + + + + @@ -1972,7 +1979,7 @@ 0 0 1379 - 24 + 22 diff --git a/src/sendtab.cpp b/src/sendtab.cpp index 2bd4fab..96153d8 100644 --- a/src/sendtab.cpp +++ b/src/sendtab.cpp @@ -31,6 +31,9 @@ void MainWindow::setupSendTab() { // Max available Checkbox QObject::connect(ui->Max1, &QCheckBox::stateChanged, this, &MainWindow::maxAmountChecked); + //Custom Fee Checkbox + QObject::connect(ui->customFee, &QCheckBox::stateChanged, this, &MainWindow::toggleMinerFeeEditable); + // The first Address button QObject::connect(ui->Address1, &QLineEdit::textChanged, [=] (auto text) { this->addressChanged(1, text); @@ -57,8 +60,8 @@ void MainWindow::setupSendTab() { this->amountChanged(1, text); }); - // Fee amount changed ui->minerFeeAmt->setReadOnly(true); + // Fee amount changed QObject::connect(ui->minerFeeAmt, &QLineEdit::textChanged, [=](auto txt) { CAmount fee = CAmount::fromDecimalString(txt); @@ -520,7 +523,6 @@ Tx MainWindow::createTxFromSendPage() { CAmount amt; - // Make sure it parses amtStr.toDouble(&ok); if (!ok) { @@ -534,16 +536,21 @@ Tx MainWindow::createTxFromSendPage() { QString memo = ui->sendToWidgets->findChild(QString("MemoTxt") % QString::number(i+1))->text().trimmed(); - - tx.toAddrs.push_back( ToFields{addr, amt, memo} ); } + // Allow Custom Fee in SendTab + bool customFee = ui->customFee->isChecked(); - - tx.fee = Settings::getMinerFee(); + CAmount fee ; + if (customFee) { + QString feeStr = ui->minerFeeAmt->text(); + tx.fee = CAmount::fromDecimalString(feeStr); + }else{ + tx.fee = Settings::getMinerFee(); + } return tx; } @@ -797,11 +804,20 @@ bool MainWindow::confirmTx(Tx tx, RecurringPaymentInfo* rpi) { confirm.lblRecurringDesc->setText(rpi->getScheduleDescription()); } + CAmount defaultFee = Settings::getMinerFee(); + if (tx.fee.toDecimalString() != defaultFee.toDecimalString() ) { + auto customFeeWarning = new QLabel(confirm.sendToAddrs); + customFeeWarning->setObjectName(QStringLiteral("Custom Fee")); + customFeeWarning->setText(tr("You are using a custom Fee")); + customFeeWarning->setStyleSheet("color: red;"); + confirm.gridLayout->addWidget(customFeeWarning); + confirm.gridLayout->rowStretch(1); + row++; +} + // Syncing warning confirm.syncingWarning->setVisible(Settings::getInstance()->isSyncing()); - - // Show the dialog and submit it if the user confirms return d.exec() == QDialog::Accepted; } @@ -956,9 +972,24 @@ QString MainWindow::doSendTxValidations(Tx tx) { .arg(available.toDecimalhushString(), total.toDecimalhushString()); } + if (total == 0) { + return tr("Value or fee must be > 0\n\nValue and fee cannot both be 0."); + + } + return ""; } void MainWindow::cancelButton() { clearSendForm(); } + +//Check for custom fee checkbox +void MainWindow::toggleMinerFeeEditable(int state) { + if (state == Qt::Checked) { + ui->minerFeeAmt->setReadOnly(false); + } else { + ui->minerFeeAmt->setReadOnly(true); + ui->minerFeeAmt->setText(Settings::getMinerFee().toDecimalString()); + } +} \ No newline at end of file