Class: Bitcoin::Message::SendCmpct

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

Overview

Constant Summary collapse

COMMAND =
'sendcmpct'
MODE_HIGH =
1
MODE_LOW =
0

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

TODO support version 2



17
18
19
20
# File 'lib/bitcoin/message/send_cmpct.rb', line 17

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

Instance Attribute Details

#modeObject

Returns the value of attribute mode.



13
14
15
# File 'lib/bitcoin/message/send_cmpct.rb', line 13

def mode
  @mode
end

#versionObject

Returns the value of attribute version.



14
15
16
# File 'lib/bitcoin/message/send_cmpct.rb', line 14

def version
  @version
end

Class Method Details

.parse_from_payload(payload) ⇒ Object



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

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

Instance Method Details

#high?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/bitcoin/message/send_cmpct.rb', line 33

def high?
  mode == 1
end

#low?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/bitcoin/message/send_cmpct.rb', line 37

def low?
  mode.zero?
end

#to_payloadObject



29
30
31
# File 'lib/bitcoin/message/send_cmpct.rb', line 29

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