Skip to content

Commit b37f609

Browse files
committed
merge bitcoin-core/gui#399: Fix "Load PSBT" functionality when no wallet loaded
1 parent 94173f1 commit b37f609

File tree

6 files changed

+65
-58
lines changed

6 files changed

+65
-58
lines changed

src/qt/bitcoingui.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ BitcoinGUI::BitcoinGUI(interfaces::Node& node, const NetworkStyle* networkStyle,
111111
{
112112
/** Create wallet frame*/
113113
walletFrame = new WalletFrame(this);
114+
connect(walletFrame, &WalletFrame::message, [this](const QString& title, const QString& message, unsigned int style) {
115+
this->message(title, message, style);
116+
});
114117
} else
115118
#endif // ENABLE_WALLET
116119
{

src/qt/psbtoperationsdialog.cpp

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,22 @@ void PSBTOperationsDialog::openWithPSBT(PartiallySignedTransaction psbtx)
4747
{
4848
m_transaction_data = psbtx;
4949

50-
bool complete;
51-
size_t n_could_sign;
52-
FinalizePSBT(psbtx); // Make sure all existing signatures are fully combined before checking for completeness.
53-
TransactionError err = m_wallet_model->wallet().fillPSBT(SIGHASH_ALL, false /* sign */, true /* bip32derivs */, &n_could_sign, m_transaction_data, complete);
54-
if (err != TransactionError::OK) {
55-
showStatus(tr("Failed to load transaction: %1")
56-
.arg(QString::fromStdString(TransactionErrorString(err).translated)), StatusLevel::ERR);
57-
return;
50+
bool complete = FinalizePSBT(psbtx); // Make sure all existing signatures are fully combined before checking for completeness.
51+
if (m_wallet_model) {
52+
size_t n_could_sign;
53+
TransactionError err = m_wallet_model->wallet().fillPSBT(SIGHASH_ALL, false /* sign */, true /* bip32derivs */, &n_could_sign, m_transaction_data, complete);
54+
if (err != TransactionError::OK) {
55+
showStatus(tr("Failed to load transaction: %1")
56+
.arg(QString::fromStdString(TransactionErrorString(err).translated)),
57+
StatusLevel::ERR);
58+
return;
59+
}
60+
m_ui->signTransactionButton->setEnabled(!complete && !m_wallet_model->wallet().privateKeysDisabled() && n_could_sign > 0);
61+
} else {
62+
m_ui->signTransactionButton->setEnabled(false);
5863
}
5964

6065
m_ui->broadcastTransactionButton->setEnabled(complete);
61-
m_ui->signTransactionButton->setEnabled(!complete && !m_wallet_model->wallet().privateKeysDisabled() && n_could_sign > 0);
6266

6367
updateTransactionDisplay();
6468
}
@@ -133,7 +137,7 @@ void PSBTOperationsDialog::saveTransaction() {
133137
}
134138
CTxDestination address;
135139
ExtractDestination(out.scriptPubKey, address);
136-
QString amount = BitcoinUnits::format(m_wallet_model->getOptionsModel()->getDisplayUnit(), out.nValue);
140+
QString amount = BitcoinUnits::format(m_client_model->getOptionsModel()->getDisplayUnit(), out.nValue);
137141
QString address_str = QString::fromStdString(EncodeDestination(address));
138142
filename_suggestion.append(address_str + "-" + amount);
139143
first = false;
@@ -224,6 +228,10 @@ void PSBTOperationsDialog::showStatus(const QString &msg, StatusLevel level) {
224228
}
225229

226230
size_t PSBTOperationsDialog::couldSignInputs(const PartiallySignedTransaction &psbtx) {
231+
if (!m_wallet_model) {
232+
return 0;
233+
}
234+
227235
size_t n_signed;
228236
bool complete;
229237
TransactionError err = m_wallet_model->wallet().fillPSBT(SIGHASH_ALL, false /* sign */, false /* bip32derivs */, &n_signed, m_transaction_data, complete);
@@ -246,7 +254,10 @@ void PSBTOperationsDialog::showTransactionStatus(const PartiallySignedTransactio
246254
case PSBTRole::SIGNER: {
247255
QString need_sig_text = tr("Transaction still needs signature(s).");
248256
StatusLevel level = StatusLevel::INFO;
249-
if (m_wallet_model->wallet().privateKeysDisabled()) {
257+
if (!m_wallet_model) {
258+
need_sig_text += " " + tr("(But no wallet is loaded.)");
259+
level = StatusLevel::WARN;
260+
} else if (m_wallet_model->wallet().privateKeysDisabled()) {
250261
need_sig_text += " " + tr("(But this wallet cannot sign transactions.)");
251262
level = StatusLevel::WARN;
252263
} else if (n_could_sign < 1) {

src/qt/walletframe.cpp

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,24 @@
44

55
#include <qt/walletframe.h>
66

7+
#include <node/ui_interface.h>
8+
#include <psbt.h>
79
#include <qt/bitcoingui.h>
810
#include <qt/createwalletdialog.h>
911
#include <qt/governancelist.h>
12+
#include <qt/guiutil.h>
1013
#include <qt/masternodelist.h>
1114
#include <qt/overviewpage.h>
15+
#include <qt/psbtoperationsdialog.h>
1216
#include <qt/walletcontroller.h>
1317
#include <qt/walletmodel.h>
1418
#include <qt/walletview.h>
1519
#include <util/system.h>
1620

1721
#include <cassert>
1822

23+
#include <QApplication>
24+
#include <QClipboard>
1925
#include <QHBoxLayout>
2026
#include <QLabel>
2127
#include <QPushButton>
@@ -245,10 +251,40 @@ void WalletFrame::gotoVerifyMessageTab(QString addr)
245251

246252
void WalletFrame::gotoLoadPSBT(bool from_clipboard)
247253
{
248-
WalletView *walletView = currentWalletView();
249-
if (walletView) {
250-
walletView->gotoLoadPSBT(from_clipboard);
254+
std::string data;
255+
256+
if (from_clipboard) {
257+
std::string raw = QApplication::clipboard()->text().toStdString();
258+
bool invalid;
259+
data = DecodeBase64(raw, &invalid);
260+
if (invalid) {
261+
Q_EMIT message(tr("Error"), tr("Unable to decode PSBT from clipboard (invalid base64)"), CClientUIInterface::MSG_ERROR);
262+
return;
263+
}
264+
} else {
265+
QString filename = GUIUtil::getOpenFileName(this,
266+
tr("Load Transaction Data"), QString(),
267+
tr("Partially Signed Transaction (*.psbt)"), nullptr);
268+
if (filename.isEmpty()) return;
269+
if (GetFileSize(filename.toLocal8Bit().data(), MAX_FILE_SIZE_PSBT) == MAX_FILE_SIZE_PSBT) {
270+
Q_EMIT message(tr("Error"), tr("PSBT file must be smaller than 100 MiB"), CClientUIInterface::MSG_ERROR);
271+
return;
272+
}
273+
std::ifstream in(filename.toLocal8Bit().data(), std::ios::binary);
274+
data = std::string(std::istreambuf_iterator<char>{in}, {});
275+
}
276+
277+
std::string error;
278+
PartiallySignedTransaction psbtx;
279+
if (!DecodeRawPSBT(psbtx, data, error)) {
280+
Q_EMIT message(tr("Error"), tr("Unable to decode PSBT") + "\n" + QString::fromStdString(error), CClientUIInterface::MSG_ERROR);
281+
return;
251282
}
283+
284+
PSBTOperationsDialog* dlg = new PSBTOperationsDialog(this, currentWalletModel(), clientModel);
285+
dlg->openWithPSBT(psbtx);
286+
dlg->setAttribute(Qt::WA_DeleteOnClose);
287+
dlg->exec();
252288
}
253289

254290
void WalletFrame::encryptWallet()

src/qt/walletframe.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class WalletFrame : public QFrame
5050
QSize sizeHint() const override { return m_size_hint; }
5151

5252
Q_SIGNALS:
53+
void message(const QString& title, const QString& message, unsigned int style);
5354
/** Notify that the user has requested more information about the out-of-sync warning */
5455
void requestedSyncWarningInfo();
5556

src/qt/walletview.cpp

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include <qt/askpassphrasedialog.h>
1212
#include <qt/clientmodel.h>
1313
#include <qt/guiutil.h>
14-
#include <qt/psbtoperationsdialog.h>
1514
#include <qt/optionsmodel.h>
1615
#include <qt/overviewpage.h>
1716
#include <qt/receivecoinsdialog.h>
@@ -24,13 +23,10 @@
2423

2524
#include <interfaces/node.h>
2625
#include <node/ui_interface.h>
27-
#include <psbt.h>
2826
#include <util/strencodings.h>
2927

3028
#include <QAction>
3129
#include <QActionGroup>
32-
#include <QApplication>
33-
#include <QClipboard>
3430
#include <QFileDialog>
3531
#include <QHBoxLayout>
3632
#include <QLabel>
@@ -298,44 +294,6 @@ void WalletView::gotoVerifyMessageTab(QString addr)
298294
signVerifyMessageDialog->setAddress_VM(addr);
299295
}
300296

301-
void WalletView::gotoLoadPSBT(bool from_clipboard)
302-
{
303-
std::string data;
304-
305-
if (from_clipboard) {
306-
std::string raw = QApplication::clipboard()->text().toStdString();
307-
bool invalid;
308-
data = DecodeBase64(raw, &invalid);
309-
if (invalid) {
310-
Q_EMIT message(tr("Error"), tr("Unable to decode PSBT from clipboard (invalid base64)"), CClientUIInterface::MSG_ERROR);
311-
return;
312-
}
313-
} else {
314-
QString filename = GUIUtil::getOpenFileName(this,
315-
tr("Load Transaction Data"), QString(),
316-
tr("Partially Signed Transaction (*.psbt)"), nullptr);
317-
if (filename.isEmpty()) return;
318-
if (GetFileSize(filename.toLocal8Bit().data(), MAX_FILE_SIZE_PSBT) == MAX_FILE_SIZE_PSBT) {
319-
Q_EMIT message(tr("Error"), tr("PSBT file must be smaller than 100 MiB"), CClientUIInterface::MSG_ERROR);
320-
return;
321-
}
322-
std::ifstream in(filename.toLocal8Bit().data(), std::ios::binary);
323-
data = std::string(std::istreambuf_iterator<char>{in}, {});
324-
}
325-
326-
std::string error;
327-
PartiallySignedTransaction psbtx;
328-
if (!DecodeRawPSBT(psbtx, data, error)) {
329-
Q_EMIT message(tr("Error"), tr("Unable to decode PSBT") + "\n" + QString::fromStdString(error), CClientUIInterface::MSG_ERROR);
330-
return;
331-
}
332-
333-
PSBTOperationsDialog* dlg = new PSBTOperationsDialog(this, walletModel, clientModel);
334-
dlg->openWithPSBT(psbtx);
335-
dlg->setAttribute(Qt::WA_DeleteOnClose);
336-
dlg->exec();
337-
}
338-
339297
bool WalletView::handlePaymentRequest(const SendCoinsRecipient& recipient)
340298
{
341299
return sendCoinsPage->handlePaymentRequest(recipient);

src/qt/walletview.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,6 @@ public Q_SLOTS:
9494
void gotoSignMessageTab(QString addr = "");
9595
/** Show Sign/Verify Message dialog and switch to verify message tab */
9696
void gotoVerifyMessageTab(QString addr = "");
97-
/** Load Partially Signed Bitcoin Transaction */
98-
void gotoLoadPSBT(bool from_clipboard = false);
9997

10098
/** Show incoming transaction notification for new transactions.
10199

0 commit comments

Comments
 (0)