lib/bitcoin/protocol.rb in bitcoin-ruby-0.0.18 vs lib/bitcoin/protocol.rb in bitcoin-ruby-0.0.19
- old
+ new
@@ -17,11 +17,10 @@
autoload :TxIn, 'bitcoin/protocol/txin'
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 :PartialMerkleTree, 'bitcoin/protocol/partial_merkle_tree'
@@ -60,11 +59,11 @@
end
end
def self.unpack_var_string(payload)
size, payload = unpack_var_int(payload)
- size > 0 ? (string, payload = payload.unpack("a#{size}a*")) : [nil, payload]
+ size > 0 ? (_, payload = payload.unpack("a#{size}a*")) : [nil, payload]
end
def self.unpack_var_string_from_io(buf)
size = unpack_var_int_from_io(buf)
size > 0 ? buf.read(size) : nil
@@ -112,10 +111,14 @@
def self.pkt(command, payload)
cmd = command.ljust(12, "\x00")[0...12]
length = [payload.bytesize].pack("V")
checksum = Digest::SHA256.digest(Digest::SHA256.digest(payload))[0...4]
pkt = "".force_encoding(BINARY)
- pkt << Bitcoin.network[:magic_head].force_encoding(BINARY) << cmd.force_encoding(BINARY) << length << checksum << payload.force_encoding(BINARY)
+ pkt << Bitcoin.network[:magic_head].force_encoding(BINARY)
+ pkt << cmd.force_encoding(BINARY)
+ pkt << length
+ pkt << checksum
+ pkt << payload.dup.force_encoding(BINARY)
end
def self.version_pkt(from_id, from=nil, to=nil, last_block=nil, time=nil, user_agent=nil, version=nil)
opts = if from_id.is_a?(Hash)
from_id