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.
This commit is contained in:
Glenn Willen
2019-03-05 18:55:40 -08:00
parent 8e1704c015
commit afd20a25f2
5 changed files with 33 additions and 35 deletions

View File

@@ -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;
}