Merge bitcoin-core/gui#469: Load Base64 PSBT string from file

2c3ee4c347 gui: Load Base64 PSBT string from file (Andrew Chow)

Pull request description:

  Some .psbt files may have the PSBT as a base64 string instead of in binary. We should be able to load those files.

ACKs for top commit:
  jarolrod:
    tACK 2c3ee4c347
  shaavan:
    ACK 2c3ee4c347

Tree-SHA512: 352b0611693c8989ea7d1b8d494ea58c69dc15cf81b8d62271541832e74b0a0399cb6ed4e686ab7c741cb4e5374527e054a9ecfe7355bc6f77d8fdd13569ab76
This commit is contained in:
Hennadii Stepanov 2022-07-15 21:11:39 +01:00
commit 6decdedaf9
No known key found for this signature in database
GPG Key ID: 410108112E7EA81F

View File

@ -213,6 +213,14 @@ void WalletFrame::gotoLoadPSBT(bool from_clipboard)
}
std::ifstream in{filename.toLocal8Bit().data(), std::ios::binary};
data.assign(std::istream_iterator<unsigned char>{in}, {});
// Some psbt files may be base64 strings in the file rather than binary data
std::string b64_str{data.begin(), data.end()};
b64_str.erase(b64_str.find_last_not_of(" \t\n\r\f\v") + 1); // Trim trailing whitespace
auto b64_dec = DecodeBase64(b64_str);
if (b64_dec.has_value()) {
data = b64_dec.value();
}
}
std::string error;