Class: Tapyrus::Message::Block
- Defined in:
- lib/tapyrus/message/block.rb
Overview
block message bitcoin.org/en/developer-reference#block
Constant Summary collapse
- COMMAND =
"block"
Constants included from Util
Instance Attribute Summary collapse
-
#header ⇒ Object
Returns the value of attribute header.
-
#transactions ⇒ Object
Returns the value of attribute transactions.
-
#use_segwit ⇒ Object
Returns the value of attribute use_segwit.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(header, transactions = []) ⇒ Block
constructor
A new instance of Block.
-
#to_block ⇒ Object
generate Tapyrus::Block object.
- #to_payload ⇒ Object
Methods inherited from Base
Methods included from Util
#byte_to_bit, #calc_checksum, #decode_base58_address, #double_sha256, #encode_base58_address, #hash160, #hmac_sha256, #pack_boolean, #pack_var_int, #pack_var_string, #padding_zero, #sha256, #unpack_boolean, #unpack_var_int, #unpack_var_int_from_io, #unpack_var_string, #valid_address?
Methods included from HexConverter
Constructor Details
#initialize(header, transactions = []) ⇒ Block
Returns a new instance of Block.
12 13 14 15 16 |
# File 'lib/tapyrus/message/block.rb', line 12 def initialize(header, transactions = []) @header = header @transactions = transactions @use_segwit = false end |
Instance Attribute Details
#header ⇒ Object
Returns the value of attribute header.
6 7 8 |
# File 'lib/tapyrus/message/block.rb', line 6 def header @header end |
#transactions ⇒ Object
Returns the value of attribute transactions.
7 8 9 |
# File 'lib/tapyrus/message/block.rb', line 7 def transactions @transactions end |
#use_segwit ⇒ Object
Returns the value of attribute use_segwit.
8 9 10 |
# File 'lib/tapyrus/message/block.rb', line 8 def use_segwit @use_segwit end |
Class Method Details
.parse_from_payload(payload) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/tapyrus/message/block.rb', line 18 def self.parse_from_payload(payload) buf = StringIO.new(payload) header = Tapyrus::BlockHeader.parse_from_payload(buf) transactions = [] unless buf.eof? tx_count = Tapyrus.unpack_var_int_from_io(buf) tx_count.times { transactions << Tapyrus::Tx.parse_from_payload(buf) } end new(header, transactions) end |
Instance Method Details
#to_block ⇒ Object
generate Tapyrus::Block object.
34 35 36 |
# File 'lib/tapyrus/message/block.rb', line 34 def to_block Tapyrus::Block.new(header, transactions) end |
#to_payload ⇒ Object
29 30 31 |
# File 'lib/tapyrus/message/block.rb', line 29 def to_payload header.to_payload << Tapyrus.pack_var_int(transactions.size) << transactions.map(&:to_payload).join end |