Sha256: ef2ebc924d70dea5f6bf8863769ad37da85060050f1aead39a6639e642f8aec3

Contents?: true

Size: 850 Bytes

Versions: 12

Compression:

Stored size: 850 Bytes

Contents

# encoding: ascii-8bit

module Bitcoin
module Protocol

  class Reject < Struct.new(:message, :ccode, :reason, :data)
    CCODE_TABLE = {
      0x01 => :malformed,
      0x10 => :invalid,
      0x11 => :obsolete,
      0x12 => :duplicate,
      0x40 => :nonstandard,
      0x41 => :dust,
      0x42 => :insufficientfee,
      0x43 => :checkpoint,
    }

    def self.parse(payload)
      message, payload = Bitcoin::Protocol.unpack_var_string(payload)
      ccode,   payload = payload.unpack("Ca*")
      reason,  payload = Bitcoin::Protocol.unpack_var_string(payload)
      data =   payload

      code = CCODE_TABLE[ccode] || ccode
      new(message, code, reason, data)
    end

    def tx_hash
      message == "tx" && self[:data].reverse.bth
    end

    def block_hash
      message == "block" && self[:data].reverse.bth
    end
  end

end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
bitcoin-ruby-0.0.18 lib/bitcoin/protocol/reject.rb
bitcoin-ruby-0.0.17 lib/bitcoin/protocol/reject.rb
bitcoin-ruby-0.0.16 lib/bitcoin/protocol/reject.rb
bitcoin-ruby-0.0.15 lib/bitcoin/protocol/reject.rb
monacoin-ruby-0.1.3 lib/bitcoin/protocol/reject.rb
bitcoin-ruby-0.0.14 lib/bitcoin/protocol/reject.rb
bitcoin-ruby-0.0.13 lib/bitcoin/protocol/reject.rb
bitcoin-ruby-0.0.12 lib/bitcoin/protocol/reject.rb
bitcoin-ruby-0.0.11 lib/bitcoin/protocol/reject.rb
bitcoin-ruby-0.0.10 lib/bitcoin/protocol/reject.rb
bitcoin-ruby-0.0.9 lib/bitcoin/protocol/reject.rb
bitcoin-ruby-0.0.8 lib/bitcoin/protocol/reject.rb