Skip to content

Instantly share code, notes, and snippets.

@altamic
Created February 1, 2011 22:50
Show Gist options
  • Save altamic/806899 to your computer and use it in GitHub Desktop.
Save altamic/806899 to your computer and use it in GitHub Desktop.
# lib/bitcoin/protocol/configuration.rb
Bitcoin::Protocol.configure do
register_constant :MAGIC, :production => [0xf9, 0xbe, 0xb4, 0xd9],
:test => [0xfa, 0xbf, 0xb5, 0xda]
register_constant :VERSION, 318
register_constant :SUB_VERSION, '.1'
register_constant :SERVICES, { :node_network => 1 }
register_constant :MESSAGE_SIZE_LIMIT, 50_000
#register_type??
#TODO: implement address, string
register_message :version do |m|
m.uint32_little :version, :default => VERSION
m.uint64_little :services, :default => SERVICES[:node_network]
m.int64_little :time, :default => Proc.new { Time.now.to_i }
m.address :origin, :default => Proc.new { nil }
m.address :destination
m.int64_little :nonce, :default => Proc.new { rand(2**64) }
m.string :sub_version, :default => SUB_VERSION
m.int32_little :starting_height, :default => nil
end
register_message :verack, :alias => :version_ack
#TODO: implement address_collection
register_message :addr, :alias => :addresses, :size_limit => 1000 do |m|
m.addresses_sequence :addresses
end
# An inv message is sent to peers when a node successfully creates a block
# as a result of:
#
# b) transaction is initiated by a user,
# a) mining activity
#
# Having a list of vectors larger than 50,000 bytes is considered to be an
# error condition and the packet is ignored.
register_message :inv, :alias => :inventory, :size_limit => true do |m|
m.variable_size :items_count
m.inventory_sequence :items
end
register_message :getdata, :alias => :get_data, :size_limit => true
register_message :getblocks, :alias => :get_blocks
register_message :tx, :alias => :transactions
register_message :block
register_message :getaddr, :alias => :get_addresses
register_message :checkorder, :alias => :check_order
register_message :submitorder, :alias => :submit_order
register_message :reply
register_message :ping
register_message :alert
register_sequence :initialize, :request => :version, :response => :verack
register_sequence :identificate_peer, :request => :getaddr, :response => :addr
register_sequence :bootstrap_blocks, :request => :getblocks, :response => :inv
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment