2020-10-16 03:05:05 +00:00
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
2022-02-10 10:26:41 +00:00
|
|
|
// SPDX-FileCopyrightText: 2020-2022 The Monero Project
|
2020-10-16 03:05:05 +00:00
|
|
|
|
2021-06-27 12:22:54 +00:00
|
|
|
#include "TxBroadcastDialog.h"
|
|
|
|
#include "ui_TxBroadcastDialog.h"
|
2020-10-16 03:05:05 +00:00
|
|
|
|
|
|
|
#include <QMessageBox>
|
|
|
|
|
2021-06-27 14:33:18 +00:00
|
|
|
#include "utils/NetworkManager.h"
|
|
|
|
|
2021-06-27 12:22:54 +00:00
|
|
|
TxBroadcastDialog::TxBroadcastDialog(QWidget *parent, QSharedPointer<AppContext> ctx, const QString &transactionHex)
|
2021-10-22 17:19:56 +00:00
|
|
|
: WindowModalDialog(parent)
|
2021-06-27 12:22:54 +00:00
|
|
|
, ui(new Ui::TxBroadcastDialog)
|
2021-05-18 15:59:18 +00:00
|
|
|
, m_ctx(std::move(ctx))
|
2020-10-16 03:05:05 +00:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
2021-05-23 22:15:31 +00:00
|
|
|
auto node = m_ctx->nodes->connection();
|
2021-05-02 18:22:38 +00:00
|
|
|
m_rpc = new DaemonRpc(this, getNetworkTor(), node.toAddress());
|
2020-10-16 03:05:05 +00:00
|
|
|
|
2021-06-27 12:22:54 +00:00
|
|
|
connect(ui->btn_Broadcast, &QPushButton::clicked, this, &TxBroadcastDialog::broadcastTx);
|
|
|
|
connect(ui->btn_Close, &QPushButton::clicked, this, &TxBroadcastDialog::reject);
|
2020-10-16 03:05:05 +00:00
|
|
|
|
2021-06-27 12:22:54 +00:00
|
|
|
connect(m_rpc, &DaemonRpc::ApiResponse, this, &TxBroadcastDialog::onApiResponse);
|
2020-10-16 03:05:05 +00:00
|
|
|
|
2020-12-14 22:07:23 +00:00
|
|
|
if (!transactionHex.isEmpty()) {
|
|
|
|
ui->transaction->setPlainText(transactionHex);
|
|
|
|
}
|
|
|
|
|
2020-10-16 03:05:05 +00:00
|
|
|
this->adjustSize();
|
|
|
|
}
|
|
|
|
|
2021-06-27 12:22:54 +00:00
|
|
|
void TxBroadcastDialog::broadcastTx() {
|
2020-10-16 03:05:05 +00:00
|
|
|
QString tx = ui->transaction->toPlainText();
|
|
|
|
|
2021-05-24 22:08:19 +00:00
|
|
|
FeatherNode node = ui->radio_useCustom->isChecked() ? FeatherNode(ui->customNode->text()) : m_ctx->nodes->connection();
|
2020-10-16 03:05:05 +00:00
|
|
|
|
2021-05-24 22:08:19 +00:00
|
|
|
if (node.isLocal()) {
|
|
|
|
m_rpc->setNetwork(getNetworkClearnet());
|
|
|
|
} else {
|
|
|
|
m_rpc->setNetwork(getNetworkTor());
|
|
|
|
}
|
2020-10-16 03:05:05 +00:00
|
|
|
|
2021-05-24 22:08:19 +00:00
|
|
|
m_rpc->setDaemonAddress(node.toURL());
|
2020-10-16 03:05:05 +00:00
|
|
|
m_rpc->sendRawTransaction(tx);
|
|
|
|
}
|
|
|
|
|
2021-06-27 12:22:54 +00:00
|
|
|
void TxBroadcastDialog::onApiResponse(const DaemonRpc::DaemonResponse &resp) {
|
2020-10-16 03:05:05 +00:00
|
|
|
if (!resp.ok) {
|
|
|
|
QMessageBox::warning(this, "Transaction broadcast", resp.status);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (resp.endpoint == DaemonRpc::Endpoint::SEND_RAW_TRANSACTION) {
|
|
|
|
QMessageBox::information(this, "Transaction broadcast", "Transaction submitted successfully.\n\n"
|
|
|
|
"If the transaction belongs to this wallet it may take several minutes before it shows up in the history tab.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-27 12:22:54 +00:00
|
|
|
TxBroadcastDialog::~TxBroadcastDialog() = default;
|