Sha256: 17138c35d9739fafdb530b174c9529a5bbcbd4eaeeb2666048e43f2d2a8a04ba

Contents?: true

Size: 829 Bytes

Versions: 9

Compression:

Stored size: 829 Bytes

Contents

module Tapyrus
  module Message

    # BIP-152 Compact Block's data format.
    # https://github.com/bitcoin/bips/blob/master/bip-0152.mediawiki#BlockTransactions
    class BlockTransactions

      attr_accessor :block_hash
      attr_accessor :transactions

      def initialize(block_hash, transactions)
        @block_hash = block_hash
        @transactions = transactions
      end

      def self.parse_from_payload(payload)
        buf = StringIO.new(payload)
        block_hash = buf.read(32).bth
        tx_count = Tapyrus.unpack_var_int_from_io(buf)
        txn = tx_count.times.map{Tapyrus::Tx.parse_from_payload(buf)}
        self.new(block_hash, txn)
      end

      def to_payload
        block_hash.htb << Tapyrus.pack_var_int(transactions.size) << transactions.map(&:to_payload).join
      end

    end

  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
tapyrus-0.2.7 lib/tapyrus/message/block_transactions.rb
tapyrus-0.2.6 lib/tapyrus/message/block_transactions.rb
tapyrus-0.2.5 lib/tapyrus/message/block_transactions.rb
tapyrus-0.2.4 lib/tapyrus/message/block_transactions.rb
tapyrus-0.2.3 lib/tapyrus/message/block_transactions.rb
tapyrus-0.2.2 lib/tapyrus/message/block_transactions.rb
tapyrus-0.2.1 lib/tapyrus/message/block_transactions.rb
tapyrus-0.2.0 lib/tapyrus/message/block_transactions.rb
tapyrus-0.1.0 lib/tapyrus/message/block_transactions.rb