0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-09 10:43:19 -05:00

[gui] Load PSBT from clipboard

This commit is contained in:
Glenn Willen 2020-01-31 15:59:57 -08:00
parent a6cb0b0c29
commit 11a0ffb29d
6 changed files with 38 additions and 19 deletions

View file

@ -323,6 +323,8 @@ void BitcoinGUI::createActions()
verifyMessageAction->setStatusTip(tr("Verify messages to ensure they were signed with specified Bitcoin addresses")); verifyMessageAction->setStatusTip(tr("Verify messages to ensure they were signed with specified Bitcoin addresses"));
m_load_psbt_action = new QAction(tr("&Load PSBT from file..."), this); m_load_psbt_action = new QAction(tr("&Load PSBT from file..."), this);
m_load_psbt_action->setStatusTip(tr("Load Partially Signed Bitcoin Transaction")); m_load_psbt_action->setStatusTip(tr("Load Partially Signed Bitcoin Transaction"));
m_load_psbt_clipboard_action = new QAction(tr("Load PSBT from clipboard..."), this);
m_load_psbt_clipboard_action->setStatusTip(tr("Load Partially Signed Bitcoin Transaction from clipboard"));
openRPCConsoleAction = new QAction(tr("Node window"), this); openRPCConsoleAction = new QAction(tr("Node window"), this);
openRPCConsoleAction->setStatusTip(tr("Open node debugging and diagnostic console")); openRPCConsoleAction->setStatusTip(tr("Open node debugging and diagnostic console"));
@ -381,6 +383,7 @@ void BitcoinGUI::createActions()
connect(signMessageAction, &QAction::triggered, [this]{ showNormalIfMinimized(); }); connect(signMessageAction, &QAction::triggered, [this]{ showNormalIfMinimized(); });
connect(signMessageAction, &QAction::triggered, [this]{ gotoSignMessageTab(); }); connect(signMessageAction, &QAction::triggered, [this]{ gotoSignMessageTab(); });
connect(m_load_psbt_action, &QAction::triggered, [this]{ gotoLoadPSBT(); }); connect(m_load_psbt_action, &QAction::triggered, [this]{ gotoLoadPSBT(); });
connect(m_load_psbt_clipboard_action, &QAction::triggered, [this]{ gotoLoadPSBT(true); });
connect(verifyMessageAction, &QAction::triggered, [this]{ showNormalIfMinimized(); }); connect(verifyMessageAction, &QAction::triggered, [this]{ showNormalIfMinimized(); });
connect(verifyMessageAction, &QAction::triggered, [this]{ gotoVerifyMessageTab(); }); connect(verifyMessageAction, &QAction::triggered, [this]{ gotoVerifyMessageTab(); });
connect(usedSendingAddressesAction, &QAction::triggered, walletFrame, &WalletFrame::usedSendingAddresses); connect(usedSendingAddressesAction, &QAction::triggered, walletFrame, &WalletFrame::usedSendingAddresses);
@ -459,6 +462,7 @@ void BitcoinGUI::createMenuBar()
file->addAction(signMessageAction); file->addAction(signMessageAction);
file->addAction(verifyMessageAction); file->addAction(verifyMessageAction);
file->addAction(m_load_psbt_action); file->addAction(m_load_psbt_action);
file->addAction(m_load_psbt_clipboard_action);
file->addSeparator(); file->addSeparator();
} }
file->addAction(quitAction); file->addAction(quitAction);
@ -878,9 +882,9 @@ void BitcoinGUI::gotoVerifyMessageTab(QString addr)
{ {
if (walletFrame) walletFrame->gotoVerifyMessageTab(addr); if (walletFrame) walletFrame->gotoVerifyMessageTab(addr);
} }
void BitcoinGUI::gotoLoadPSBT() void BitcoinGUI::gotoLoadPSBT(bool from_clipboard)
{ {
if (walletFrame) walletFrame->gotoLoadPSBT(); if (walletFrame) walletFrame->gotoLoadPSBT(from_clipboard);
} }
#endif // ENABLE_WALLET #endif // ENABLE_WALLET

View file

@ -139,6 +139,7 @@ private:
QAction* signMessageAction = nullptr; QAction* signMessageAction = nullptr;
QAction* verifyMessageAction = nullptr; QAction* verifyMessageAction = nullptr;
QAction* m_load_psbt_action = nullptr; QAction* m_load_psbt_action = nullptr;
QAction* m_load_psbt_clipboard_action = nullptr;
QAction* aboutAction = nullptr; QAction* aboutAction = nullptr;
QAction* receiveCoinsAction = nullptr; QAction* receiveCoinsAction = nullptr;
QAction* receiveCoinsMenuAction = nullptr; QAction* receiveCoinsMenuAction = nullptr;
@ -278,8 +279,8 @@ public Q_SLOTS:
void gotoSignMessageTab(QString addr = ""); void gotoSignMessageTab(QString addr = "");
/** Show Sign/Verify Message dialog and switch to verify message tab */ /** Show Sign/Verify Message dialog and switch to verify message tab */
void gotoVerifyMessageTab(QString addr = ""); void gotoVerifyMessageTab(QString addr = "");
/** Show load Partially Signed Bitcoin Transaction dialog */ /** Load Partially Signed Bitcoin Transaction from file or clipboard */
void gotoLoadPSBT(); void gotoLoadPSBT(bool from_clipboard = false);
/** Show open dialog */ /** Show open dialog */
void openClicked(); void openClicked();

