Sha256: cbe9f5532856b6c1e35a62b17663471ddd0559d48f3d1034d236a785ecf235c9

Contents?: true

Size: 750 Bytes

Versions: 1

Compression:

Stored size: 750 Bytes

Contents

module Tapyrus
  module Message

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

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

1 entries across 1 versions & 1 rubygems

Version Path
tapyrus-0.1.0 lib/tapyrus/message/base.rb