diff options
author | Glenn Willen <gwillen@nerdnet.org> | 2019-03-05 18:55:40 -0800 |
---|---|---|
committer | Glenn Willen <gwillen@nerdnet.org> | 2019-03-26 17:38:00 -0700 |
commit | afd20a25f2937fee8d992c279631fa26cde4a7c8 (patch) | |
tree | 38e654a027437a32296fd432b0fa6069624aace5 /src/psbt.cpp | |
parent | 8e1704c01537d1750555de23bfae00efa5864b3e (diff) |
Move PSBT decoding functions from core_io to psbt.cpp
Move PSBT decoding functions from core_io.h/core_read.cpp to psbt.h/psbt.cpp,
to deal with a linker issue.
Diffstat (limited to 'src/psbt.cpp')
-rw-r--r-- | src/psbt.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/psbt.cpp b/src/psbt.cpp index 0fb7d49d7d..734e7897ec 100644 --- a/src/psbt.cpp +++ b/src/psbt.cpp @@ -325,3 +325,30 @@ TransactionError CombinePSBTs(PartiallySignedTransaction& out, const std::vector return TransactionError::OK; } + +bool DecodeBase64PSBT(PartiallySignedTransaction& psbt, const std::string& base64_tx, std::string& error) +{ + 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()) { + error = "extra data after PSBT"; + return false; + } + } catch (const std::exception& e) { + error = e.what(); + return false; + } + return true; +} |