class Bitcoin::Message::CmpctBlock

cmpctblock message github.com/bitcoin/bips/blob/master/bip-0152.mediawiki

Constants

COMMAND

Attributes

header_and_short_ids[RW]

Public Class Methods

from_block(block, version, nonce = SecureRandom.hex(8).to_i(16)) click to toggle source

generate CmpctBlock from Block data. @param [Bitcoin::Block] block the block to generate CmpctBlock. @param [Integer] version Compact Block version specified by sendcmpct message. @param [Integer] nonce @return [Bitcoin::Message::CmpctBlock]

# File lib/bitcoin/message/cmpct_block.rb, line 21
def self.from_block(block, version, nonce = SecureRandom.hex(8).to_i(16))
  raise 'Unsupported version.' unless [1, 2].include?(version)
  h = HeaderAndShortIDs.new(block.header, nonce)
  block.transactions[1..-1].each do |tx|
    h.short_ids << h.short_id(version == 1 ? tx.txid : tx.wtxid)
  end
  h.prefilled_txn << PrefilledTx.new(0, block.transactions.first)
  self.new(h)
end
new(header_and_short_ids) click to toggle source
# File lib/bitcoin/message/cmpct_block.rb, line 12
def initialize(header_and_short_ids)
  @header_and_short_ids = header_and_short_ids
end
parse_from_payload(payload) click to toggle source
# File lib/bitcoin/message/cmpct_block.rb, line 31
def self.parse_from_payload(payload)
  self.new(HeaderAndShortIDs.parse_from_payload(payload))
end

Public Instance Methods

to_payload() click to toggle source
# File lib/bitcoin/message/cmpct_block.rb, line 35
def to_payload
  header_and_short_ids.to_payload
end