Skip to content

Commit

Permalink
feat: add two attrs to TxPoolInfo
Browse files Browse the repository at this point in the history
Add `total_tx_cycles` and `total_tx_size` to `TxPoolInfo`
  • Loading branch information
classicalliu committed May 27, 2019
1 parent 9d87a63 commit e737235
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
19 changes: 17 additions & 2 deletions lib/ckb/types/tx_pool_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,27 @@
module CKB
module Types
class TxPoolInfo
attr_reader :pending, :proposed, :orphan, :last_txs_updated_at
attr_reader :pending, :proposed, :orphan, :total_tx_cycles, :total_tx_size, :last_txs_updated_at

# @param pending [String] number
# @param proposed [String] number
# @param orphan [String] number
# @param total_tx_cycles [String] number
# @param total_tx_size [String] number
# @param last_txs_updated_at [String] timestamp
def initialize(pending:, proposed:, orphan:, last_txs_updated_at:)
def initialize(
pending:,
proposed:,
orphan:,
last_txs_updated_at:,
total_tx_cycles:,
total_tx_size:
)
@pending = pending.to_s
@proposed = proposed.to_s
@orphan = orphan.to_s
@total_tx_cycles = total_tx_cycles.to_s
@total_tx_size = total_tx_size.to_s
@last_txs_updated_at = last_txs_updated_at
end

Expand All @@ -21,6 +32,8 @@ def to_h
pending: @pending,
proposed: @proposed,
orphan: @orphan,
total_tx_cycles: @total_tx_cycles,
total_tx_size: @total_tx_size,
last_txs_updated_at: @last_txs_updated_at
}
end
Expand All @@ -32,6 +45,8 @@ def self.from_h(hash)
pending: hash[:pending],
proposed: hash[:proposed],
orphan: hash[:orphan],
total_tx_cycles: hash[:total_tx_cycles],
total_tx_size: hash[:total_tx_size],
last_txs_updated_at: hash[:last_txs_updated_at]
)
end
Expand Down
4 changes: 4 additions & 0 deletions spec/ckb/types/tx_pool_info_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"pending": "34",
"proposed": "22",
"orphan": "33",
"total_tx_cycles": "12",
"total_tx_size": "156",
"last_txs_updated_at": "1555507787683"
}
end
Expand All @@ -12,5 +14,7 @@
tx_pool_info = CKB::Types::TxPoolInfo.from_h(tx_pool_info_h)
expect(tx_pool_info).to be_a(CKB::Types::TxPoolInfo)
expect(tx_pool_info.pending).to eq tx_pool_info_h[:pending]
expect(tx_pool_info.total_tx_cycles).to eq tx_pool_info_h[:total_tx_cycles]
expect(tx_pool_info.total_tx_size).to eq tx_pool_info_h[:total_tx_size]
end
end

0 comments on commit e737235

Please sign in to comment.