Skip to content

Commit 11a0ffb

Browse files
committed
[gui] Load PSBT from clipboard
1 parent a6cb0b0 commit 11a0ffb

File tree

6 files changed

+38
-19
lines changed

6 files changed

+38
-19
lines changed

src/qt/bitcoingui.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,8 @@ void BitcoinGUI::createActions()
323323
verifyMessageAction->setStatusTip(tr("Verify messages to ensure they were signed with specified Bitcoin addresses"));
324324
m_load_psbt_action = new QAction(tr("&Load PSBT from file..."), this);
325325
m_load_psbt_action->setStatusTip(tr("Load Partially Signed Bitcoin Transaction"));
326+
m_load_psbt_clipboard_action = new QAction(tr("Load PSBT from clipboard..."), this);
327+
m_load_psbt_clipboard_action->setStatusTip(tr("Load Partially Signed Bitcoin Transaction from clipboard"));
326328

327329
openRPCConsoleAction = new QAction(tr("Node window"), this);
328330
openRPCConsoleAction->setStatusTip(tr("Open node debugging and diagnostic console"));
@@ -381,6 +383,7 @@ void BitcoinGUI::createActions()
381383
connect(signMessageAction, &QAction::triggered, [this]{ showNormalIfMinimized(); });
382384
connect(signMessageAction, &QAction::triggered, [this]{ gotoSignMessageTab(); });
383385
connect(m_load_psbt_action, &QAction::triggered, [this]{ gotoLoadPSBT(); });
386+
connect(m_load_psbt_clipboard_action, &QAction::triggered, [this]{ gotoLoadPSBT(true); });
384387
connect(verifyMessageAction, &QAction::triggered, [this]{ showNormalIfMinimized(); });
385388
connect(verifyMessageAction, &QAction::triggered, [this]{ gotoVerifyMessageTab(); });
386389
connect(usedSendingAddressesAction, &QAction::triggered, walletFrame, &WalletFrame::usedSendingAddresses);
@@ -459,6 +462,7 @@ void BitcoinGUI::createMenuBar()
459462
file->addAction(signMessageAction);
460463
file->addAction(verifyMessageAction);
461464
file->addAction(m_load_psbt_action);
465+
file->addAction(m_load_psbt_clipboard_action);
462466
file->addSeparator();
463467
}
464468
file->addAction(quitAction);
@@ -878,9 +882,9 @@ void BitcoinGUI::gotoVerifyMessageTab(QString addr)
878882
{
879883
if (walletFrame) walletFrame->gotoVerifyMessageTab(addr);
880884
}
881-
void BitcoinGUI::gotoLoadPSBT()
885+
void BitcoinGUI::gotoLoadPSBT(bool from_clipboard)
882886
{
883-
if (walletFrame) walletFrame->gotoLoadPSBT();
887+
if (walletFrame) walletFrame->gotoLoadPSBT(from_clipboard);
884888
}
885889
#endif // ENABLE_WALLET
886890

src/qt/bitcoingui.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ class BitcoinGUI : public QMainWindow
139139
QAction* signMessageAction = nullptr;
140140
QAction* verifyMessageAction = nullptr;
141141
QAction* m_load_psbt_action = nullptr;
142+
QAction* m_load_psbt_clipboard_action = nullptr;
142143
QAction* aboutAction = nullptr;
143144
QAction* receiveCoinsAction = nullptr;
144145
QAction* receiveCoinsMenuAction = nullptr;
@@ -278,8 +279,8 @@ public Q_SLOTS:
278279
void gotoSignMessageTab(QString addr = "");
279280
/** Show Sign/Verify Message dialog and switch to verify message tab */
280281
void gotoVerifyMessageTab(QString addr = "");
281-
/** Show load Partially Signed Bitcoin Transaction dialog */
282-
void gotoLoadPSBT();
282+
/** Load Partially Signed Bitcoin Transaction from file or clipboard */
283+
void gotoLoadPSBT(bool from_clipboard = false);
283284

284285
/** Show open dialog */
285286
void openClicked();

src/qt/walletframe.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,11 @@ void WalletFrame::gotoVerifyMessageTab(QString addr)
165165
walletView->gotoVerifyMessageTab(addr);
166166
}
167167

