Sha256: a6a96e61f9d0faef92a77b0300a2e4d2c72266814bc5998e5b82123e490d4f16

Contents?: true

Size: 750 Bytes

Versions: 22

Compression:

Stored size: 750 Bytes

Contents

module Bitcoin
  module Message

    # Base message class
    class Base
      include Bitcoin::Util
      extend Bitcoin::Util

      # generate message header (binary format)
      # https://bitcoin.org/en/developer-reference#message-headers
      def to_pkt
        payload = to_payload
        magic = Bitcoin.chain_params.magic_head.htb
        command_name = self.class.const_get(:COMMAND, false).ljust(12, "\x00")
        payload_size = [payload.bytesize].pack('V')
        checksum = Bitcoin.double_sha256(payload)[0...4]
        magic << command_name << payload_size << checksum << payload
      end

      # abstract method
      def to_payload
        raise 'to_payload must be implemented in a child class.'
      end

    end

  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
bitcoinrb-0.4.0 lib/bitcoin/message/base.rb
bitcoinrb-0.3.2 lib/bitcoin/message/base.rb
bitcoinrb-0.3.1 lib/bitcoin/message/base.rb
bitcoinrb-0.3.0 lib/bitcoin/message/base.rb
bitcoinrb-0.2.9 lib/bitcoin/message/base.rb
bitcoinrb-0.2.8 lib/bitcoin/message/base.rb
bitcoinrb-0.2.7 lib/bitcoin/message/base.rb
bitcoinrb-0.2.6 lib/bitcoin/message/base.rb
bitcoinrb-0.2.5 lib/bitcoin/message/base.rb
bitcoinrb-0.2.4 lib/bitcoin/message/base.rb
bitcoinrb-0.2.2 lib/bitcoin/message/base.rb
bitcoinrb-0.2.1 lib/bitcoin/message/base.rb
bitcoinrb-0.2.0 lib/bitcoin/message/base.rb
bitcoinrb-0.1.9 lib/bitcoin/message/base.rb
bitcoinrb-0.1.8 lib/bitcoin/message/base.rb
bitcoinrb-0.1.7 lib/bitcoin/message/base.rb
bitcoinrb-0.1.6 lib/bitcoin/message/base.rb
bitcoinrb-0.1.5 lib/bitcoin/message/base.rb
bitcoinrb-0.1.4 lib/bitcoin/message/base.rb
bitcoinrb-0.1.3 lib/bitcoin/message/base.rb