Expand description
Bitcoin P2P wire format serialization
Implements Bitcoin P2P protocol message framing: Format: [magic:4][command:12][length:4][checksum:4][payload:var]
- Magic bytes: Network identifier (mainnet, testnet, etc.)
- Command: 12-byte ASCII string (null-padded)
- Length: Payload length in bytes (little-endian u32)
- Checksum: First 4 bytes of double SHA256 of payload
- Payload: Message-specific data
Constants§
- MAX_
MESSAGE_ PAYLOAD - Maximum message payload size (32 MB)
- MESSAGE_
HEADER_ SIZE - Bitcoin P2P message header size (magic + command + length + checksum)
Functions§
- calculate_
checksum - Calculate checksum for message payload (first 4 bytes of double SHA256)
- deserialize_
addr - deserialize_
addrv2 - Deserialize AddrV2Message from Bitcoin wire format (BIP155)
- deserialize_
block - deserialize_
blocktxn - deserialize_
cmpctblock - deserialize_
feefilter - deserialize_
getblocks - deserialize_
getblocktxn - deserialize_
getdata - Deserialize GetDataMessage from Bitcoin wire format
- deserialize_
getheaders - Deserialize GetHeadersMessage from Bitcoin wire format
- deserialize_
headers - Deserialize HeadersMessage from Bitcoin wire format
- deserialize_
inv - Deserialize InvMessage from Bitcoin wire format
- deserialize_
message - Deserialize Bitcoin P2P wire format to network message
- deserialize_
notfound - Deserialize NotFoundMessage from Bitcoin wire format.
- deserialize_
ping - Deserialize PingMessage from Bitcoin wire format
- deserialize_
pong - Deserialize PongMessage from Bitcoin wire format
- deserialize_
reject - deserialize_
sendcmpct - deserialize_
tx - deserialize_
version - Deserialize VersionMessage from Bitcoin wire format
- serialize_
addr - Serialize AddrMessage to Bitcoin wire format (legacy addr) Format: CompactSize(count) + [timestamp(4) + services(8) + addr(16) + port(2)]*
- serialize_
addrv2 - Serialize AddrV2Message to Bitcoin wire format (BIP155) Format: CompactSize(count) + [time(4) + services(8) + address_type(1) + address(var) + port(2)]*
- serialize_
block - serialize_
blocktxn - BIP152: blocktxn - block_hash(32) + count(varint) + transactions
- serialize_
cmpctblock - BIP152: cmpctblock - header(80) + nonce(8) + shortids(varint+6*count) + prefilled(varint+each: diff_index+tx)
- serialize_
feefilter - Serialize FeeFilterMessage per BIP133: 8-byte feerate (LE)
- serialize_
getblocks - Serialize GetBlocksMessage - same structure as GetHeaders (version + locator + hash_stop)
- serialize_
getblocktxn - BIP152: getblocktxn - block_hash(32) + indexes(varint count + diff-encoded varints)
- serialize_
getdata - Serialize GetDataMessage to Bitcoin wire format Format: identical to Inv - count (varint) + count * (type u32 LE + hash 32 bytes)
- serialize_
getheaders - Serialize GetHeadersMessage to Bitcoin wire format Format: version (4 bytes LE) + hash_count (varint) + hashes (32 bytes each) + hash_stop (32 bytes)
- serialize_
headers - Serialize HeadersMessage to Bitcoin wire format Format: count (varint) + headers (each: 80 bytes header + varint tx_count which is always 0)
- serialize_
inv - Serialize InvMessage to Bitcoin wire format Format: count (varint) + count * (type u32 LE + hash 32 bytes)
- serialize_
message - Serialize a network message to Bitcoin P2P wire format
- serialize_
notfound - Serialize NotFoundMessage to Bitcoin wire format. Format: identical to Inv/GetData - count (varint) + count * (type u32 LE + hash 32 bytes)
- serialize_
ping - Serialize PingMessage to Bitcoin wire format (8-byte nonce)
- serialize_
pong - Serialize PongMessage to Bitcoin wire format (8-byte nonce)
- serialize_
reject - Serialize RejectMessage per BIP61: message(12) + ccode(1) + reason(var) + data(32 optional)
- serialize_
sendcmpct - BIP152: sendcmpct - 1 byte prefer_cmpct + 8 bytes version (LE)
- serialize_
tx - serialize_
version - Serialize VersionMessage to Bitcoin wire format Format per Bitcoin protocol specification: