Class: Bitcoin::Message::Reject

Inherits:
Base
  • Object
show all
Defined in:
lib/bitcoin/message/reject.rb

Overview

Constant Summary collapse

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

from_pkt, #to_pkt

Methods included from Util

#byte_to_bit, #calc_checksum, #decode_base58_address, #double_sha256, #encode_base58_address, #hash160, #hkdf_sha256, #hmac_sha256, #pack_boolean, #pack_var_int, #pack_var_string, #padding_zero, #sha256, #tagged_hash, #unpack_boolean, #unpack_var_int, #unpack_var_int_from_io, #unpack_var_string, #valid_address?

Methods included from HexConverter

#to_hex

Constructor Details

#initialize(message, code, reason = '', extra = '') ⇒ Reject

Returns a new instance of Reject.



24
25
26
27
28
29
# File 'lib/bitcoin/message/reject.rb', line 24

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

Instance Attribute Details

#codeObject

Returns the value of attribute code.



9
10
11
# File 'lib/bitcoin/message/reject.rb', line 9

def code
  @code
end

#extraObject

Returns the value of attribute extra.



11
12
13
# File 'lib/bitcoin/message/reject.rb', line 11

def extra
  @extra
end

#messageObject

Returns the value of attribute message.



8
9
10
# File 'lib/bitcoin/message/reject.rb', line 8

def message
  @message
end

#reasonObject

Returns the value of attribute reason.



10
11
12
# File 'lib/bitcoin/message/reject.rb', line 10

def reason
  @reason
end

Class Method Details

.parse_from_payload(payload) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/bitcoin/message/reject.rb', line 31

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

Instance Method Details

#to_payloadObject



39
40
41
42
# File 'lib/bitcoin/message/reject.rb', line 39

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