Class: Bitcoin::Protocol::Reject

Inherits:
Struct
  • Object
show all
Defined in:
lib/bitcoin/protocol/reject.rb

Constant Summary collapse

CCODE_TABLE =
{
  0x01 => :malformed,
  0x10 => :invalid,
  0x11 => :obsolete,
  0x12 => :duplicate,
  0x40 => :nonstandard,
  0x41 => :dust,
  0x42 => :insufficientfee,
  0x43 => :checkpoint
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#ccodeObject

Returns the value of attribute ccode

Returns:

  • (Object)

    the current value of ccode



5
6
7
# File 'lib/bitcoin/protocol/reject.rb', line 5

def ccode
  @ccode
end

#dataObject

Returns the value of attribute data

Returns:

  • (Object)

    the current value of data



5
6
7
# File 'lib/bitcoin/protocol/reject.rb', line 5

def data
  @data
end

#messageObject

Returns the value of attribute message

Returns:

  • (Object)

    the current value of message



5
6
7
# File 'lib/bitcoin/protocol/reject.rb', line 5

def message
  @message
end

#reasonObject

Returns the value of attribute reason

Returns:

  • (Object)

    the current value of reason



5
6
7
# File 'lib/bitcoin/protocol/reject.rb', line 5

def reason
  @reason
end

Class Method Details

.parse(payload) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/bitcoin/protocol/reject.rb', line 17

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

Instance Method Details

#block_hashObject



31
32
33
# File 'lib/bitcoin/protocol/reject.rb', line 31

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

#tx_hashObject



27
28
29
# File 'lib/bitcoin/protocol/reject.rb', line 27

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