transaction: clarify witness branches
This commit is contained in:
parent
4831a16223
commit
e37b16a75c
1 changed files with 5 additions and 3 deletions
|
@ -290,6 +290,8 @@ struct CMutableTransaction;
|
||||||
*/
|
*/
|
||||||
template<typename Stream, typename Operation, typename TxType>
|
template<typename Stream, typename Operation, typename TxType>
|
||||||
inline void SerializeTransaction(TxType& tx, Stream& s, Operation ser_action, int nType, int nVersion) {
|
inline void SerializeTransaction(TxType& tx, Stream& s, Operation ser_action, int nType, int nVersion) {
|
||||||
|
const bool fAllowWitness = !(nVersion & SERIALIZE_TRANSACTION_NO_WITNESS);
|
||||||
|
|
||||||
READWRITE(*const_cast<int32_t*>(&tx.nVersion));
|
READWRITE(*const_cast<int32_t*>(&tx.nVersion));
|
||||||
unsigned char flags = 0;
|
unsigned char flags = 0;
|
||||||
if (ser_action.ForRead()) {
|
if (ser_action.ForRead()) {
|
||||||
|
@ -298,7 +300,7 @@ inline void SerializeTransaction(TxType& tx, Stream& s, Operation ser_action, in
|
||||||
const_cast<CTxWitness*>(&tx.wit)->SetNull();
|
const_cast<CTxWitness*>(&tx.wit)->SetNull();
|
||||||
/* Try to read the vin. In case the dummy is there, this will be read as an empty vector. */
|
/* Try to read the vin. In case the dummy is there, this will be read as an empty vector. */
|
||||||
READWRITE(*const_cast<std::vector<CTxIn>*>(&tx.vin));
|
READWRITE(*const_cast<std::vector<CTxIn>*>(&tx.vin));
|
||||||
if (tx.vin.size() == 0 && !(nVersion & SERIALIZE_TRANSACTION_NO_WITNESS)) {
|
if (tx.vin.size() == 0 && fAllowWitness) {
|
||||||
/* We read a dummy or an empty vin. */
|
/* We read a dummy or an empty vin. */
|
||||||
READWRITE(flags);
|
READWRITE(flags);
|
||||||
if (flags != 0) {
|
if (flags != 0) {
|
||||||
|
@ -309,7 +311,7 @@ inline void SerializeTransaction(TxType& tx, Stream& s, Operation ser_action, in
|
||||||
/* We read a non-empty vin. Assume a normal vout follows. */
|
/* We read a non-empty vin. Assume a normal vout follows. */
|
||||||
READWRITE(*const_cast<std::vector<CTxOut>*>(&tx.vout));
|
READWRITE(*const_cast<std::vector<CTxOut>*>(&tx.vout));
|
||||||
}
|
}
|
||||||
if ((flags & 1) && !(nVersion & SERIALIZE_TRANSACTION_NO_WITNESS)) {
|
if ((flags & 1) && fAllowWitness) {
|
||||||
/* The witness flag is present, and we support witnesses. */
|
/* The witness flag is present, and we support witnesses. */
|
||||||
flags ^= 1;
|
flags ^= 1;
|
||||||
const_cast<CTxWitness*>(&tx.wit)->vtxinwit.resize(tx.vin.size());
|
const_cast<CTxWitness*>(&tx.wit)->vtxinwit.resize(tx.vin.size());
|
||||||
|
@ -322,7 +324,7 @@ inline void SerializeTransaction(TxType& tx, Stream& s, Operation ser_action, in
|
||||||
} else {
|
} else {
|
||||||
// Consistency check
|
// Consistency check
|
||||||
assert(tx.wit.vtxinwit.size() <= tx.vin.size());
|
assert(tx.wit.vtxinwit.size() <= tx.vin.size());
|
||||||
if (!(nVersion & SERIALIZE_TRANSACTION_NO_WITNESS)) {
|
if (fAllowWitness) {
|
||||||
/* Check whether witnesses need to be serialized. */
|
/* Check whether witnesses need to be serialized. */
|
||||||
if (!tx.wit.IsNull()) {
|
if (!tx.wit.IsNull()) {
|
||||||
flags |= 1;
|
flags |= 1;
|
||||||
|
|
Loading…
Reference in a new issue