Inside Bitcoin
Opening the selected file…
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2009-2010 Satoshi Nakamoto2// Copyright (c) 2009-present The Bitcoin Core developers3// Distributed under the MIT software license, see the accompanying4// file COPYING or http://www.opensource.org/licenses/mit-license.php.6#ifndef BITCOIN_UNDO_H7#define BITCOIN_UNDO_H9#include <coins.h>10#include <compressor.h>11#include <consensus/consensus.h>12#include <primitives/transaction.h>13#include <serialize.h>15/** Formatter for undo information for a CTxIn16*17* Contains the prevout's CTxOut being spent, and its metadata as well18* (coinbase or not, height). The serialization contains a dummy value of19* zero. This is compatible with older versions which expect to see20* the transaction version there.21*/22struct TxInUndoFormatter23{24template<typename Stream>25void Ser(Stream &s, const Coin& txout) {26uint32_t nCode{(uint32_t{txout.nHeight} << 1) | uint32_t{txout.fCoinBase}};27::Serialize(s, VARINT(nCode));28if (txout.nHeight > 0) {29// Required to maintain compatibility with older undo format.30::Serialize(s, (unsigned char)0);31}32::Serialize(s, Using<TxOutCompression>(txout.out));33}35template<typename Stream>36void Unser(Stream &s, Coin& txout) {37uint32_t nCode = 0;38::Unserialize(s, VARINT(nCode));39txout.nHeight = nCode >> 1;40txout.fCoinBase = nCode & 1;41if (txout.nHeight > 0) {42// Old versions stored the version number for the last spend of43// a transaction's outputs. Non-final spends were indicated with44// height = 0.45unsigned int nVersionDummy;46::Unserialize(s, VARINT(nVersionDummy));47}48::Unserialize(s, Using<TxOutCompression>(txout.out));49}50};52/** Undo information for a CTransaction */53class CTxUndo54{55public:56// undo information for all txins57std::vector<Coin> vprevout;59SERIALIZE_METHODS(CTxUndo, obj) { READWRITE(Using<VectorFormatter<TxInUndoFormatter>>(obj.vprevout)); }60};62/** Undo information for a CBlock */63class CBlockUndo64{65public:66std::vector<CTxUndo> vtxundo; // for all but the coinbase68SERIALIZE_METHODS(CBlockUndo, obj) { READWRITE(obj.vtxundo); }69};71#endif // BITCOIN_UNDO_H