Class: Bitcoin::Message::Block
- Defined in:
- lib/bitcoin/message/block.rb
Overview
block message bitcoin.org/en/developer-reference#block
Constant Summary collapse
- COMMAND =
'block'
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 = [], use_segwit = false) ⇒ Block
constructor
A new instance of Block.
-
#to_block ⇒ Object
generate Bitcoin::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, #hkdf_sha256, #hmac_sha256, #pack_boolean, #pack_var_int, #pack_var_string, #padding_zero, #sha256, #tagged_hash, #unpack_boolean, #unpack_var_int, #unpack_var_int_from_io, #unpack_var_string, #valid_address?
Methods included from HexConverter
Constructor Details
#initialize(header, transactions = [], use_segwit = false) ⇒ Block
Returns a new instance of Block.
14 15 16 17 18 |
# File 'lib/bitcoin/message/block.rb', line 14 def initialize(header, transactions = [], use_segwit = false) @header = header @transactions = transactions @use_segwit = use_segwit end |
Instance Attribute Details
#header ⇒ Object
Returns the value of attribute header.
8 9 10 |
# File 'lib/bitcoin/message/block.rb', line 8 def header @header end |
#transactions ⇒ Object
Returns the value of attribute transactions.
9 10 11 |
# File 'lib/bitcoin/message/block.rb', line 9 def transactions @transactions end |
#use_segwit ⇒ Object
Returns the value of attribute use_segwit.
10 11 12 |
# File 'lib/bitcoin/message/block.rb', line 10 def use_segwit @use_segwit end |
Class Method Details
.parse_from_payload(payload) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/bitcoin/message/block.rb', line 20 def self.parse_from_payload(payload) buf = StringIO.new(payload) header = Bitcoin::BlockHeader.parse_from_payload(buf.read(80)) transactions = [] unless buf.eof? tx_count = Bitcoin.unpack_var_int_from_io(buf) tx_count.times do transactions << Bitcoin::Tx.parse_from_payload(buf) end end new(header, transactions) end |
Instance Method Details
#to_block ⇒ Object
generate Bitcoin::Block object.
39 40 41 |
# File 'lib/bitcoin/message/block.rb', line 39 def to_block Bitcoin::Block.new(header, transactions) end |
#to_payload ⇒ Object
33 34 35 36 |
# File 'lib/bitcoin/message/block.rb', line 33 def to_payload header.to_payload << Bitcoin.pack_var_int(transactions.size) << transactions.map{|t|use_segwit ? t.to_payload : t.serialize_old_format}.join end |