Class: Tapyrus::Message::SendCmpct

Inherits:
Base
  • Object
show all
Defined in:
lib/tapyrus/message/send_cmpct.rb

Overview

Constant Summary collapse

COMMAND =
"sendcmpct"
MODE_HIGH =
1
MODE_LOW =
0

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(mode = MODE_HIGH, version = 1) ⇒ SendCmpct

TODO support version 2



16
17
18
19
# File 'lib/tapyrus/message/send_cmpct.rb', line 16

def initialize(mode = MODE_HIGH, version = 1)
  @mode = mode
  @version = version
end

Instance Attribute Details

#modeObject

Returns the value of attribute mode.



11
12
13
# File 'lib/tapyrus/message/send_cmpct.rb', line 11

def mode
  @mode
end

#versionObject

Returns the value of attribute version.



12
13
14
# File 'lib/tapyrus/message/send_cmpct.rb', line 12

def version
  @version
end

Class Method Details

.parse_from_payload(payload) ⇒ Object



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

def self.parse_from_payload(payload)
  buf = StringIO.new(payload)
  mode = buf.read(1).unpack("c").first
  version = buf.read(8).unpack("Q").first
  new(mode, version)
end

Instance Method Details

#high?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/tapyrus/message/send_cmpct.rb', line 32

def high?
  mode == 1
end

#low?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/tapyrus/message/send_cmpct.rb', line 36

def low?
  mode.zero?
end

#to_payloadObject



28
29
30
# File 'lib/tapyrus/message/send_cmpct.rb', line 28

def to_payload
  [mode, version].pack("cQ")
end