mirror of
https://github.com/feather-wallet/feather.git
synced 2024-12-22 19:49:28 +00:00
TxImportDialog: use scanTransactions
This commit is contained in:
parent
f8905ce46b
commit
65b419c039
5 changed files with 7 additions and 124 deletions
|
@ -12,28 +12,15 @@ TxImportDialog::TxImportDialog(QWidget *parent, QSharedPointer<AppContext> ctx)
|
||||||
: WindowModalDialog(parent)
|
: WindowModalDialog(parent)
|
||||||
, ui(new Ui::TxImportDialog)
|
, ui(new Ui::TxImportDialog)
|
||||||
, m_ctx(std::move(ctx))
|
, m_ctx(std::move(ctx))
|
||||||
, m_loadTimer(new QTimer(this))
|
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
ui->resp->hide();
|
|
||||||
ui->label_loading->hide();
|
|
||||||
|
|
||||||
auto node = m_ctx->nodes->connection();
|
|
||||||
m_rpc = new DaemonRpc(this, getNetworkTor(), node.toAddress());
|
|
||||||
|
|
||||||
connect(ui->btn_load, &QPushButton::clicked, this, &TxImportDialog::loadTx);
|
|
||||||
connect(ui->btn_import, &QPushButton::clicked, this, &TxImportDialog::onImport);
|
connect(ui->btn_import, &QPushButton::clicked, this, &TxImportDialog::onImport);
|
||||||
|
|
||||||
connect(m_rpc, &DaemonRpc::ApiResponse, this, &TxImportDialog::onApiResponse);
|
|
||||||
|
|
||||||
connect(m_loadTimer, &QTimer::timeout, [this]{
|
|
||||||
ui->label_loading->setText(ui->label_loading->text() + ".");
|
|
||||||
});
|
|
||||||
|
|
||||||
this->adjustSize();
|
this->adjustSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TxImportDialog::loadTx() {
|
void TxImportDialog::onImport() {
|
||||||
QString txid = ui->line_txid->text();
|
QString txid = ui->line_txid->text();
|
||||||
|
|
||||||
if (m_ctx->wallet->haveTransaction(txid)) {
|
if (m_ctx->wallet->haveTransaction(txid)) {
|
||||||
|
@ -43,65 +30,7 @@ void TxImportDialog::loadTx() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
FeatherNode node = m_ctx->nodes->connection();
|
if (m_ctx->wallet->importTransaction(txid)) {
|
||||||
|
|
||||||
if (node.isLocal()) {
|
|
||||||
m_rpc->setNetwork(getNetworkClearnet());
|
|
||||||
} else {
|
|
||||||
m_rpc->setNetwork(getNetworkTor());
|
|
||||||
}
|
|
||||||
|
|
||||||
qDebug() << node.toURL();
|
|
||||||
m_rpc->setDaemonAddress(node.toURL());
|
|
||||||
m_rpc->getTransactions(QStringList() << txid, false, true);
|
|
||||||
|
|
||||||
ui->label_loading->setText("Loading transaction");
|
|
||||||
ui->label_loading->setHidden(false);
|
|
||||||
m_loadTimer->start(1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TxImportDialog::onApiResponse(const DaemonRpc::DaemonResponse &resp) {
|
|
||||||
m_loadTimer->stop();
|
|
||||||
ui->label_loading->setHidden(true);
|
|
||||||
if (!resp.ok) {
|
|
||||||
QMessageBox::warning(this, "Import transaction", resp.status);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (resp.endpoint == DaemonRpc::Endpoint::GET_TRANSACTIONS) {
|
|
||||||
ui->resp->setVisible(true);
|
|
||||||
ui->resp->setPlainText(QJsonDocument(resp.obj).toJson(QJsonDocument::Indented));
|
|
||||||
this->adjustSize();
|
|
||||||
|
|
||||||
if (resp.obj.contains("missed_tx")) {
|
|
||||||
ui->btn_import->setEnabled(false);
|
|
||||||
QMessageBox::warning(this, "Load transaction", "Transaction could not be found. Make sure the txid is correct, or try connecting to a different node.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QMessageBox::information(this, "Load transaction", "Transaction loaded successfully.\n\nAfter closing this message box click the Import button to import the transaction into your wallet.");
|
|
||||||
m_transaction = resp.obj;
|
|
||||||
ui->btn_import->setEnabled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void TxImportDialog::onImport() {
|
|
||||||
QJsonObject tx = m_transaction.value("txs").toArray().first().toObject();
|
|
||||||
|
|
||||||
QString txid = tx.value("tx_hash").toString();
|
|
||||||
|
|
||||||
QVector<quint64> output_indices;
|
|
||||||
for (const auto &o: tx.value("output_indices").toArray()) {
|
|
||||||
output_indices.push_back(o.toInt());
|
|
||||||
}
|
|
||||||
|
|
||||||
quint64 height = tx.value("block_height").toInt();
|
|
||||||
quint64 timestamp = tx.value("block_timestamp").toInt();
|
|
||||||
|
|
||||||
bool pool = tx.value("in_pool").toBool();
|
|
||||||
bool double_spend_seen = tx.value("double_spend_seen").toBool();
|
|
||||||
|
|
||||||
if (m_ctx->wallet->importTransaction(tx.value("tx_hash").toString(), output_indices, height, timestamp, false, pool, double_spend_seen)) {
|
|
||||||
if (!m_ctx->wallet->haveTransaction(txid)) {
|
if (!m_ctx->wallet->haveTransaction(txid)) {
|
||||||
QMessageBox::warning(this, "Import transaction", "This transaction does not belong to this wallet.");
|
QMessageBox::warning(this, "Import transaction", "This transaction does not belong to this wallet.");
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -23,18 +23,11 @@ public:
|
||||||
~TxImportDialog() override;
|
~TxImportDialog() override;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void loadTx();
|
|
||||||
void onImport();
|
void onImport();
|
||||||
void onApiResponse(const DaemonRpc::DaemonResponse &resp);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QScopedPointer<Ui::TxImportDialog> ui;
|
QScopedPointer<Ui::TxImportDialog> ui;
|
||||||
QSharedPointer<AppContext> m_ctx;
|
QSharedPointer<AppContext> m_ctx;
|
||||||
|
|
||||||
DaemonRpc *m_rpc;
|
|
||||||
QTimer *m_loadTimer;
|
|
||||||
|
|
||||||
QJsonObject m_transaction;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>700</width>
|
<width>700</width>
|
||||||
<height>442</height>
|
<height>88</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="minimumSize">
|
<property name="minimumSize">
|
||||||
|
@ -27,42 +27,15 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
|
||||||
<widget class="QPlainTextEdit" name="resp">
|
|
||||||
<property name="readOnly">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
<property name="placeholderText">
|
|
||||||
<string>Debug info..</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
<item>
|
|
||||||
<widget class="QPushButton" name="btn_load">
|
|
||||||
<property name="text">
|
|
||||||
<string>Load</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="btn_import">
|
<widget class="QPushButton" name="btn_import">
|
||||||
<property name="enabled">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Import</string>
|
<string>Import</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
|
||||||
<widget class="QLabel" name="label_loading">
|
|
||||||
<property name="text">
|
|
||||||
<string>Loading transaction</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
<item>
|
||||||
<widget class="QDialogButtonBox" name="buttonBox">
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
|
|
|
@ -495,21 +495,9 @@ bool Wallet::importOutputs(const QString& path) {
|
||||||
return m_walletImpl->importOutputs(path.toStdString());
|
return m_walletImpl->importOutputs(path.toStdString());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Wallet::importTransaction(const QString& txid, const QVector<quint64>& output_indeces, quint64 height, quint64 timestamp, bool miner_tx, bool pool, bool double_spend_seen) {
|
bool Wallet::importTransaction(const QString& txid) {
|
||||||
std::vector<uint64_t> o_indeces;
|
std::vector<std::string> txids = {txid.toStdString()};
|
||||||
for (const auto &o : output_indeces) {
|
return m_walletImpl->scanTransactions(txids);
|
||||||
o_indeces.push_back(o);
|
|
||||||
}
|
|
||||||
|
|
||||||
return m_walletImpl->importTransaction(
|
|
||||||
txid.toStdString(),
|
|
||||||
o_indeces,
|
|
||||||
height,
|
|
||||||
17, // todo: get actual block_version
|
|
||||||
timestamp,
|
|
||||||
miner_tx,
|
|
||||||
pool,
|
|
||||||
double_spend_seen);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Wallet::printBlockchain()
|
QString Wallet::printBlockchain()
|
||||||
|
|
|
@ -231,7 +231,7 @@ public:
|
||||||
bool importOutputs(const QString& path);
|
bool importOutputs(const QString& path);
|
||||||
|
|
||||||
//! import a transaction
|
//! import a transaction
|
||||||
bool importTransaction(const QString& txid, const QVector<quint64>& output_indeces, quint64 height, quint64 timestamp, bool miner_tx, bool pool, bool double_spend_seen);
|
bool importTransaction(const QString& txid);
|
||||||
|
|
||||||
QString printBlockchain();
|
QString printBlockchain();
|
||||||
QString printTransfers();
|
QString printTransfers();
|
||||||
|
|
Loading…
Reference in a new issue