]> Nutra Git (v1) - gamesguru/feather.git/commitdiff
VerifyProofDialog: don't hang on verify
authortobtoht <thotbot@protonmail.com>
Fri, 22 Oct 2021 19:25:27 +0000 (21:25 +0200)
committertobtoht <thotbot@protonmail.com>
Fri, 22 Oct 2021 19:25:27 +0000 (21:25 +0200)
src/dialog/VerifyProofDialog.cpp
src/dialog/VerifyProofDialog.h
src/libwalletqt/Wallet.cpp
src/libwalletqt/Wallet.h
src/main.cpp

index f27aa027893ec66e66bfea00fc288e2a7d9a2020..937b6d9bf42509f0d9d29def5d8b3823d16cbeb4 100644 (file)
@@ -50,6 +50,9 @@ VerifyProofDialog::VerifyProofDialog(Wallet *wallet, QWidget *parent)
         }
     });
 
+    connect(m_wallet, &Wallet::transactionProofVerified, this, &VerifyProofDialog::onTxProofVerified);
+    connect(m_wallet, &Wallet::spendProofVerified, this, &VerifyProofDialog::onSpendProofVerified);
+
     ui->input_formattedProof->setFont(ModelUtils::getMonospaceFont());
 }
 
@@ -69,31 +72,15 @@ void VerifyProofDialog::checkProof() {
 
 void VerifyProofDialog::checkTxProof(const QString &txId, const QString &address, const QString &message,
                                      const QString &signature) {
-    TxProofResult r = m_wallet->checkTxProof(txId, address, message, signature);
-
-    if (!r.success) {
-        this->proofStatus(false, m_wallet->errorString());
-        return;
-    }
-
-    if (!r.good) {
-        this->proofStatus(false, "Proof is invalid");
-        return;
-    }
-
-    this->proofStatus(true, QString("Proof is valid.\n\nThis address received %1 XMR, with %2 confirmation(s)").arg(WalletManager::displayAmount(r.received), QString::number(r.confirmations)));
+    ui->btn_verifyFormattedProof->setEnabled(false);
+    ui->btn_verify->setEnabled(false);
+    m_wallet->checkTxProofAsync(txId, address, message, signature);
 }
 
 void VerifyProofDialog::checkSpendProof(const QString &txId, const QString &message, const QString &signature) {
-    auto r = m_wallet->checkSpendProof(txId, message, signature);
-
-    if (!r.first) {
-        this->proofStatus(false, m_wallet->errorString());
-        return;
-    }
-
-    r.second ? this->proofStatus(true, "Proof is valid")
-             : this->proofStatus(false, "Proof is invalid");
+    ui->btn_verifyFormattedProof->setEnabled(false);
+    ui->btn_verify->setEnabled(false);
+    m_wallet->checkSpendProofAsync(txId, message, signature);
 }
 
 void VerifyProofDialog::checkOutProof() {
@@ -163,11 +150,37 @@ void VerifyProofDialog::proofStatus(bool success, const QString &message) {
         ui->frame_status->show();
         ui->label_icon->setPixmap(success ? m_success : m_failure);
         ui->label_status->setText(message);
+        ui->btn_verifyFormattedProof->setEnabled(true);
     }
     else {
+        ui->btn_verify->setEnabled(true);
         success ? QMessageBox::information(this, "Information", message)
                 : QMessageBox::warning(this, "Warning", message);
     }
 }
 
+void VerifyProofDialog::onTxProofVerified(TxProofResult r) {
+    if (!r.success) {
+        this->proofStatus(false, m_wallet->errorString());
+        return;
+    }
+
+    if (!r.good) {
+        this->proofStatus(false, "Proof is invalid");
+        return;
+    }
+
+    this->proofStatus(true, QString("Proof is valid.\n\nThis address received %1 XMR, with %2 confirmation(s)").arg(WalletManager::displayAmount(r.received), QString::number(r.confirmations)));
+}
+
+void VerifyProofDialog::onSpendProofVerified(QPair<bool, bool> r) {
+    if (!r.first) {
+        this->proofStatus(false, m_wallet->errorString());
+        return;
+    }
+
+    r.second ? this->proofStatus(true, "Proof is valid")
+             : this->proofStatus(false, "Proof is invalid");
+}
+
 VerifyProofDialog::~VerifyProofDialog() = default;
\ No newline at end of file
index 4d9f3ab4b4b4f36f14bd31c957d563a91281c102..ca2f641af4f1167c731672aba751b4004ea7c457 100644 (file)
@@ -32,6 +32,8 @@ private:
     void checkInProof();
     void checkFormattedProof();
     void proofStatus(bool success, const QString &message);
+    void onTxProofVerified(TxProofResult result);
+    void onSpendProofVerified(QPair<bool, bool> result);
 
     QScopedPointer<Ui::VerifyProofDialog> ui;
     Wallet *m_wallet;
index ea1d844db3154fbf0a2adc7e02058edb3ac8d668..41225dd21f2d172fde24fe90be8784be0f349453 100644 (file)
@@ -1016,6 +1016,14 @@ TxProofResult Wallet::checkTxProof(const QString &txid, const QString &address,
     return {success, good, received, in_pool, confirmations};
 }
 
+void Wallet::checkTxProofAsync(const QString &txid, const QString &address, const QString &message,
+                               const QString &signature) {
+    m_scheduler.run([this, txid, address, message, signature] {
+        auto result = this->checkTxProof(txid, address, message, signature);
+        emit transactionProofVerified(result);
+    });
+}
+
 Q_INVOKABLE TxProof Wallet::getSpendProof(const QString &txid, const QString &message) const
 {
     std::string result = m_walletImpl->getSpendProof(txid.toStdString(), message.toStdString());
@@ -1036,6 +1044,13 @@ Q_INVOKABLE QPair<bool, bool> Wallet::checkSpendProof(const QString &txid, const
     return {success, good};
 }
 
+void Wallet::checkSpendProofAsync(const QString &txid, const QString &message, const QString &signature) {
+    m_scheduler.run([this, txid, message, signature] {
+        auto result = this->checkSpendProof(txid, message, signature);
+        emit spendProofVerified(result);
+    });
+}
+
 QString Wallet::signMessage(const QString &message, bool filename, const QString &address) const
 {
   if (filename) {
index f54e8c77a3dab24e5f2949e8d36dc0a566990d42..9bcdd670761699ea1d299385d64000aa30919a20 100644 (file)
@@ -61,6 +61,7 @@ class Coins;
 class CoinsModel;
 
 struct TxProofResult {
+    TxProofResult() {}
     TxProofResult(bool success, bool good, uint64_t received, bool in_pool, uint64_t confirmations)
       : success(success), good(good), received(received), in_pool(in_pool), confirmations(confirmations){}
 
@@ -406,9 +407,11 @@ public:
    // void getTxProofAsync(const QString &txid, const QString &address, const QString &message, const QJSValue &callback);
     //QString checkTxProof(const QString &txid, const QString &address, const QString &message, const QString &signature);
     TxProofResult checkTxProof(const QString &txid, const QString &address, const QString &message, const QString &signature);
+    void checkTxProofAsync(const QString &txid, const QString &address, const QString &message, const QString &signature);
     TxProof getSpendProof(const QString &txid, const QString &message) const;
    // void getSpendProofAsync(const QString &txid, const QString &message, const QJSValue &callback);
     QPair<bool, bool> checkSpendProof(const QString &txid, const QString &message, const QString &signature) const;
+    void checkSpendProofAsync(const QString &txid, const QString &message, const QString &signature);
     // Rescan spent outputs
     bool rescanSpent();
 
@@ -475,6 +478,8 @@ signals:
     void transactionCommitted(bool status, PendingTransaction *t, const QStringList& txid);
     void heightRefreshed(quint64 walletHeight, quint64 daemonHeight, quint64 targetHeight) const;
     void deviceShowAddressShowed();
+    void transactionProofVerified(TxProofResult result);
+    void spendProofVerified(QPair<bool, bool> result);
 
     // emitted when transaction is created async
     void transactionCreated(PendingTransaction * transaction, QVector<QString> address);
index 6850195900ca253c061b854e13c9efa749d00600..c748615ea645ef1965837c0e9ceff7bad27ba00d 100644 (file)
@@ -207,6 +207,8 @@ if (AttachConsole(ATTACH_PARENT_PROCESS)) {
 
     qInstallMessageHandler(Utils::applicationLogHandler);
     qRegisterMetaType<QVector<QString>>();
+    qRegisterMetaType<TxProofResult>("TxProofResult");
+    qRegisterMetaType<QPair<bool, bool>>();
 
     WindowManager windowManager;