# Gavin Andresen # 2010-07-24 01:44:02 # https://bitcointalk.org/index.php?topic=555.msg5424#msg5424 They key bits of code are: @p{brk} Code: fileout @p{lt}@p{lt} FLATDATA(pchMessageStart) @p{lt}@p{lt} nSize; @p{brk} ... @p{brk} fileout @p{lt}@p{lt} *this; pchMessageStart are the four magic bytes, and those are written with FLATDATA. @p{par} The CBlock itself is written by @p{lt}@p{lt} *this, and that's done by the IMPLEMENT_SERIALIZE in main.h: @p{brk} Code: IMPLEMENT_SERIALIZE @p{brk} ( @p{brk} READWRITE(this-@s{gt}nVersion); @p{brk} nVersion = this-@s{gt}nVersion; @p{brk} READWRITE(hashPrevBlock); @p{brk} READWRITE(hashMerkleRoot); @p{brk} READWRITE(nTime); @p{brk} READWRITE(nBits); @p{brk} READWRITE(nNonce); @p{par} // ConnectBlock depends on vtx being last so it can calculate offset @p{brk} if (!(nType & (SER_GETHASH|SER_BLOCKHEADERONLY))) @p{brk} READWRITE(vtx); @p{brk} else if (fRead) @p{brk} const_cast@p{lt}CBlock*@s{gt}(this)-@s{gt}vtx.clear(); @p{brk} ) @p{brk} @p{brk} The READWRITE macros Do The Right Thing, reading in or writing out the members in a machine-independent way. @p{par} See @s{(link)} for simplified Python code that can dump out transactions and blocks. @p{par}