Sha256: 9c293c979422c5dc509645be42bee50e55cee23e176e6b46c96c8283e18a4edb
Contents?: true
Size: 1.23 KB
Versions: 1
Compression:
Stored size: 1.23 KB
Contents
module Tapyrus module Message # cmpctblock message # https://github.com/bitcoin/bips/blob/master/bip-0152.mediawiki class CmpctBlock < Base COMMAND = 'cmpctblock' attr_accessor :header_and_short_ids def initialize(header_and_short_ids) @header_and_short_ids = header_and_short_ids end # generate CmpctBlock from Block data. # @param [Tapyrus::Block] block the block to generate CmpctBlock. # @param [Integer] version Compact Block version specified by sendcmpct message. # @param [Integer] nonce # @return [Tapyrus::Message::CmpctBlock] 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 def self.parse_from_payload(payload) self.new(HeaderAndShortIDs.parse_from_payload(payload)) end def to_payload header_and_short_ids.to_payload end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
tapyrus-0.1.0 | lib/tapyrus/message/cmpct_block.rb |