user24926: I'd like to learn how segregated witness works, and I thought the raw transaction data would be a good place to start
If this is the structure of current transactions:
version | [inputcount] {[txid] [vin] [signature] [sequence]} | [outputcount] {value} {varint} {lockingscript} | [locktime]

What does a segregated witness transaction look like?

user208: From Bitcoin Core's primitive/transaction.h:
/**
 * Basic transaction serialization format:
 * - int32_t nVersion
 * - std::vector<CTxIn> vin
 * - std::vector<CTxOut> vout
 * - uint32_t nLockTime
 *
 * Extended transaction serialization format:
 * - int32_t nVersion
 * - unsigned char dummy = 0x00
 * - unsigned char flags (!= 0)
 * - std::vector<CTxIn> vin
 * - std::vector<CTxOut> vout
 * - if (flags & 1):
 *   - CTxWitness wit;
 * - uint32_t nLockTime
 */

In other words, before the txin count, there is a 0x00 0x01 sequence (which would otherwise be interpreted as a transaction with 0 inputs and 1 output, which cannot be valid), and before the locktime there is a witness record for each input (the txin count is not repeated, it's implicitly assumed to be equal to the txin count given before).

24926: <p>I'd like to learn how <strong>segregated witness</strong> works, and I thought the <em>raw transaction data</em> would be a good place to start</p>

<p>If this is the structure of current transactions:</p>

<pre><code>version | [inputcount] {[txid] [vin] [signature] [sequence]} | [outputcount] {value} {varint} {lockingscript} | [locktime]
</code></pre>

<p>What does a segregated witness transaction look like?</p>
 208: <p>From Bitcoin Core's <a href="https://github.com/bitcoin/bitcoin/blob/v0.13.1rc2/src/primitives/transaction.h#L275" rel="noreferrer">primitive/transaction.h</a>:</p>

<pre><code>/**
 * Basic transaction serialization format:
 * - int32_t nVersion
 * - std::vector&lt;CTxIn&gt; vin
 * - std::vector&lt;CTxOut&gt; vout
 * - uint32_t nLockTime
 *
 * Extended transaction serialization format:
 * - int32_t nVersion
 * - unsigned char dummy = 0x00
 * - unsigned char flags (!= 0)
 * - std::vector&lt;CTxIn&gt; vin
 * - std::vector&lt;CTxOut&gt; vout
 * - if (flags &amp; 1):
 *   - CTxWitness wit;
 * - uint32_t nLockTime
 */
</code></pre>

<p>In other words, before the txin count, there is a <code>0x00 0x01</code> sequence (which would otherwise be interpreted as a transaction with 0 inputs and 1 output, which cannot be valid), and before the locktime there is a witness record for each input (the txin count is not repeated, it's implicitly assumed to be equal to the txin count given before).</p>
