Class: Tapyrus::Message::BlockTransactionRequest
- Inherits:
-
Object
- Object
- Tapyrus::Message::BlockTransactionRequest
- Defined in:
- lib/tapyrus/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 Tapyrus::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.
9 10 11 12 |
# File 'lib/tapyrus/message/block_transaction_request.rb', line 9 def initialize(block_hash, indexes) @block_hash = block_hash @indexes = indexes end |
Instance Attribute Details
#block_hash ⇒ Object
When matching with Tapyrus::BlockHeader#hash It is necessary to reverse the byte order.
6 7 8 |
# File 'lib/tapyrus/message/block_transaction_request.rb', line 6 def block_hash @block_hash end |
#indexes ⇒ Object
Returns the value of attribute indexes.
7 8 9 |
# File 'lib/tapyrus/message/block_transaction_request.rb', line 7 def indexes @indexes end |
Class Method Details
.parse_from_payload(payload) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/tapyrus/message/block_transaction_request.rb', line 14 def self.parse_from_payload(payload) buf = StringIO.new(payload) block_hash = buf.read(32).bth index_len = Tapyrus.unpack_var_int_from_io(buf) indexes = index_len.times.map { Tapyrus.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
31 32 33 34 35 36 37 38 39 |
# File 'lib/tapyrus/message/block_transaction_request.rb', line 31 def to_payload p = block_hash.htb << Tapyrus.pack_var_int(indexes.size) indexes.size.times do |i| index = indexes[i] index -= indexes[i - 1] + 1 if i > 0 p << Tapyrus.pack_var_int(index) end p end |