aboutsummaryrefslogtreecommitdiff
path: root/src/core_read.cpp
diff options
context:
space:
mode:
authorGlenn Willen <gwillen@nerdnet.org>2019-01-29 21:32:38 -0800
committerGlenn Willen <gwillen@nerdnet.org>2019-02-11 12:23:14 -0800
commitc734aaa15d924470cec0f17b00ad2e47472b471f (patch)
tree57a374ce9179e44ba453c2d48014b5375268f965 /src/core_read.cpp
parent162ffefd2f562169725559906601c25c579aa91c (diff)
downloadbitcoin-c734aaa15d924470cec0f17b00ad2e47472b471f.tar.xz
Split DecodePSBT into Base64 and Raw versions
Split up DecodePSBT, which both decodes base64 and then deserializes a PartiallySignedTransaction, into two functions: DecodeBase64PSBT, which retains the old behavior, and DecodeRawPSBT, which only performs the deserialization. Add a test for base64 decoding failure.
Diffstat (limited to 'src/core_read.cpp')
-rw-r--r--src/core_read.cpp16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/core_read.cpp b/src/core_read.cpp
index 3b82b2853c..0379098712 100644
--- a/src/core_read.cpp
+++ b/src/core_read.cpp
@@ -176,10 +176,20 @@ bool DecodeHexBlk(CBlock& block, const std::string& strHexBlk)
return true;
}
-bool DecodePSBT(PartiallySignedTransaction& psbt, const std::string& base64_tx, std::string& error)
+bool DecodeBase64PSBT(PartiallySignedTransaction& psbt, const std::string& base64_tx, std::string& error)
{
- std::vector<unsigned char> tx_data = DecodeBase64(base64_tx.c_str());
- CDataStream ss_data(tx_data, SER_NETWORK, PROTOCOL_VERSION);
+ bool invalid;
+ std::string tx_data = DecodeBase64(base64_tx, &invalid);
+ if (invalid) {
+ error = "invalid base64";
+ return false;
+ }
+ return DecodeRawPSBT(psbt, tx_data, error);
+}
+
+bool DecodeRawPSBT(PartiallySignedTransaction& psbt, const std::string& tx_data, std::string& error)
+{
+ CDataStream ss_data(tx_data.data(), tx_data.data() + tx_data.size(), SER_NETWORK, PROTOCOL_VERSION);
try {
ss_data >> psbt;
if (!ss_data.empty()) {