added Wallet::createTransactionAsync()

This commit is contained in:
Jacob Brydolf 2016-11-08 16:33:36 +01:00
parent 68736ab834
commit 00ea5d6be9
2 changed files with 29 additions and 1 deletions

View File

@ -10,6 +10,7 @@
#include <QDebug>
#include <QUrl>
#include <QTimer>
#include <QtConcurrent/QtConcurrent>
namespace {
static const int DAEMON_BLOCKCHAIN_HEIGHT_CACHE_TTL_SECONDS = 10;
@ -211,10 +212,29 @@ PendingTransaction *Wallet::createTransaction(const QString &dst_addr, const QSt
Bitmonero::PendingTransaction * ptImpl = m_walletImpl->createTransaction(
dst_addr.toStdString(), payment_id.toStdString(), amount, mixin_count,
static_cast<Bitmonero::PendingTransaction::Priority>(priority));
PendingTransaction * result = new PendingTransaction(ptImpl, this);
PendingTransaction * result = new PendingTransaction(ptImpl, m_walletManager);
return result;
}
void Wallet::createTransactionAsync(const QString &dst_addr, const QString &payment_id,
quint64 amount, quint32 mixin_count,
PendingTransaction::Priority priority)
{
QFuture<PendingTransaction*> future = QtConcurrent::run(this, &Wallet::createTransaction,
dst_addr, payment_id,amount, mixin_count, priority);
QFutureWatcher<PendingTransaction*> * watcher = new QFutureWatcher<PendingTransaction*>();
watcher->setFuture(future);
connect(watcher, &QFutureWatcher<PendingTransaction*>::finished,
this, [this, watcher]() {
QFuture<PendingTransaction*> future = watcher->future();
watcher->deleteLater();
emit transactionCreated(future.result());
});
}
void Wallet::disposeTransaction(PendingTransaction *t)
{
m_walletImpl->disposeTransaction(t->m_pimpl);
@ -287,6 +307,7 @@ Wallet::Wallet(Bitmonero::Wallet *w, QObject *parent)
{
m_history = new TransactionHistory(m_walletImpl->history(), this);
m_walletImpl->setListener(new WalletListenerImpl(this));
m_walletManager = parent;
}
Wallet::~Wallet()

View File

@ -125,6 +125,10 @@ public:
Q_INVOKABLE PendingTransaction * createTransaction(const QString &dst_addr, const QString &payment_id,
quint64 amount, quint32 mixin_count,
PendingTransaction::Priority priority);
//! creates async transaction
Q_INVOKABLE void createTransactionAsync(const QString &dst_addr, const QString &payment_id,
quint64 amount, quint32 mixin_count,
PendingTransaction::Priority priority);
//! deletes transaction and frees memory
Q_INVOKABLE void disposeTransaction(PendingTransaction * t);
@ -166,6 +170,8 @@ signals:
void newBlock(quint64 height);
void historyModelChanged() const;
// emitted when transaction is created async
void transactionCreated(PendingTransaction * transaction);
private:
Wallet(QObject * parent = nullptr);
@ -188,6 +194,7 @@ private:
mutable QTime m_daemonBlockChainTargetHeightTime;
mutable quint64 m_daemonBlockChainTargetHeight;
int m_daemonBlockChainTargetHeightTtl;
QObject * m_walletManager;
};