Class: Tapyrus::Message::Reject

Inherits:
Base
  • Object
show all
Defined in:
lib/tapyrus/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

Constants included from Util

Util::DIGEST_NAME_SHA256

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#to_pkt

Methods included from Util

#byte_to_bit, #calc_checksum, #decode_base58_address, #double_sha256, #encode_base58_address, #hash160, #hmac_sha256, #pack_boolean, #pack_var_int, #pack_var_string, #padding_zero, #sha256, #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.



22
23
24
25
26
27
# File 'lib/tapyrus/message/reject.rb', line 22

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.



7
8
9
# File 'lib/tapyrus/message/reject.rb', line 7

def code
  @code
end

#extraObject

Returns the value of attribute extra.



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

def extra
  @extra
end

#messageObject

Returns the value of attribute message.



6
7
8
# File 'lib/tapyrus/message/reject.rb', line 6

def message
  @message
end

#reasonObject

Returns the value of attribute reason.



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

def reason
  @reason
end

Class Method Details

.parse_from_payload(payload) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/tapyrus/message/reject.rb', line 29

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 = %w[tx block].include?(message) ? payload.bth : payload
  new(message, code, reason, extra)
end

Instance Method Details

#to_payloadObject



37
38
39
40
# File 'lib/tapyrus/message/reject.rb', line 37

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