bin/bitcoin_node in bitcoin-ruby-0.0.1 vs bin/bitcoin_node in bitcoin-ruby-0.0.2

- old
+ new

@@ -1,42 +1,15 @@ #!/usr/bin/env ruby $:.unshift( File.expand_path("../../lib", __FILE__) ) require 'bitcoin' require 'optparse' +require 'fileutils' Bitcoin.require_dependency :eventmachine Bitcoin.require_dependency :json -defaults = { - :network => "bitcoin", - :command => "127.0.0.1:9999", - :listen => "0.0.0.0:8332", - :connect => "", - :storage => "sequel::sqlite://bitcoin.db", - :headers_only => false, - :dns => true, - :epoll => false, - :epoll_limit => 10000, - :epoll_user => nil, - :log => { - :network => :info, - :storage => :info, - }, - :max => { - :connections => 32, - :addr => 1024, - :queue => 500, - :inv => 500, - }, - :intervals => { - :queue => 5, - :inv_queue => 5, - :addrs => 15, - :connect => 30, - }, - :daemon => false, -} +defaults = Bitcoin::Network::Node::DEFAULT_CONFIG options = Bitcoin::Config.load(defaults, :blockchain) optparse = OptionParser.new do |opts| opts.banner = "Usage: bitcoin_node [options]" @@ -52,29 +25,40 @@ "User Network (default: #{options[:network]})") do |network| options[:network] = network end opts.on("--command [HOST:PORT]", - "Command socket (default: #{options[:command]})") do |command| - options[:command] = command + "Command socket (default: #{options[:command].join(':')})") do |command| + options[:command] = command.split(":") end opts.on("-l", "--listen [HOST:PORT]", - "Listen address/port (default: #{options[:listen]})") do |listen| - options[:listen] = listen + "Listen address/port (default: #{options[:listen].join(':')})") do |listen| + options[:listen] = listen.split(":") end - opts.on("--connect [HOST:PORT[,HOST:PORT[...]]]", - "Hosts to connect to (default: #{options[:connect]})") do |connect| - options[:connect] = connect + opts.on("--connect [HOST:PORT]", + "Hosts to connect to (default: #{options[:connect].map{|c|c.join(':')}.join(',')})") do |connect| + connect.split(",").each do |host| + options[:connect] << host.split(":") + end end opts.on("-s", "--storage [BACKEND::CONFIG]", "Use storage backend (default: #{options[:storage]})") do |storage| options[:storage] = storage end + opts.on("--skip-validation", "Skip validation of blocks and transactions") do + options[:skip_validation] = true + end + + opts.on("--check-blocks COUNT", + "Check consistency of COUNT latest blocks; -1 for all (default: 1000)") do |check| + options[:check_blocks] = check.to_i + end + opts.on("--ho", "--headers-only", "Download only block headers") do options[:headers_only] = true end @@ -98,11 +82,19 @@ opts.on("--epoll-user [NAME]", "Set effective user after increasing socket descriptor limit") do |user| options[:epoll_user] = user end - [:connections, :addr, :queue, :inv].each do |name| + opts.on("--mco", "--max-connections-out COUNT", "Maximum number of outgoing connections (default: #{options[:max][:connections_out]})") do |count| + options[:max][:connections_out] = count.to_i + end + + opts.on("--mci", "--max-connections-in COUNT", "Maximum number of incoming connections (default: #{options[:max][:connections_in]})") do |count| + options[:max][:connections_in] = count.to_i + end + + [:addr, :queue, :inv, :unconfirmed].each do |name| opts.on("--m#{name.to_s[0]}", "--max-#{name} [COUNT]", "Max #{name} (default: #{options[:max][name]})") do |count| options[:max][name] = count.to_i end end @@ -119,10 +111,14 @@ "Log level for #{name} (default: #{options[:log][name]})") do |level| options[:log][name] = level.to_sym end end + opts.on("--import DIR", "Import blk*.dat files from DIR") do |dir| + options[:import] = dir + end + opts.on("-v", "--verbose", "Set all loggers to debug") do options[:log].each_key {|k| options[:log][k] = :debug } end opts.on("-q", "--quiet", "Set all loggers to warn") do @@ -135,13 +131,11 @@ end optparse.parse! Bitcoin.network = options[:network] -options[:command] = options[:command] == "" ? nil : options[:command].split(':') -options[:listen] = options[:listen] == "" ? nil : options[:listen].split(':') -options[:connect] = options[:connect] == "" ? [] : options[:connect].split(',').map{|h| h.split(':')} +FileUtils.mkdir_p File.join(ENV['HOME'], ".bitcoin-ruby/#{Bitcoin.network_name}") if ARGV.any? EM.run do Bitcoin::Network::CommandClient.connect(*options[:command]) do on_response do |cmd, data| @@ -151,11 +145,14 @@ end end on_block do |block, depth| puts "block: #{block['hash']} (#{depth})" end - on_tx do |tx| - puts "tx: #{tx['hash']}" + on_tx do |tx, confirmations| + puts "tx(#{confirmations}): #{tx['hash']}" + end + on_output do |tx_hash, address, value, confirmations| + puts "output(#{confirmations}): tx #{tx_hash[0..8]}: #{address} received #{value.to_f / 1e8} BTC" end on_connection do |type, host| if type == "connected" puts "Connected: #{host['host']}:#{host['port']}" else