lib/bitcoin/network/command_client.rb in bitcoin-ruby-0.0.1 vs lib/bitcoin/network/command_client.rb in bitcoin-ruby-0.0.2
- old
+ new
@@ -1,5 +1,9 @@
+# encoding: ascii-8bit
+
+require 'json'
+
# Client to connect to CommandHandler and issue requests or register for events
class Bitcoin::Network::CommandClient < EM::Connection
# create new client connecting to +host+:+port+ and executing callbacks from +block+,
# passing +args+ in.
@@ -33,15 +37,11 @@
# call +disconnected+ callback and try to reconnect
def unbind
log.debug { "Disconnected." }
callback :disconnected
- if @connection_attempts > 1
- log.info { "Trying to start server..." }
- EM.defer { system("bin/bitcoin_node", "--quiet") }
- end
- EM.add_timer(1) do
+ EM.add_timer(@connection_attempts) do
@connection_attempts += 1
reconnect(@host, @port)
post_init
end
end
@@ -84,10 +84,11 @@
end
# register callbacks for monitor
def register_monitor_callbacks
on_monitor do |type, data|
- callback(type, *data)
+ type, *params = type.split("_")
+ callback(type, *((data || []) + (params || [])))
end
end
end