diff options
author | laanwj <126646+laanwj@users.noreply.github.com> | 2022-04-27 15:48:02 +0200 |
---|---|---|
committer | laanwj <126646+laanwj@users.noreply.github.com> | 2022-04-27 17:18:54 +0200 |
commit | 132d5f8c2f2397a4600a42203f413dafdb6bcc37 (patch) | |
tree | a71de46fa5bf3910b5705f7f884de63a5a7c354a /src/qt | |
parent | 0b8e2868f5cb7efb4679da948660f22645a9248e (diff) | |
parent | fa7078d84fc2858a466bc1a85404f821df682538 (diff) | |
download | bitcoin-132d5f8c2f2397a4600a42203f413dafdb6bcc37.tar.xz |
Merge bitcoin/bitcoin#25001: Modernize util/strencodings and util/string: `string_view` and `optional`
fa7078d84fc2858a466bc1a85404f821df682538 scripted-diff: Rename ValidAsCString to ContainsNoNUL (MacroFake)
e7d2fbda63c346ae88767c3f8d4db3edeae2dc0b Use std::string_view throughout util strencodings/string (Pieter Wuille)
8ffbd1412d887535ce5eb613884858c319bd12be Make DecodeBase{32,64} take string_view arguments (Pieter Wuille)
1a72d62152bfdd7c5c2b2704b679f894e7d35e37 Generalize ConvertBits to permit transforming the input (Pieter Wuille)
78f3ac51b7d073d12da6a3b9b7d80d91e04ce3a7 Make DecodeBase{32,64} return optional instead of taking bool* (Pieter Wuille)
a65931e3ce66d87b8f83d67ecdbb46f137e6a670 Make DecodeBase{32,64} always return vector, not string (Pieter Wuille)
a4377a0843636eae0aaf698510fc6518582545db Reject incorrect base64 in HTTP auth (Pieter Wuille)
d648b5120b2fefa9e599898bd26f05ecf4428fac Make SanitizeString use string_view (Pieter Wuille)
963bc9b576f0a62caffede2ce32830aef3473995 Make IsHexNumber use string_view (Pieter Wuille)
40062997f223d88d4f92aaae4622a31476686163 Make IsHex use string_view (Pieter Wuille)
c1d165a8c2678c31aced5e1d46231d9996b0774a Make ParseHex use string_view (Pieter Wuille)
Pull request description:
Make use of `std::string_view` and `std::optional` in the util/{strencodings, string} files.
This avoids many temporary string/vector objects being created, while making the interface easier to read. Changes include:
* Make all input arguments in functions in util/strencodings and util/string take `std::string_view` instead of `std::string`.
* Add `RemovePrefixView` and `TrimStringView` which also *return* `std::string_view` objects (the corresponding `RemovePrefix` and `TrimString` keep returning an `std::string`, as that's needed in many call sites still).
* Stop returning `std::string` from `DecodeBase32` and `DecodeBase64`, but return vectors. Base32/64 are fundamentally algorithms for encoding bytes as strings; returning `std::string` from those (especially doing it conditionally based on the input arguments/types) is just bizarre.
* Stop taking a `bool* pf_invalid` output argument pointer in `DecodeBase32` and `DecodeBase64`; return an `std::optional` instead.
* Make `DecodeBase32` and `DecodeBase64` more efficient by doing the conversion from characters to integer symbols on-the-fly rather than through a temporary vector.
ACKs for top commit:
MarcoFalke:
re-ACK fa7078d84fc2858a466bc1a85404f821df682538 only change is rebase and adding a scripted-diff 🍲
martinus:
Code review ACK fa7078d84fc2858a466bc1a85404f821df682538, found no issue
laanwj:
Code review ACK fa7078d84fc2858a466bc1a85404f821df682538
sipa:
utACK fa7078d84fc2858a466bc1a85404f821df682538 (as far as the commit that isn't mine goes)
Tree-SHA512: 5cf02e541caef0bcd100466747664bdb828a68a05dae568cbcd0632a53dd3a4c4e85cd8c48ebbd168d4247d5c9666689c16005f1c8ad75b0f057d8683931f664
Diffstat (limited to 'src/qt')
-rw-r--r-- | src/qt/walletframe.cpp | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/qt/walletframe.cpp b/src/qt/walletframe.cpp index 91ce420a33..dc4e25a02b 100644 --- a/src/qt/walletframe.cpp +++ b/src/qt/walletframe.cpp @@ -194,16 +194,16 @@ void WalletFrame::gotoVerifyMessageTab(QString addr) void WalletFrame::gotoLoadPSBT(bool from_clipboard) { - std::string data; + std::vector<unsigned char> data; if (from_clipboard) { std::string raw = QApplication::clipboard()->text().toStdString(); - bool invalid; - data = DecodeBase64(raw, &invalid); - if (invalid) { + auto result = DecodeBase64(raw); + if (!result) { Q_EMIT message(tr("Error"), tr("Unable to decode PSBT from clipboard (invalid base64)"), CClientUIInterface::MSG_ERROR); return; } + data = std::move(*result); } else { QString filename = GUIUtil::getOpenFileName(this, tr("Load Transaction Data"), QString(), @@ -214,12 +214,12 @@ void WalletFrame::gotoLoadPSBT(bool from_clipboard) return; } std::ifstream in{filename.toLocal8Bit().data(), std::ios::binary}; - data = std::string(std::istreambuf_iterator<char>{in}, {}); + data.assign(std::istream_iterator<unsigned char>{in}, {}); } std::string error; PartiallySignedTransaction psbtx; - if (!DecodeRawPSBT(psbtx, data, error)) { + if (!DecodeRawPSBT(psbtx, MakeByteSpan(data), error)) { Q_EMIT message(tr("Error"), tr("Unable to decode PSBT") + "\n" + QString::fromStdString(error), CClientUIInterface::MSG_ERROR); return; } |