Skip to content

Commit

Permalink
Use Elements PSBT magic when in Elements mode
Browse files Browse the repository at this point in the history
Elements PSBTs are incompatible with normal PSBTs due to differing transaction
formats, so use different magic bytes to distinguish.
  • Loading branch information
achow101 authored and instagibbs committed Oct 14, 2019
1 parent 8be2a9e commit f72e57a
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/psbt.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f72e57a

Please sign in to comment.