class Bitcoin::Message::Block
block message bitcoin.org/en/developer-reference#block
Constants
- COMMAND
Attributes
header[RW]
transactions[RW]
use_segwit[RW]
Public Class Methods
new(header, transactions = [], use_segwit = false)
click to toggle source
# File lib/bitcoin/message/block.rb, line 14 def initialize(header, transactions = [], use_segwit = false) @header = header @transactions = transactions @use_segwit = use_segwit end
parse_from_payload(payload)
click to toggle source
# 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
Public Instance Methods
to_block()
click to toggle source
generate Bitcoin::Block
object.
# File lib/bitcoin/message/block.rb, line 39 def to_block Bitcoin::Block.new(header, transactions) end
to_payload()
click to toggle source
# 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