Class: Bitcoin::Protocol::Alert
- Inherits:
-
Struct
- Object
- Struct
- Bitcoin::Protocol::Alert
- Defined in:
- lib/bitcoin/protocol/alert.rb
Instance Attribute Summary collapse
-
#cancel ⇒ Object
Returns the value of attribute cancel.
-
#comment ⇒ Object
Returns the value of attribute comment.
-
#expiration ⇒ Object
Returns the value of attribute expiration.
-
#id ⇒ Object
Returns the value of attribute id.
-
#max_ver ⇒ Object
Returns the value of attribute max_ver.
-
#min_ver ⇒ Object
Returns the value of attribute min_ver.
-
#payload ⇒ Object
Returns the value of attribute payload.
-
#priority ⇒ Object
Returns the value of attribute priority.
-
#relay_until ⇒ Object
Returns the value of attribute relay_until.
-
#reserved ⇒ Object
Returns the value of attribute reserved.
-
#set_cancel ⇒ Object
Returns the value of attribute set_cancel.
-
#set_sub_ver ⇒ Object
Returns the value of attribute set_sub_ver.
-
#signature ⇒ Object
Returns the value of attribute signature.
-
#status_bar ⇒ Object
Returns the value of attribute status_bar.
-
#version ⇒ Object
Returns the value of attribute version.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(values, alert_payload = nil, alert_signature = nil) ⇒ Alert
constructor
A new instance of Alert.
- #valid_signature? ⇒ Boolean
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
#cancel ⇒ Object
Returns the value of attribute cancel
6 7 8 |
# File 'lib/bitcoin/protocol/alert.rb', line 6 def cancel @cancel end |
#comment ⇒ Object
Returns the value of attribute comment
6 7 8 |
# File 'lib/bitcoin/protocol/alert.rb', line 6 def comment @comment end |
#expiration ⇒ Object
Returns the value of attribute expiration
6 7 8 |
# File 'lib/bitcoin/protocol/alert.rb', line 6 def expiration @expiration end |
#id ⇒ Object
Returns the value of attribute id
6 7 8 |
# File 'lib/bitcoin/protocol/alert.rb', line 6 def id @id end |
#max_ver ⇒ Object
Returns the value of attribute max_ver
6 7 8 |
# File 'lib/bitcoin/protocol/alert.rb', line 6 def max_ver @max_ver end |
#min_ver ⇒ Object
Returns the value of attribute min_ver
6 7 8 |
# File 'lib/bitcoin/protocol/alert.rb', line 6 def min_ver @min_ver end |
#payload ⇒ Object
Returns the value of attribute payload.
9 10 11 |
# File 'lib/bitcoin/protocol/alert.rb', line 9 def payload @payload end |
#priority ⇒ Object
Returns the value of attribute priority
6 7 8 |
# File 'lib/bitcoin/protocol/alert.rb', line 6 def priority @priority end |
#relay_until ⇒ Object
Returns the value of attribute relay_until
6 7 8 |
# File 'lib/bitcoin/protocol/alert.rb', line 6 def relay_until @relay_until end |
#reserved ⇒ Object
Returns the value of attribute reserved
6 7 8 |
# File 'lib/bitcoin/protocol/alert.rb', line 6 def reserved @reserved end |
#set_cancel ⇒ Object
Returns the value of attribute set_cancel
6 7 8 |
# File 'lib/bitcoin/protocol/alert.rb', line 6 def set_cancel @set_cancel end |
#set_sub_ver ⇒ Object
Returns the value of attribute set_sub_ver
6 7 8 |
# File 'lib/bitcoin/protocol/alert.rb', line 6 def set_sub_ver @set_sub_ver end |
#signature ⇒ Object
Returns the value of attribute signature.
9 10 11 |
# File 'lib/bitcoin/protocol/alert.rb', line 9 def signature @signature end |
#status_bar ⇒ Object
Returns the value of attribute status_bar
6 7 8 |
# File 'lib/bitcoin/protocol/alert.rb', line 6 def @status_bar end |
#version ⇒ Object
Returns the value of attribute 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) , 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, , reserved ] new(values, alert_payload, alert_signature) end |
Instance Method Details
#valid_signature? ⇒ 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 |