Sha256: 5cc685488da02dbc99c98931205fec4643ca2334f8e3b4ed4e65d67d4b331e23

Contents?: true

Size: 513 Bytes

Versions: 10

Compression:

Stored size: 513 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

10 entries across 10 versions & 1 rubygems

Version Path
tapyrus-0.3.4 lib/tapyrus/message/ping.rb
tapyrus-0.3.3 lib/tapyrus/message/ping.rb
tapyrus-0.3.2 lib/tapyrus/message/ping.rb
tapyrus-0.3.1 lib/tapyrus/message/ping.rb
tapyrus-0.3.0 lib/tapyrus/message/ping.rb
tapyrus-0.2.13 lib/tapyrus/message/ping.rb
tapyrus-0.2.12 lib/tapyrus/message/ping.rb
tapyrus-0.2.10 lib/tapyrus/message/ping.rb
tapyrus-0.2.9 lib/tapyrus/message/ping.rb
tapyrus-0.2.8 lib/tapyrus/message/ping.rb