Sha256: f90dab79e7da7e2a87bdea778549dc0943cf8b9959f94b30ba3ec554ace7b10d

Contents?: true

Size: 651 Bytes

Versions: 8

Compression:

Stored size: 651 Bytes

Contents

module Bitcoin
  module Message

    # Common message parser which handle multiple block headers as a payload.
    module HeadersParser

      def parse_from_payload(payload)
        ver, payload = payload.unpack('Va*')
        size, payload = Bitcoin.unpack_var_int(payload)
        hashes = []
        buf = StringIO.new(payload)
        size.times do
          hashes << buf.read(32).reverse.bth
        end
        new(ver, hashes, buf.read(32).reverse.bth)
      end

      def to_payload
        [version].pack('V') << Bitcoin.pack_var_int(hashes.length) << hashes.map{|h|h.htb.reverse}.join << stop_hash.htb.reverse
      end

    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
bitcoinrb-0.1.7 lib/bitcoin/message/headers_parser.rb
bitcoinrb-0.1.6 lib/bitcoin/message/headers_parser.rb
bitcoinrb-0.1.5 lib/bitcoin/message/headers_parser.rb
bitcoinrb-0.1.4 lib/bitcoin/message/headers_parser.rb
bitcoinrb-0.1.3 lib/bitcoin/message/headers_parser.rb
bitcoinrb-0.1.2 lib/bitcoin/message/headers_parser.rb
bitcoinrb-0.1.1 lib/bitcoin/message/headers_parser.rb
bitcoinrb-0.0.1 lib/bitcoin/message/headers_parser.rb