mirror of
https://github.com/feather-wallet/feather.git
synced 2024-11-17 01:37:53 +00:00
Trezor: get tx key async
This commit is contained in:
parent
357486359f
commit
1e943b6208
8 changed files with 55 additions and 45 deletions
|
@ -20,18 +20,13 @@ TxInfoDialog::TxInfoDialog(QSharedPointer<AppContext> ctx, TransactionInfo *txIn
|
|||
, 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);
|
||||
|
||||
|
@ -61,8 +56,6 @@ TxInfoDialog::TxInfoDialog(QSharedPointer<AppContext> ctx, TransactionInfo *txIn
|
|||
ui->frameDestinations->hide();
|
||||
}
|
||||
|
||||
m_txProofDialog = new TxProofDialog(this, m_ctx, txInfo);
|
||||
|
||||
QCoreApplication::processEvents();
|
||||
|
||||
qreal lineHeight = QFontMetrics(ui->destinations->document()->defaultFont()).height();
|
||||
|
@ -125,11 +118,20 @@ void TxInfoDialog::updateData() {
|
|||
}
|
||||
|
||||
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;
|
|
@ -36,7 +36,6 @@ private:
|
|||
QSharedPointer<AppContext> m_ctx;
|
||||
TransactionInfo *m_txInfo;
|
||||
TxProofDialog *m_txProofDialog;
|
||||
QString m_txKey;
|
||||
QString m_txid;
|
||||
};
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ TxProofDialog::TxProofDialog(QWidget *parent, QSharedPointer<AppContext> ctx, Tr
|
|||
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()) {
|
||||
|
@ -54,6 +54,14 @@ TxProofDialog::TxProofDialog(QWidget *parent, QSharedPointer<AppContext> ctx, Tr
|
|||
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);
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ public:
|
|||
explicit TxProofDialog(QWidget *parent, QSharedPointer<AppContext> ctx, TransactionInfo *txid);
|
||||
~TxProofDialog() override;
|
||||
void setTxId(const QString &txid);
|
||||
void getTxKey();
|
||||
|
||||
private slots:
|
||||
void selectSpendProof();
|
||||
|
|
|
@ -969,12 +969,14 @@ QString Wallet::getTxKey(const QString &txid) const
|
|||
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)
|
||||
{
|
||||
|
|
|
@ -393,7 +393,8 @@ public:
|
|||
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);
|
||||
|
|
|
@ -45,32 +45,27 @@ QPair<bool, QFuture<void>> FutureScheduler::run(std::function<void()> function)
|
|||
});
|
||||
}
|
||||
|
||||
//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
|
||||
{
|
||||
|
|
|
@ -25,6 +25,8 @@ public:
|
|||
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;
|
||||
|
||||
|
@ -57,7 +59,7 @@ private:
|
|||
}
|
||||
|
||||
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;
|
||||
|
|
Loading…
Reference in a new issue