Class: Bitcoin::Protocol::Alert

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(values, alert_payload = nil, alert_signature = nil) ⇒ Alert

Returns a new instance of Alert.



11
12
13
14
# File 'lib/bitcoin/protocol/alert.rb', line 11

def initialize(values, alert_payload=nil, alert_signature=nil)
  @payload, @signature = alert_payload, alert_signature
  super(*values)
end

Instance Attribute Details

#cancelObject

Returns the value of attribute cancel

Returns:

  • (Object)

    the current value of cancel



6
7
8
# File 'lib/bitcoin/protocol/alert.rb', line 6

def cancel
  @cancel
end

#commentObject

Returns the value of attribute comment

Returns:

  • (Object)

    the current value of comment



6
7
8
# File 'lib/bitcoin/protocol/alert.rb', line 6

def comment
  @comment
end

#expirationObject

Returns the value of attribute expiration

Returns:

  • (Object)

    the current value of expiration



6
7
8
# File 'lib/bitcoin/protocol/alert.rb', line 6

def expiration
  @expiration
end

#idObject

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



6
7
8
# File 'lib/bitcoin/protocol/alert.rb', line 6

def id
  @id
end

#max_verObject

Returns the value of attribute max_ver

Returns:

  • (Object)

    the current value of max_ver



6
7
8
# File 'lib/bitcoin/protocol/alert.rb', line 6

def max_ver
  @max_ver
end

#min_verObject

Returns the value of attribute min_ver

Returns:

  • (Object)

    the current value of min_ver



6
7
8
# File 'lib/bitcoin/protocol/alert.rb', line 6

def min_ver
  @min_ver
end

#payloadObject

Returns the value of attribute payload.



9
10
11
# File 'lib/bitcoin/protocol/alert.rb', line 9

def payload
  @payload
end

#priorityObject

Returns the value of attribute priority

Returns:

  • (Object)

    the current value of priority



6
7
8
# File 'lib/bitcoin/protocol/alert.rb', line 6

def priority
  @priority
end

#relay_untilObject

Returns the value of attribute relay_until

Returns:

  • (Object)

    the current value of relay_until



6
7
8
# File 'lib/bitcoin/protocol/alert.rb', line 6

def relay_until
  @relay_until
end

#reservedObject

Returns the value of attribute reserved

Returns:

  • (Object)

    the current value of reserved



6
7
8
# File 'lib/bitcoin/protocol/alert.rb', line 6

def reserved
  @reserved
end

#set_cancelObject

Returns the value of attribute set_cancel

Returns:

  • (Object)

    the current value of set_cancel



6
7
8
# File 'lib/bitcoin/protocol/alert.rb', line 6

def set_cancel
  @set_cancel
end

#set_sub_verObject

Returns the value of attribute set_sub_ver

Returns:

  • (Object)

    the current value of set_sub_ver



6
7
8
# File 'lib/bitcoin/protocol/alert.rb', line 6

def set_sub_ver
  @set_sub_ver
end

#signatureObject

Returns the value of attribute signature.



9
10
11
# File 'lib/bitcoin/protocol/alert.rb', line 9

def signature
  @signature
end

#status_barObject

Returns the value of attribute status_bar

Returns:

  • (Object)

    the current value of status_bar



6
7
8
# File 'lib/bitcoin/protocol/alert.rb', line 6

def status_bar
  @status_bar
end

#versionObject

Returns the value of attribute version

Returns:

  • (Object)

    the current value of version



6
7
8
# File 'lib/bitcoin/protocol/alert.rb', line 6

def version
  @version
end

Class Method Details

.parse(payload) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/bitcoin/protocol/alert.rb', line 23

def self.parse(payload)
  count,             payload = Bitcoin::Protocol.unpack_var_int(payload)
  alert_payload,     payload = payload.unpack("a#{count}a*")
  count,             payload = Bitcoin::Protocol.unpack_var_int(payload)
  alert_signature,   payload = payload.unpack("a#{count}a*")

  version, relay_until, expiration, id, cancel, payload = alert_payload.unpack("VQQVVa*")

  set_cancel,        payload = Bitcoin::Protocol.unpack_var_int_array(payload)
  min_ver, max_ver,  payload = payload.unpack("VVa*")
  set_sub_ver,       payload = Bitcoin::Protocol.unpack_var_string_array(payload)
  priority,          payload = payload.unpack("Va*")
  comment,           payload = Bitcoin::Protocol.unpack_var_string(payload)
  status_bar,        payload = Bitcoin::Protocol.unpack_var_string(payload)
  reserved,          payload = Bitcoin::Protocol.unpack_var_string(payload)

  values = [ version, relay_until, expiration, id, cancel, set_cancel, min_ver, max_ver, set_sub_ver, priority, comment, status_bar, reserved ]

  new(values, alert_payload, alert_signature)
end

Instance Method Details

#valid_signature?Boolean

Returns:

  • (Boolean)


16
17
18
19
20
# File 'lib/bitcoin/protocol/alert.rb', line 16

def valid_signature?
  return false unless @payload && @signature
  hash = Digest::SHA256.digest(Digest::SHA256.digest(@payload))
  Bitcoin.network[:alert_pubkeys].any?{|public_key| Bitcoin.verify_signature(hash, @signature, public_key) }
end