Skip to content

Instantly share code, notes, and snippets.

@andrewschaaf
Created March 19, 2011 16:56
Show Gist options
  • Save andrewschaaf/877610 to your computer and use it in GitHub Desktop.
Save andrewschaaf/877610 to your computer and use it in GitHub Desktop.

[[Stuff]]


[[Messages]]


Terms

{i,u}32       {signed,unsigned} 4-byte integer, little endian
(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

Connection Messages

version:    version, start_height, ...
verack

ping
  To confirm that the TCP/IP connection is still valid
  No reply is expected

P2P Messages

getaddr
  request addr message(s)

addr:       (timestamp, IP)-list

alert:      message, signature

Data messages

type: TX, BLOCK, ERROR (error: ignore this item) (should probably only be heeded for not-yet-filled INV )

inv:        (type, 4-byte hash)-list
getdata:    (type, 4-byte hash)-list
getblocks:  (hash_start, hash_stop, ...)

tx:         (TX, ...)
block:      (BLOCK...)

Mining

  • Difficulty adjusted every 2016 blocks
uint256 hashTarget = f(difficulty)
uint256 hash = sha256(sha256( headerData ))
if (hash <= hashTarget) {
  // yay!
}

Other docs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment