Class: Bitcoin::Message::CmpctBlock
- Defined in:
- lib/bitcoin/message/cmpct_block.rb
Overview
cmpctblock message github.com/bitcoin/bips/blob/master/bip-0152.mediawiki
Constant Summary collapse
- COMMAND =
'cmpctblock'
Instance Attribute Summary collapse
-
#header_and_short_ids ⇒ Object
Returns the value of attribute header_and_short_ids.
Class Method Summary collapse
-
.from_block(block, version, nonce = SecureRandom.hex(8).to_i(16)) ⇒ Bitcoin::Message::CmpctBlock
generate CmpctBlock from Block data.
- .parse_from_payload(payload) ⇒ Object
Instance Method Summary collapse
-
#initialize(header_and_short_ids) ⇒ CmpctBlock
constructor
A new instance of CmpctBlock.
- #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_and_short_ids) ⇒ CmpctBlock
Returns a new instance of CmpctBlock.
12 13 14 |
# File 'lib/bitcoin/message/cmpct_block.rb', line 12 def initialize(header_and_short_ids) @header_and_short_ids = header_and_short_ids end |
Instance Attribute Details
#header_and_short_ids ⇒ Object
Returns the value of attribute header_and_short_ids.
10 11 12 |
# File 'lib/bitcoin/message/cmpct_block.rb', line 10 def header_and_short_ids @header_and_short_ids end |
Class Method Details
.from_block(block, version, nonce = SecureRandom.hex(8).to_i(16)) ⇒ Bitcoin::Message::CmpctBlock
generate CmpctBlock from Block data.
21 22 23 24 25 26 27 28 29 |
# 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 |
.parse_from_payload(payload) ⇒ Object
31 32 33 |
# File 'lib/bitcoin/message/cmpct_block.rb', line 31 def self.parse_from_payload(payload) self.new(HeaderAndShortIDs.parse_from_payload(payload)) end |
Instance Method Details
#to_payload ⇒ Object
35 36 37 |
# File 'lib/bitcoin/message/cmpct_block.rb', line 35 def to_payload header_and_short_ids.to_payload end |