Class: Tapyrus::Message::CmpctBlock

Inherits:
Base
  • Object
show all
Defined in:
lib/tapyrus/message/cmpct_block.rb

Overview

cmpctblock message. support only version 1. github.com/bitcoin/bips/blob/master/bip-0152.mediawiki

Constant Summary collapse

COMMAND =
"cmpctblock"

Constants included from Util

Util::DIGEST_NAME_SHA256

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#to_pkt

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

#to_hex

Constructor Details

#initialize(header_and_short_ids) ⇒ CmpctBlock

Returns a new instance of CmpctBlock.



10
11
12
# File 'lib/tapyrus/message/cmpct_block.rb', line 10

def initialize(header_and_short_ids)
  @header_and_short_ids = header_and_short_ids
end

Instance Attribute Details

#header_and_short_idsObject

Returns the value of attribute header_and_short_ids.



8
9
10
# File 'lib/tapyrus/message/cmpct_block.rb', line 8

def header_and_short_ids
  @header_and_short_ids
end

Class Method Details

.from_block(block, nonce = SecureRandom.hex(8).to_i(16)) ⇒ Tapyrus::Message::CmpctBlock

generate CmpctBlock from Block data.

Parameters:

  • block (Tapyrus::Block)

    the block to generate CmpctBlock.

  • nonce (Integer) (defaults to: SecureRandom.hex(8).to_i(16))

Returns:



18
19
20
21
22
23
# File 'lib/tapyrus/message/cmpct_block.rb', line 18

def self.from_block(block, nonce = SecureRandom.hex(8).to_i(16))
  h = HeaderAndShortIDs.new(block.header, nonce)
  block.transactions[1..-1].each { |tx| h.short_ids << h.short_id(tx.txid) }
  h.prefilled_txn << PrefilledTx.new(0, block.transactions.first)
  self.new(h)
end

.parse_from_payload(payload) ⇒ Object



25
26
27
# File 'lib/tapyrus/message/cmpct_block.rb', line 25

def self.parse_from_payload(payload)
  self.new(HeaderAndShortIDs.parse_from_payload(payload))
end

Instance Method Details

#to_payloadObject



29
30
31
# File 'lib/tapyrus/message/cmpct_block.rb', line 29

def to_payload
  header_and_short_ids.to_payload
end