Class: Bitcoin::Message::BlockTransactionRequest
- Inherits:
-
Object
- Object
- Bitcoin::Message::BlockTransactionRequest
- Defined in:
- lib/bitcoin/message/block_transaction_request.rb
Overview
BIP-152 Compact Block’s data format. github.com/bitcoin/bips/blob/master/bip-0152.mediawiki#BlockTransactionsRequest
Instance Attribute Summary collapse
-
#block_hash ⇒ Object
When matching with Bitcoin::BlockHeader#hash It is necessary to reverse the byte order.
-
#indexes ⇒ Object
Returns the value of attribute indexes.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(block_hash, indexes) ⇒ BlockTransactionRequest
constructor
A new instance of BlockTransactionRequest.
- #to_payload ⇒ Object
Constructor Details
#initialize(block_hash, indexes) ⇒ BlockTransactionRequest
Returns a new instance of BlockTransactionRequest.
11 12 13 14 |
# File 'lib/bitcoin/message/block_transaction_request.rb', line 11 def initialize(block_hash, indexes) @block_hash = block_hash @indexes = indexes end |
Instance Attribute Details
#block_hash ⇒ Object
When matching with Bitcoin::BlockHeader#hash It is necessary to reverse the byte order.
8 9 10 |
# File 'lib/bitcoin/message/block_transaction_request.rb', line 8 def block_hash @block_hash end |
#indexes ⇒ Object
Returns the value of attribute indexes.
9 10 11 |
# File 'lib/bitcoin/message/block_transaction_request.rb', line 9 def indexes @indexes end |
Class Method Details
.parse_from_payload(payload) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/bitcoin/message/block_transaction_request.rb', line 16 def self.parse_from_payload(payload) buf = StringIO.new(payload) block_hash = buf.read(32).bth index_len = Bitcoin.unpack_var_int_from_io(buf) indexes = index_len.times.map{Bitcoin.unpack_var_int_from_io(buf)} # index data differentially encoded offset = 0 index_len.times do |i| index = indexes[i] index += offset indexes[i] = index offset = index + 1 end self.new(block_hash, indexes) end |
Instance Method Details
#to_payload ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/bitcoin/message/block_transaction_request.rb', line 32 def to_payload p = block_hash.htb << Bitcoin.pack_var_int(indexes.size) indexes.size.times do |i| index = indexes[i] index -= indexes[i-1] + 1 if i > 0 p << Bitcoin.pack_var_int(index) end p end |