diff --git a/lib/ckb/types/alert_message.rb b/lib/ckb/types/alert_message.rb new file mode 100644 index 00000000..562a8a74 --- /dev/null +++ b/lib/ckb/types/alert_message.rb @@ -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 \ No newline at end of file diff --git a/lib/ckb/types/chain_info.rb b/lib/ckb/types/chain_info.rb index f603817a..9d21e8d8 100644 --- a/lib/ckb/types/chain_info.rb +++ b/lib/ckb/types/chain_info.rb @@ -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 @@ -34,7 +34,7 @@ def to_h difficulty: @difficulty, median_time: @median_time, chain: @chain, - warnings: @warnings + alerts: @alerts } end @@ -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 diff --git a/lib/ckb/types/types.rb b/lib/ckb/types/types.rb index 5e3695b6..71609c3c 100644 --- a/lib/ckb/types/types.rb +++ b/lib/ckb/types/types.rb @@ -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"