diff --git a/src/dialog/VerifyProofDialog.cpp b/src/dialog/VerifyProofDialog.cpp index f27aa02..937b6d9 100644 --- a/src/dialog/VerifyProofDialog.cpp +++ b/src/dialog/VerifyProofDialog.cpp @@ -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 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 diff --git a/src/dialog/VerifyProofDialog.h b/src/dialog/VerifyProofDialog.h index 4d9f3ab..ca2f641 100644 --- a/src/dialog/VerifyProofDialog.h +++ b/src/dialog/VerifyProofDialog.h @@ -32,6 +32,8 @@ private: void checkInProof(); void checkFormattedProof(); void proofStatus(bool success, const QString &message); + void onTxProofVerified(TxProofResult result); + void onSpendProofVerified(QPair result); QScopedPointer ui; Wallet *m_wallet; diff --git a/src/libwalletqt/Wallet.cpp b/src/libwalletqt/Wallet.cpp index ea1d844..41225dd 100644 --- a/src/libwalletqt/Wallet.cpp +++ b/src/libwalletqt/Wallet.cpp @@ -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 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) { diff --git a/src/libwalletqt/Wallet.h b/src/libwalletqt/Wallet.h index f54e8c7..9bcdd67 100644 --- a/src/libwalletqt/Wallet.h +++ b/src/libwalletqt/Wallet.h @@ -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 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 result); // emitted when transaction is created async void transactionCreated(PendingTransaction * transaction, QVector address); diff --git a/src/main.cpp b/src/main.cpp index 6850195..c748615 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -207,6 +207,8 @@ if (AttachConsole(ATTACH_PARENT_PROCESS)) { qInstallMessageHandler(Utils::applicationLogHandler); qRegisterMetaType>(); + qRegisterMetaType("TxProofResult"); + qRegisterMetaType>(); WindowManager windowManager;