VerifyProofDialog: don't hang on verify

This commit is contained in:
tobtoht 2021-10-22 21:25:27 +02:00
parent dcb2224537
commit 6ccc988420
No known key found for this signature in database
GPG key ID: 1CADD27F41F45C3C
5 changed files with 59 additions and 22 deletions

View 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;

View 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;

View 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) {

View 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);

View 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;