Sha256: 0fc96fcbcde892ecf422a9e5716bae6f05e6205d5b315e41710b209d5031b078

Contents?: true

Size: 516 Bytes

Versions: 9

Compression:

Stored size: 516 Bytes

Contents

module Tapyrus
  module Message

    # ping message class
    # https://bitcoin.org/en/developer-reference#ping
    class Ping < Base

      COMMAND = 'ping'

      attr_accessor :nonce

      def initialize(nonce = SecureRandom.random_number(0xffffffff))
        @nonce = nonce
      end

      def self.parse_from_payload(payload)
        new(payload.unpack('Q').first)
      end

      def to_payload
        [nonce].pack('Q')
      end

      def to_response
        Pong.new(nonce)
      end

    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

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