Skip to content
andrewschaaf edited this page Apr 16, 2011 · 16 revisions

This page should be concise.

A topic header should be linked to its own wiki page if and only if that page currently contains additional information.

{public,private} keys

Like base64, but without these characters: +/0O1l

Bitcoin address

def bitcoin_address(public_key):
  x = "\x00" + ripemd160(sha256(public_key))
  x += sha256(sha256(x))[0:4]
  return base58_encode(x)

Notation for the rest of this page

all integers are little-endian unless otherwise stated

{i,u}32       {signed,unsigned} 4-byte integer
(N)-byte      arbitrary bytes

var_str       (var_int(N)) + (N arbitrary bytes)

var_int = (N) ->
  uint8(N)          if N < 0xFD
  FD + uint16(N)    if N <= 0xFFFF
  FE + uint32(N)    if N <= 0xFFFFFFFF
  FF + uint64(N)    if N <= 0xFFFFFFFFFFFFFFFF

TX

BLOCK

i32         version
32-byte     next_hash
u32         file
u32         block_pos
i32         height
i32         version
32-byte     prev_hash
32-byte     merkle_root
i32         timestamp
i32         difficulty_bits
i32         nonce
-----------------------------
total: 128 bytes

Mining

boolean isValidBlock(bytes[] blockHeader, uint256 difficulty):
  return sha256(sha256(blockHeader)) <= difficulty

Overview of messages

Connection Messages

version:    version, start_height, ...
verack      // "ok"
ping:       // for testing the TCP connection -- no reply needed

P2P Messages

getaddr     // "please send me addr message(s)"
addr:       (timestamp, IP)-list
alert:      message, signature

Data messages

inv:        (type, hash)-list
getdata:    (type, hash)-list
getblocks:  (hash_start, hash_stop, ...)
tx:         (TX, ...)
block:      (BLOCK...)

...where type \in {TX, BLOCK, ERROR}