Sha256: dee8790002748adf4f50b8e60ebfa1cba72171fda9bb7f3d2221f26ef4ba7b82

Contents?: true

Size: 829 Bytes

Versions: 32

Compression:

Stored size: 829 Bytes

Contents

module Bitcoin
  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 = Bitcoin.unpack_var_int_from_io(buf)
        txn = tx_count.times.map{Bitcoin::Tx.parse_from_payload(buf)}
        self.new(block_hash, txn)
      end

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

    end

  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
bitcoinrb-1.7.0 lib/bitcoin/message/block_transactions.rb
bitcoinrb-1.6.0 lib/bitcoin/message/block_transactions.rb
bitcoinrb-1.5.0 lib/bitcoin/message/block_transactions.rb
bitcoinrb-1.4.0 lib/bitcoin/message/block_transactions.rb
bitcoinrb-1.3.0 lib/bitcoin/message/block_transactions.rb
bitcoinrb-1.2.1 lib/bitcoin/message/block_transactions.rb
bitcoinrb-1.2.0 lib/bitcoin/message/block_transactions.rb
bitcoinrb-1.1.1 lib/bitcoin/message/block_transactions.rb
bitcoinrb-1.1.0 lib/bitcoin/message/block_transactions.rb
bitcoinrb-1.0.0 lib/bitcoin/message/block_transactions.rb
bitcoinrb-0.9.0 lib/bitcoin/message/block_transactions.rb
bitcoinrb-0.8.0 lib/bitcoin/message/block_transactions.rb
bitcoinrb-0.7.0 lib/bitcoin/message/block_transactions.rb
bitcoinrb-0.6.0 lib/bitcoin/message/block_transactions.rb
bitcoinrb-0.5.0 lib/bitcoin/message/block_transactions.rb
bitcoinrb-0.4.0 lib/bitcoin/message/block_transactions.rb
bitcoinrb-0.3.2 lib/bitcoin/message/block_transactions.rb
bitcoinrb-0.3.1 lib/bitcoin/message/block_transactions.rb
bitcoinrb-0.3.0 lib/bitcoin/message/block_transactions.rb
bitcoinrb-0.2.9 lib/bitcoin/message/block_transactions.rb