Skip to content

Commit a4ade40

Browse files
committed
feat: implement get_cells_capacity api
1 parent b6e5497 commit a4ade40

3 files changed

Lines changed: 44 additions & 0 deletions

File tree

lib/ckb/indexer/api.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ def get_cells(search_key:, order: "asc", limit: DEFAULT_LIMIT, after_cursor: nil
1515
result = rpc.get_cells(search_key.to_h, order, Utils.to_hex(limit), after_cursor)
1616
CKB::Indexer::Types::LiveCells.from_h(result)
1717
end
18+
19+
def get_cells_capacity(search_key)
20+
result = rpc.get_cells_capacity(search_key.to_h)
21+
CKB::Indexer::Types::CellsCapacity.from_h(result)
22+
end
1823
end
1924
end
2025
end
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# frozen_string_literal: true
2+
3+
module CKB
4+
module Indexer
5+
module Types
6+
class CellsCapacity
7+
attr_reader :block_number, :block_hash, :capacity
8+
9+
# @param block_number [String | Integer] integer or hex number
10+
# @param block_hash [String]
11+
# @param capacity [String | Integer]
12+
def initialize(capacity:, block_number:, block_hash:)
13+
@capacity = Utils.to_int(capacity)
14+
@block_hash = block_hash
15+
@block_number = Utils.to_int(block_number)
16+
end
17+
18+
def self.from_h(hash)
19+
return if hash.nil?
20+
21+
new(
22+
capacity: hash[:capacity],
23+
block_hash: hash[:block_hash],
24+
block_number: hash[:block_number]
25+
)
26+
end
27+
28+
def to_h
29+
{
30+
capacity: Utils.to_hex(capacity),
31+
block_hash: block_hash,
32+
block_number: block_number
33+
}
34+
end
35+
end
36+
end
37+
end
38+
end

lib/ckb/indexer/types/types.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
require_relative "live_cell"
55
require_relative "live_cells"
66
require_relative "search_key_filter"
7+
require_relative "cells_capacity"
78

89
module CKB
910
module Indexer

0 commit comments

Comments
 (0)