Sha256: 3002745a11d9bf99f827b190f6c1cf7422b65fb1fa791326639c64863fee4ed4

Contents?: true

Size: 1.05 KB

Versions: 10

Compression:

Stored size: 1.05 KB

Contents

module Tapyrus
  module Message
    # cmpctblock message. support only version 1.
    # 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] nonce
      # @return [Tapyrus::Message::CmpctBlock]
      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

      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

10 entries across 10 versions & 1 rubygems

Version Path
tapyrus-0.3.4 lib/tapyrus/message/cmpct_block.rb
tapyrus-0.3.3 lib/tapyrus/message/cmpct_block.rb
tapyrus-0.3.2 lib/tapyrus/message/cmpct_block.rb
tapyrus-0.3.1 lib/tapyrus/message/cmpct_block.rb
tapyrus-0.3.0 lib/tapyrus/message/cmpct_block.rb
tapyrus-0.2.13 lib/tapyrus/message/cmpct_block.rb
tapyrus-0.2.12 lib/tapyrus/message/cmpct_block.rb
tapyrus-0.2.10 lib/tapyrus/message/cmpct_block.rb
tapyrus-0.2.9 lib/tapyrus/message/cmpct_block.rb
tapyrus-0.2.8 lib/tapyrus/message/cmpct_block.rb