Skip to content

Commit 0237d95

Browse files
committed
qt: Add Load PSBT functionaliy with nowallet
1 parent 03826ae commit 0237d95

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
@@ -110,6 +110,9 @@ BitcoinGUI::BitcoinGUI(interfaces::Node& node, const PlatformStyle *_platformSty
110110
connect(activity, &CreateWalletActivity::finished, activity, &QObject::deleteLater);
111111
activity->create();
112112
});
113+
connect(walletFrame, &WalletFrame::message, [this](const QString& title, const QString& message, unsigned int style) {
114+
this->message(title, message, style);
115+
});
113116
setCentralWidget(walletFrame);
114117
} else
115118
#endif // ENABLE_WALLET

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,12 +4,18 @@
44

55
#include <qt/walletframe.h>
66

7+
#include <node/ui_interface.h>
8+
#include <psbt.h>
9+
#include <qt/guiutil.h>
710
#include <qt/overviewpage.h>
11+
#include <qt/psbtoperationsdialog.h>
812
#include <qt/walletmodel.h>
913
#include <qt/walletview.h>
1014

1115
#include <cassert>
1216

17+
#include <QApplication>
18+
#include <QClipboard>
1319
#include <QGroupBox>
1420
#include <QHBoxLayout>
1521
#include <QLabel>
@@ -184,10 +190,40 @@ void WalletFrame::gotoVerifyMessageTab(QString addr)
184190

185191
void WalletFrame::gotoLoadPSBT(bool from_clipboard)
186192
{
187-
WalletView *walletView = currentWalletView();
188-
if (walletView) {
189-
walletView->gotoLoadPSBT(from_clipboard);
193+
std::string data;
194+
195+
if (from_clipboard) {
196+
std::string raw = QApplication::clipboard()->text().toStdString();
197+
bool invalid;
198+
data = DecodeBase64(raw, &invalid);
199+
if (invalid) {
200+
Q_EMIT message(tr("Error"), tr("Unable to decode PSBT from clipboard (invalid base64)"), CClientUIInterface::MSG_ERROR);
201+
return;
202+
}
203+
} else {
204+
QString filename = GUIUtil::getOpenFileName(this,
205+
tr("Load Transaction Data"), QString(),
206+
tr("Partially Signed Transaction (*.psbt)"), nullptr);
207+
if (filename.isEmpty()) return;
208+
if (GetFileSize(filename.toLocal8Bit().data(), MAX_FILE_SIZE_PSBT) == MAX_FILE_SIZE_PSBT) {
209+
Q_EMIT message(tr("Error"), tr("PSBT file must be smaller than 100 MiB"), CClientUIInterface::MSG_ERROR);
210+
return;
211+
}
212+
std::ifstream in(filename.toLocal8Bit().data(), std::ios::binary);
213+
data = std::string(std::istreambuf_iterator<char>{in}, {});
190214
}
215+
216+
std::string error;
217+
PartiallySignedTransaction psbtx;
218+
if (!DecodeRawPSBT(psbtx, data, error)) {
219+
Q_EMIT message(tr("Error"), tr("Unable to decode PSBT") + "\n" + QString::fromStdString(error), CClientUIInterface::MSG_ERROR);
220+
return;
221+
}
222+
223+
PSBTOperationsDialog* dlg = new PSBTOperationsDialog(this, currentWalletModel(), clientModel);
224+
dlg->openWithPSBT(psbtx);
225+
dlg->setAttribute(Qt::WA_DeleteOnClose);
226+
dlg->exec();
191227
}
192228

193229
void WalletFrame::encryptWallet()

src/qt/walletframe.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class WalletFrame : public QFrame
4848

4949
Q_SIGNALS:
5050
void createWalletButtonClicked();
51+
void message(const QString& title, const QString& message, unsigned int style);
5152

5253
private:
5354
QStackedWidget *walletStack;

src/qt/walletview.cpp

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include <qt/askpassphrasedialog.h>
99
#include <qt/clientmodel.h>
1010
#include <qt/guiutil.h>
11-
#include <qt/psbtoperationsdialog.h>
1211
#include <qt/optionsmodel.h>
1312
#include <qt/overviewpage.h>
1413
#include <qt/platformstyle.h>
@@ -21,13 +20,10 @@
2120

2221
#include <interfaces/node.h>
2322
#include <node/ui_interface.h>
24-
#include <psbt.h>
2523
#include <util/strencodings.h>
2624

2725
#include <QAction>
2826
#include <QActionGroup>
29-
#include <QApplication>
30-
#include <QClipboard>
3127
#include <QFileDialog>
3228
#include <QHBoxLayout>
3329
#include <QProgressDialog>
@@ -205,44 +201,6 @@ void WalletView::gotoVerifyMessageTab(QString addr)
205201
signVerifyMessageDialog->setAddress_VM(addr);
206202
}
207203

208-
void WalletView::gotoLoadPSBT(bool from_clipboard)
209-
{
210-
std::string data;
211-
212-
if (from_clipboard) {
213-
std::string raw = QApplication::clipboard()->text().toStdString();
214-
bool invalid;
215-
data = DecodeBase64(raw, &invalid);
216-
if (invalid) {
217-
Q_EMIT message(tr("Error"), tr("Unable to decode PSBT from clipboard (invalid base64)"), CClientUIInterface::MSG_ERROR);
218-
return;
219-
}
220-
} else {
221-
QString filename = GUIUtil::getOpenFileName(this,
222-
tr("Load Transaction Data"), QString(),
223-
tr("Partially Signed Transaction (*.psbt)"), nullptr);
224-
if (filename.isEmpty()) return;
225-
if (GetFileSize(filename.toLocal8Bit().data(), MAX_FILE_SIZE_PSBT) == MAX_FILE_SIZE_PSBT) {
226-
Q_EMIT message(tr("Error"), tr("PSBT file must be smaller than 100 MiB"), CClientUIInterface::MSG_ERROR);
227-
return;
228-
}
229-
std::ifstream in(filename.toLocal8Bit().data(), std::ios::binary);
230-
data = std::string(std::istreambuf_iterator<char>{in}, {});
231-
}
232-
233-
std::string error;
234-
PartiallySignedTransaction psbtx;
235-
if (!DecodeRawPSBT(psbtx, data, error)) {
236-
Q_EMIT message(tr("Error"), tr("Unable to decode PSBT") + "\n" + QString::fromStdString(error), CClientUIInterface::MSG_ERROR);
237-
return;
238-
}
239-
240-
PSBTOperationsDialog* dlg = new PSBTOperationsDialog(this, walletModel, clientModel);
241-
dlg->openWithPSBT(psbtx);
242-
dlg->setAttribute(Qt::WA_DeleteOnClose);
243-
dlg->exec();
244-
}
245-
246204
bool WalletView::handlePaymentRequest(const SendCoinsRecipient& recipient)
247205
{
248206
return sendCoinsPage->handlePaymentRequest(recipient);

src/qt/walletview.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ public Q_SLOTS:
8383
void gotoSignMessageTab(QString addr = "");
8484
/** Show Sign/Verify Message dialog and switch to verify message tab */
8585
void gotoVerifyMessageTab(QString addr = "");
86-
/** Load Partially Signed Bitcoin Transaction */
87-
void gotoLoadPSBT(bool from_clipboard = false);
8886

8987
/** Show incoming transaction notification for new transactions.
9088

0 commit comments

Comments
 (0)