lib/bitcoin/connection.rb in bitcoin-ruby-0.0.1 vs lib/bitcoin/connection.rb in bitcoin-ruby-0.0.2
- old
+ new
@@ -1,33 +1,32 @@
+# encoding: ascii-8bit
+
require 'socket'
require 'eventmachine'
require 'bitcoin'
module Bitcoin
module ConnectionHandler
- def hth(h); h.unpack("H*")[0]; end
- def htb(h); [h].pack("H*"); end
-
def on_inv_transaction(hash)
- p ['inv transaction', hth(hash)]
+ p ['inv transaction', hash.hth]
pkt = Protocol.getdata_pkt(:tx, [hash])
send_data(pkt)
end
def on_inv_block(hash)
- p ['inv block', hth(hash)]
+ p ['inv block', hash.hth]
pkt = Protocol.getdata_pkt(:block, [hash])
send_data(pkt)
end
def on_get_transaction(hash)
- p ['get transaction', hth(hash)]
+ p ['get transaction', hash.hth]
end
def on_get_block(hash)
- p ['get block', hth(hash)]
+ p ['get block', hash.hth]
end
def on_addr(addr)
p ['addr', addr, addr.alive?]
end
@@ -41,11 +40,15 @@
#p block.payload.each_byte.map{|i| "%02x" % [i] }.join(" ")
#puts block.to_json
end
def on_version(version)
- p [@sockaddr, 'version', version, version.timestamp - Time.now.to_i]
+ p [@sockaddr, 'version', version, version.time - Time.now.to_i]
send_data( Protocol.verack_pkt )
+ end
+
+ def on_verack
+ on_handshake_complete
end
def on_handshake_complete
p [@sockaddr, 'handshake complete']
@connected = true