| 371 | */ |
| 372 | template<typename Stream, typename TxType> |
| 373 | inline void UnserializeTransaction(TxType& tx, Stream& s) { |
| 374 | |
| 375 | s >> tx.nVersion; |
| 376 | unsigned char flags = 0; |
| 377 | tx.vin.clear(); |
| 378 | tx.vout.clear(); |
| 379 | tx.witness.SetNull(); |
| 380 | |
| 381 | // Witness serialization is different between Elements and Core. |
| 382 | // See code comments in SerializeTransaction for details about the differences. |
| 383 | if (g_con_elementsmode) { |
| 384 | s >> flags; |
| 385 | s >> tx.vin; |
| 386 | s >> tx.vout; |
| 387 | s >> tx.nLockTime; |
| 388 | if (flags & 1) { |
| 389 | /* The witness flag is present. */ |
| 390 | flags ^= 1; |
| 391 | tx.witness.vtxinwit.resize(tx.vin.size()); |
| 392 | tx.witness.vtxoutwit.resize(tx.vout.size()); |
| 393 | s >> tx.witness; |
| 394 | if (!tx.HasWitness()) { |
| 395 | /* It's illegal to encode witnesses when all witness stacks are empty. */ |
| 396 | throw std::ios_base::failure("Superfluous witness record"); |
| 397 | } |
| 398 | } |
| 399 | } else { |
| 400 | const bool fAllowWitness = !(s.GetVersion() & SERIALIZE_TRANSACTION_NO_WITNESS); |
| 401 | |
| 402 | /* Try to read the vin. In case the dummy is there, this will be read as an empty vector. */ |
| 403 | s >> tx.vin; |
| 404 | if (tx.vin.size() == 0 && fAllowWitness) { |
| 405 | /* We read a dummy or an empty vin. */ |
| 406 | s >> flags; |
| 407 | if (flags != 0) { |
| 408 | s >> tx.vin; |
| 409 | s >> tx.vout; |
| 410 | } |
| 411 | } else { |
| 412 | /* We read a non-empty vin. Assume a normal vout follows. */ |
| 413 | s >> tx.vout; |
| 414 | } |
| 415 | |
| 416 | if ((flags & 1) && fAllowWitness) { |
| 417 | /* The witness flag is present. */ |
| 418 | flags ^= 1; |
| 419 | tx.witness.vtxinwit.resize(tx.vin.size()); |
| 420 | tx.witness.vtxoutwit.resize(tx.vout.size()); |
| 421 | for (size_t i = 0; i < tx.vin.size(); i++) { |
| 422 | s >> tx.witness.vtxinwit[i].scriptWitness.stack; |
| 423 | // ELEMENTS: |
| 424 | if (tx.vin[i].m_is_pegin) { |
| 425 | s >> tx.witness.vtxinwit[i].m_pegin_witness.stack; |
| 426 | } |
| 427 | } |
| 428 | |
| 429 | if (!tx.HasWitness()) { |
| 430 | /* It's illegal to encode witnesses when all witness stacks are empty. */ |
no test coverage detected