Use Elements PSBT magic when in Elements mode

Elements PSBTs are incompatible with normal PSBTs due to differing transaction
formats, so use different magic bytes to distinguish.
This commit is contained in:
Andrew Chow 2019-10-08 14:12:04 -04:00 committed by Gregory Sanders
parent 8be2a9e355
commit f72e57a3af

View file

@ -665,7 +665,11 @@ struct PartiallySignedTransaction
inline void Serialize(Stream& s) const {
// magic bytes
s << PSBT_MAGIC_BYTES;
if (g_con_elementsmode) {
s << PSBT_ELEMENTS_MAGIC_BYTES;
} else {
s << PSBT_MAGIC_BYTES;
}
// unsigned tx flag
SerializeToVector(s, PSBT_GLOBAL_UNSIGNED_TX);
@ -699,8 +703,14 @@ struct PartiallySignedTransaction
// Read the magic bytes
uint8_t magic[5];
s >> magic;
if (!std::equal(magic, magic + 5, PSBT_MAGIC_BYTES)) {
throw std::ios_base::failure("Invalid PSBT magic bytes");
if (g_con_elementsmode) {
if (!std::equal(magic, magic + 5, PSBT_ELEMENTS_MAGIC_BYTES)) {
throw std::ios_base::failure("Invalid PSBT magic bytes");
}
} else {
if (!std::equal(magic, magic + 5, PSBT_MAGIC_BYTES)) {
throw std::ios_base::failure("Invalid PSBT magic bytes");
}
}
// Read global data