Skip to content

Commit

Permalink
feat: add alert message and update chain info
Browse files Browse the repository at this point in the history
  • Loading branch information
classicalliu committed Jun 19, 2019
1 parent 1926b39 commit d9580e6
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 6 deletions.
40 changes: 40 additions & 0 deletions lib/ckb/types/alert_message.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# frozen_string_literal: true

module CKB
module Types
class AlertMessage
attr_reader :id, :priority, :notice_until, :message

# @param id [String]
# @param priority [String]
# @param notice_until [String]
# @param message [String]
def initialize(id:, priority:, notice_until:, message:)
@id = id
@priority = priority
@notice_until = notice_until
@message = message
end

def to_h
{
id: @id,
priority: @priority,
notice_until: @notice_until,
message: @message
}
end

def self.from_h(hash)
return if hash.nil?

new(
id: hash[:id],
priority: hash[:priority],
notice_until: hash[:notice_until],
message: hash[:message]
)
end
end
end
end
12 changes: 6 additions & 6 deletions lib/ckb/types/chain_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@
module CKB
module Types
class ChainInfo
attr_reader :is_initial_block_download, :epoch, :difficulty, :median_time, :chain, :warnings
attr_reader :is_initial_block_download, :epoch, :difficulty, :median_time, :chain, :alerts

# @param is_initialize_block_download [Boolean]
# @param epoch [String] number
# @param difficulty [String] 0x...
# @param median_time [String] timestamp
# @param chain [String]
# @param warnings [String]
# @param alerts [Types::AlertMessage]
def initialize(
is_initial_block_download:,
epoch:,
difficulty:,
median_time:,
chain:,
warnings:
alerts:
)
@is_initial_block_download = is_initial_block_download
@epoch = epoch
@difficulty = difficulty
@median_time = median_time
@chain = chain
@warnings = warnings
@alerts = alerts
end

def to_h
Expand All @@ -34,7 +34,7 @@ def to_h
difficulty: @difficulty,
median_time: @median_time,
chain: @chain,
warnings: @warnings
alerts: @alerts
}
end

Expand All @@ -47,7 +47,7 @@ def self.from_h(hash)
difficulty: hash[:difficulty],
median_time: hash[:median_time],
chain: hash[:chain],
warnings: hash[:warnings]
alerts: hash[:alerts]&.map { |alert| Types::AlertMessage.from_h(alert) }
)
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/ckb/types/types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
require_relative "tx_status"
require_relative "witness"
require_relative "epoch"
require_relative "alert_message"
require_relative "chain_info"
require_relative "peer_state"
require_relative "address_info"
Expand Down

0 comments on commit d9580e6

Please sign in to comment.