168-
void WalletFrame::gotoLoadPSBT()
168+
void WalletFrame::gotoLoadPSBT(bool from_clipboard)
169169
{
170170
WalletView *walletView = currentWalletView();
171171
if (walletView) {
172-
walletView->gotoLoadPSBT();
172+
walletView->gotoLoadPSBT(from_clipboard);
173173
}
174174
}
175175

src/qt/walletframe.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public Q_SLOTS:
7979
void gotoVerifyMessageTab(QString addr = "");
8080

8181
/** Load Partially Signed Bitcoin Transaction */
82-
void gotoLoadPSBT();
82+
void gotoLoadPSBT(bool from_clipboard = false);
8383

8484
/** Encrypt the wallet */
8585
void encryptWallet(bool status);

src/qt/walletview.cpp

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828

2929
#include <QAction>
3030
#include <QActionGroup>
31+
#include <QApplication>
32+
#include <QClipboard>
3133
#include <QFileDialog>
3234
#include <QHBoxLayout>
3335
#include <QProgressDialog>
@@ -205,23 +207,35 @@ void WalletView::gotoVerifyMessageTab(QString addr)
205207
signVerifyMessageDialog->setAddress_VM(addr);
206208
}
207209

208-
void WalletView::gotoLoadPSBT()
210+
void WalletView::gotoLoadPSBT(bool from_clipboard)
209211
{
210-
QString filename = GUIUtil::getOpenFileName(this,
211-
tr("Load Transaction Data"), QString(),
212-
tr("Partially Signed Transaction (*.psbt)"), nullptr);
213-
if (filename.isEmpty()) return;
214-
if (GetFileSize(filename.toLocal8Bit().data(), MAX_FILE_SIZE_PSBT) == MAX_FILE_SIZE_PSBT) {
215-
Q_EMIT message(tr("Error"), tr("PSBT file must be smaller than 100 MiB"), CClientUIInterface::MSG_ERROR);
216-
return;
212+
std::string data;
213+
214+
if (from_clipboard) {
215+
std::string raw = QApplication::clipboard()->text().toStdString();
216+
bool invalid;
217+
data = DecodeBase64(raw, &invalid);
218+
if (invalid) {
219+
Q_EMIT message(tr("Error"), tr("Unable to decode PSBT from clipboard (invalid base64)"), CClientUIInterface::MSG_ERROR);
220+
return;
221+
}
222+
} else {
223+
QString filename = GUIUtil::getOpenFileName(this,
224+
tr("Load Transaction Data"), QString(),
225+
tr("Partially Signed Transaction (*.psbt)"), nullptr);
226+
if (filename.isEmpty()) return;
227+
if (GetFileSize(filename.toLocal8Bit().data(), MAX_FILE_SIZE_PSBT) == MAX_FILE_SIZE_PSBT) {
228+
Q_EMIT message(tr("Error"), tr("PSBT file must be smaller than 100 MiB"), CClientUIInterface::MSG_ERROR);
229+
return;
230+
}
231+
std::ifstream in(filename.toLocal8Bit().data(), std::ios::binary);
232+
data = std::string(std::istreambuf_iterator<char>{in}, {});
217233
}
218-
std::ifstream in(filename.toLocal8Bit().data(), std::ios::binary);
219-
std::string data(std::istreambuf_iterator<char>{in}, {});
220234

221235
std::string error;
222236
PartiallySignedTransaction psbtx;
223237
if (!DecodeRawPSBT(psbtx, data, error)) {
224-
Q_EMIT message(tr("Error"), tr("Unable to decode PSBT file") + "\n" + QString::fromStdString(error), CClientUIInterface::MSG_ERROR);
238+
Q_EMIT message(tr("Error"), tr("Unable to decode PSBT") + "\n" + QString::fromStdString(error), CClientUIInterface::MSG_ERROR);
225239
return;
226240
}
227241

src/qt/walletview.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public Q_SLOTS:
8484
/** Show Sign/Verify Message dialog and switch to verify message tab */
8585
void gotoVerifyMessageTab(QString addr = "");
8686
/** Load Partially Signed Bitcoin Transaction */
87-
void gotoLoadPSBT();
87+
void gotoLoadPSBT(bool from_clipboard = false);
8888

8989
/** Show incoming transaction notification for new transactions.
9090

0 commit comments

Comments
 (0)