class Tapyrus::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 = []) click to toggle source
# File lib/tapyrus/message/block.rb, line 12
def initialize(header, transactions = [])
  @header = header
  @transactions = transactions
  @use_segwit = false
end
parse_from_payload(payload) click to toggle source
# 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

Public Instance Methods

to_block() click to toggle source

generate Tapyrus::Block object.

# File lib/tapyrus/message/block.rb, line 34
def to_block
  Tapyrus::Block.new(header, transactions)
end
to_payload() click to toggle source
# 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