View file

@ -165,11 +165,11 @@ void WalletFrame::gotoVerifyMessageTab(QString addr)
walletView->gotoVerifyMessageTab(addr); walletView->gotoVerifyMessageTab(addr);
} }
void WalletFrame::gotoLoadPSBT() void WalletFrame::gotoLoadPSBT(bool from_clipboard)
{ {
WalletView *walletView = currentWalletView(); WalletView *walletView = currentWalletView();
if (walletView) { if (walletView) {
walletView->gotoLoadPSBT(); walletView->gotoLoadPSBT(from_clipboard);
} }
} }

View file

@ -79,7 +79,7 @@ public Q_SLOTS:
void gotoVerifyMessageTab(QString addr = ""); void gotoVerifyMessageTab(QString addr = "");
/** Load Partially Signed Bitcoin Transaction */ /** Load Partially Signed Bitcoin Transaction */
void gotoLoadPSBT(); void gotoLoadPSBT(bool from_clipboard = false);
/** Encrypt the wallet */ /** Encrypt the wallet */
void encryptWallet(bool status); void encryptWallet(bool status);

View file

@ -28,6 +28,8 @@
#include <QAction> #include <QAction>
#include <QActionGroup> #include <QActionGroup>
#include <QApplication>
#include <QClipboard>
#include <QFileDialog> #include <QFileDialog>
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QProgressDialog> #include <QProgressDialog>
@ -205,23 +207,35 @@ void WalletView::gotoVerifyMessageTab(QString addr)
signVerifyMessageDialog->setAddress_VM(addr); signVerifyMessageDialog->setAddress_VM(addr);
} }
void WalletView::gotoLoadPSBT() void WalletView::gotoLoadPSBT(bool from_clipboard)
{ {
QString filename = GUIUtil::getOpenFileName(this, std::string data;
tr("Load Transaction Data"), QString(),
tr("Partially Signed Transaction (*.psbt)"), nullptr); if (from_clipboard) {
if (filename.isEmpty()) return; std::string raw = QApplication::clipboard()->text().toStdString();
if (GetFileSize(filename.toLocal8Bit().data(), MAX_FILE_SIZE_PSBT) == MAX_FILE_SIZE_PSBT) { bool invalid;
Q_EMIT message(tr("Error"), tr("PSBT file must be smaller than 100 MiB"), CClientUIInterface::MSG_ERROR); data = DecodeBase64(raw, &invalid);
return; if (invalid) {
Q_EMIT message(tr("Error"), tr("Unable to decode PSBT from clipboard (invalid base64)"), CClientUIInterface::MSG_ERROR);
return;
}
} else {
QString filename = GUIUtil::getOpenFileName(this,
tr("Load Transaction Data"), QString(),
tr("Partially Signed Transaction (*.psbt)"), nullptr);
if (filename.isEmpty()) return;
if (GetFileSize(filename.toLocal8Bit().data(), MAX_FILE_SIZE_PSBT) == MAX_FILE_SIZE_PSBT) {
Q_EMIT message(tr("Error"), tr("PSBT file must be smaller than 100 MiB"), CClientUIInterface::MSG_ERROR);
return;
}
std::ifstream in(filename.toLocal8Bit().data(), std::ios::binary);
data = std::string(std::istreambuf_iterator<char>{in}, {});
} }
std::ifstream in(filename.toLocal8Bit().data(), std::ios::binary);
std::string data(std::istreambuf_iterator<char>{in}, {});
std::string error; std::string error;
PartiallySignedTransaction psbtx; PartiallySignedTransaction psbtx;
if (!DecodeRawPSBT(psbtx, data, error)) { if (!DecodeRawPSBT(psbtx, data, error)) {
Q_EMIT message(tr("Error"), tr("Unable to decode PSBT file") + "\n" + QString::fromStdString(error), CClientUIInterface::MSG_ERROR); Q_EMIT message(tr("Error"), tr("Unable to decode PSBT") + "\n" + QString::fromStdString(error), CClientUIInterface::MSG_ERROR);
return; return;
} }

View file

@ -84,7 +84,7 @@ public Q_SLOTS:
/** Show Sign/Verify Message dialog and switch to verify message tab */ /** Show Sign/Verify Message dialog and switch to verify message tab */
void gotoVerifyMessageTab(QString addr = ""); void gotoVerifyMessageTab(QString addr = "");
/** Load Partially Signed Bitcoin Transaction */ /** Load Partially Signed Bitcoin Transaction */
void gotoLoadPSBT(); void gotoLoadPSBT(bool from_clipboard = false);
/** Show incoming transaction notification for new transactions. /** Show incoming transaction notification for new transactions.