Sha256: f4e717ac219106f373830fa6ceabdfe4053c1bdfdc9009cd023f2b62ffed1345

Contents?: true

Size: 1.19 KB

Versions: 9

Compression:

Stored size: 1.19 KB

Contents

module Tapyrus
  module Message

    # reject message
    # https://bitcoin.org/en/developer-reference#reject
    class Reject < Base

      attr_accessor :message
      attr_accessor :code
      attr_accessor :reason
      attr_accessor :extra

      COMMAND = 'reject'

      CODE_MALFORMED = 0x01
      CODE_INVALID = 0x10
      CODE_OBSOLETE = 0x11
      CODE_DUPLICATE = 0x12
      CODE_NONSTANDARD = 0x40
      CODE_DUST = 0x41
      CODE_INSUFFICIENT_FEE = 0x42
      CODE_CHECKPOINT = 0x43

      def initialize(message, code, reason = '', extra = '')
        @message = message
        @code = code
        @reason = reason
        @extra = extra
      end

      def self.parse_from_payload(payload)
        message, payload = Tapyrus.unpack_var_string(payload)
        code, payload = payload.unpack('Ca*')
        reason, payload = Tapyrus.unpack_var_string(payload)
        extra = ['tx', 'block'].include?(message) ? payload.bth : payload
        new(message, code, reason, extra)
      end

      def to_payload
        e = ['tx', 'block'].include?(message) ? extra.htb : extra
        Tapyrus.pack_var_string(message) << [code].pack('C') << Tapyrus.pack_var_string(reason) << e
      end

    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

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