, ui(new Ui::TxInfoDialog)
, m_ctx(std::move(ctx))
, m_txInfo(txInfo)
+ , m_txProofDialog(new TxProofDialog(this, m_ctx, txInfo))
{
ui->setupUi(this);
m_txid = txInfo->hash();
ui->label_txid->setText(m_txid);
- m_txKey = m_ctx->wallet->getTxKey(txInfo->hash());
- if (m_txKey.isEmpty()) {
- ui->btn_CopyTxKey->setEnabled(false);
- ui->btn_CopyTxKey->setToolTip("Transaction key unknown");
- }
-
connect(ui->btn_CopyTxKey, &QPushButton::pressed, this, &TxInfoDialog::copyTxKey);
connect(ui->btn_createTxProof, &QPushButton::pressed, this, &TxInfoDialog::createTxProof);
ui->frameDestinations->hide();
}
- m_txProofDialog = new TxProofDialog(this, m_ctx, txInfo);
-
QCoreApplication::processEvents();
qreal lineHeight = QFontMetrics(ui->destinations->document()->defaultFont()).height();
}
void TxInfoDialog::copyTxKey() {
- Utils::copyToClipboard(m_txKey);
+ m_ctx->wallet->getTxKeyAsync(m_txid, [this](QVariantMap map){
+ QString txKey = map.value("tx_key").toString();
+ if (txKey.isEmpty()) {
+ QMessageBox::warning(this, "Unable to copy transaction key", "Transaction key unknown");
+ } else {
+ Utils::copyToClipboard(txKey);
+ QMessageBox::information(this, "Transaction key copied", "Transaction key copied to clipboard.");
+ }
+ });
}
void TxInfoDialog::createTxProof() {
m_txProofDialog->show();
+ m_txProofDialog->getTxKey();
}
TxInfoDialog::~TxInfoDialog() = default;
\ No newline at end of file
QSharedPointer<AppContext> m_ctx;
TransactionInfo *m_txInfo;
TxProofDialog *m_txProofDialog;
- QString m_txKey;
QString m_txid;
};
ui->setupUi(this);
m_txid = txInfo->hash();
- m_txKey = m_ctx->wallet->getTxKey(m_txid);
+
m_direction = txInfo->direction();
for (auto const &t: txInfo->transfers()) {
this->adjustSize();
}
+void TxProofDialog::getTxKey() {
+ if (!m_txKey.isEmpty()) return;
+
+ m_ctx->wallet->getTxKeyAsync(m_txid, [this](QVariantMap map){
+ m_txKey = map.value("tx_key").toString();
+ });
+}
+
void TxProofDialog::setTxId(const QString &txid) {
ui->label_txid->setText(txid);
}
explicit TxProofDialog(QWidget *parent, QSharedPointer<AppContext> ctx, TransactionInfo *txid);
~TxProofDialog() override;
void setTxId(const QString &txid);
+ void getTxKey();
private slots:
void selectSpendProof();
return QString::fromStdString(m_walletImpl->getTxKey(txid.toStdString()));
}
-//void Wallet::getTxKeyAsync(const QString &txid, const QJSValue &callback)
-//{
-// m_scheduler.run([this, txid] {
-// return QJSValueList({txid, getTxKey(txid)});
-// }, callback);
-//}
+void Wallet::getTxKeyAsync(const QString &txid, const std::function<void (QVariantMap)> &callback)
+{
+ m_scheduler.run([this, txid] {
+ QVariantMap map;
+ map["tx_key"] = getTxKey(txid);
+ return map;
+ }, callback);
+}
QString Wallet::checkTxKey(const QString &txid, const QString &tx_key, const QString &address)
{
bool setUserNote(const QString &txid, const QString ¬e);
QString getUserNote(const QString &txid) const;
QString getTxKey(const QString &txid) const;
- //void getTxKeyAsync(const QString &txid, const QJSValue &callback);
+ void getTxKeyAsync(const QString &txid, const std::function<void (QVariantMap)> &callback);
+
QString checkTxKey(const QString &txid, const QString &tx_key, const QString &address);
TxProof getTxProof(const QString &txid, const QString &address, const QString &message) const;
// void getTxProofAsync(const QString &txid, const QString &address, const QString &message, const QJSValue &callback);
});
}
-//QPair<bool, QFuture<QJSValueList>> FutureScheduler::run(std::function<QJSValueList()> function, const QJSValue &callback)
-//{
-// if (!callback.isCallable())
-// {
-// throw std::runtime_error("js callback must be callable");
-// }
-
-// return execute<QJSValueList>([this, function, callback](QFutureWatcher<QJSValueList> *watcher) {
-// connect(watcher, &QFutureWatcher<QJSValueList>::finished, [watcher, callback] {
-// QJSValue(callback).call(watcher->future().result());
-// });
-// return QtConcurrent::run([this, function] {
-// QJSValueList result;
-// try
-// {
-// result = function();
-// }
-// catch (const std::exception &exception)
-// {
-// qWarning() << "Exception thrown from async function: " << exception.what();
-// }
-// done();
-// return result;
-// });
-// });
-//}
+QPair<bool, QFuture<QVariantMap>> FutureScheduler::run(const std::function<QVariantMap()> &function, const std::function<void (QVariantMap)> &callback) noexcept
+{
+ return execute<QVariantMap>([this, function, callback](QFutureWatcher<QVariantMap> *watcher) {
+ connect(watcher, &QFutureWatcher<QVariantMap>::finished, [watcher, callback] {
+ callback(watcher->future().result());
+ });
+ return QtConcurrent::run([this, function] {
+ QVariantMap result;
+ try
+ {
+ result = function();
+ }
+ catch (const std::exception &exception)
+ {
+ qWarning() << "Exception thrown from async function: " << exception.what();
+ }
+ done();
+ return result;
+ });
+ });
+}
bool FutureScheduler::stopping() const noexcept
{
void shutdownWaitForFinished() noexcept;
QPair<bool, QFuture<void>> run(std::function<void()> function) noexcept;
+ QPair<bool, QFuture<QVariantMap>> run(const std::function<QVariantMap()>& function, const std::function<void (QVariantMap)>& callback) noexcept;
+
// QPair<bool, QFuture<QJSValueList>> run(std::function<QJSValueList()> function, const QJSValue &callback);
bool stopping() const noexcept;
}
QFutureWatcher<void> schedule(std::function<void()> function);
- //QFutureWatcher<QJSValueList> schedule(std::function<QJSValueList() noexcept> function, const QJSValue &callback);
+// QFutureWatcher<QVariantMap> schedule(std::function<QVariantMap() noexcept> function, std::function<void> &callback);
private:
size_t Alive;