|
28 | 28 |
|
29 | 29 | #include <QAction> |
30 | 30 | #include <QActionGroup> |
| 31 | +#include <QApplication> |
| 32 | +#include <QClipboard> |
31 | 33 | #include <QFileDialog> |
32 | 34 | #include <QHBoxLayout> |
33 | 35 | #include <QProgressDialog> |
@@ -205,23 +207,35 @@ void WalletView::gotoVerifyMessageTab(QString addr) |
205 | 207 | signVerifyMessageDialog->setAddress_VM(addr); |
206 | 208 | } |
207 | 209 |
|
208 | | -void WalletView::gotoLoadPSBT() |
| 210 | +void WalletView::gotoLoadPSBT(bool from_clipboard) |
209 | 211 | { |
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}, {}); |
217 | 233 | } |
218 | | - std::ifstream in(filename.toLocal8Bit().data(), std::ios::binary); |
219 | | - std::string data(std::istreambuf_iterator<char>{in}, {}); |
220 | 234 |
|
221 | 235 | std::string error; |
222 | 236 | PartiallySignedTransaction psbtx; |
223 | 237 | 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); |
225 | 239 | return; |
226 | 240 | } |
227 | 241 |
|
|
0 commit comments