Sha256: 656b645d7c760e8460fda144cd3eddd2dd4c5a7c8f85e62647befb4f9b055fd7

Contents?: true

Size: 1.83 KB

Versions: 18

Compression:

Stored size: 1.83 KB

Contents

# encoding: ascii-8bit

module Bitcoin
module Protocol

  class Alert < Struct.new(:version, :relay_until, :expiration, :id, :cancel, :set_cancel,
                           :min_ver, :max_ver, :set_sub_ver, :priority, :comment, :status_bar, :reserved)

    attr_accessor :payload, :signature

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

    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


    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
  end

end
end

Version data entries

18 entries across 18 versions & 2 rubygems

Version Path
bitcoin-ruby-0.0.18 lib/bitcoin/protocol/alert.rb
bitcoin-ruby-0.0.17 lib/bitcoin/protocol/alert.rb
bitcoin-ruby-0.0.16 lib/bitcoin/protocol/alert.rb
bitcoin-ruby-0.0.15 lib/bitcoin/protocol/alert.rb
monacoin-ruby-0.1.3 lib/bitcoin/protocol/alert.rb
bitcoin-ruby-0.0.14 lib/bitcoin/protocol/alert.rb
bitcoin-ruby-0.0.13 lib/bitcoin/protocol/alert.rb
bitcoin-ruby-0.0.12 lib/bitcoin/protocol/alert.rb
bitcoin-ruby-0.0.11 lib/bitcoin/protocol/alert.rb
bitcoin-ruby-0.0.10 lib/bitcoin/protocol/alert.rb
bitcoin-ruby-0.0.9 lib/bitcoin/protocol/alert.rb
bitcoin-ruby-0.0.8 lib/bitcoin/protocol/alert.rb
bitcoin-ruby-0.0.7 lib/bitcoin/protocol/alert.rb
bitcoin-ruby-0.0.6 lib/bitcoin/protocol/alert.rb
bitcoin-ruby-0.0.5 lib/bitcoin/protocol/alert.rb
bitcoin-ruby-0.0.4 lib/bitcoin/protocol/alert.rb
bitcoin-ruby-0.0.3 lib/bitcoin/protocol/alert.rb
bitcoin-ruby-0.0.2 lib/bitcoin/protocol/alert.rb