lib/bitcoin/protocol.rb in bitcoin-ruby-0.0.7 vs lib/bitcoin/protocol.rb in bitcoin-ruby-0.0.8
- old
+ new
@@ -17,10 +17,11 @@
autoload :TxOut, 'bitcoin/protocol/txout'
autoload :Tx, 'bitcoin/protocol/tx'
autoload :Block, 'bitcoin/protocol/block'
autoload :Addr, 'bitcoin/protocol/address'
autoload :Alert, 'bitcoin/protocol/alert'
+ autoload :Reject, 'bitcoin/protocol/reject'
autoload :Version, 'bitcoin/protocol/version'
autoload :AuxPow, 'bitcoin/protocol/aux_pow'
autoload :Handler, 'bitcoin/protocol/handler'
autoload :Parser, 'bitcoin/protocol/parser'
@@ -70,18 +71,30 @@
def self.pack_var_string(payload)
pack_var_int(payload.bytesize) + payload
end
def self.unpack_var_string_array(payload) # unpacks set<string>
- size, payload = unpack_var_int(payload)
- return [nil, payload] if size == 0
- [(0...size).map{ s, payload = unpack_var_string(payload); s }, payload]
+ buf = StringIO.new(payload)
+ size = unpack_var_int_from_io(buf)
+ return [nil, buf.read] if size == 0
+ strings = []
+ size.times{
+ break if buf.eof?
+ strings << unpack_var_string_from_io(buf)
+ }
+ [strings, buf.read]
end
def self.unpack_var_int_array(payload) # unpacks set<int>
- size, payload = unpack_var_int(payload)
- return [nil, payload] if size == 0
- [(0...size).map{ i, payload = unpack_var_int(payload); i }, payload]
+ buf = StringIO.new(payload)
+ size = unpack_var_int_from_io(buf)
+ return [nil, buf.read] if size == 0
+ ints = []
+ size.times{
+ break if buf.eof?
+ ints << unpack_var_int_from_io(buf)
+ }
+ [ints, buf.read]
end
def self.unpack_boolean(payload)
bdata, payload = payload.unpack("Ca*")
[ (bdata == 0 ? false : true), payload ]