Skip to content

Commit fedf9dc

Browse files
committed
feat: add indexer types
1 parent b76d3f4 commit fedf9dc

File tree

5 files changed

+142
-0
lines changed

5 files changed

+142
-0
lines changed

lib/ckb/types/cell_transaction.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# frozen_string_literal: true
2+
3+
module CKB
4+
module Types
5+
class CellTransaction
6+
attr_reader :created_by, :consumed_by
7+
8+
# @param created_by [Types::TransactionPoint]
9+
# @param consumed_by [Types::TransactionPoint | nil]
10+
def initialize(created_by:, consumed_by: nil)
11+
@created_by = created_by
12+
@consumed_by = consumed_by
13+
end
14+
15+
def to_h
16+
{
17+
created_by: @created_by,
18+
consumed_by: @consumed_by
19+
}
20+
end
21+
22+
def self.from_h(hash)
23+
return if hash.nil?
24+
25+
consumed_by = hash[:consumed_by]
26+
27+
new(
28+
created_by: TransactionPoint.from_h(cell[:created_by]),
29+
consumed_by: consumed_by ? TransactionPoint.from_h(consumed_by) : nil
30+
)
31+
end
32+
end
33+
end
34+
end

lib/ckb/types/live_cell.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# frozen_string_literal: true
2+
3+
module CKB
4+
module Types
5+
class LiveCell
6+
attr_reader :cell_output, :created_by
7+
8+
# @param cell_output [Types::Output]
9+
# @param created_by [Types::TransactionPoint]
10+
def initialize(cell_output:, created_by:)
11+
@cell_output = cell_output
12+
@created_by = created_by
13+
end
14+
15+
def to_h
16+
{
17+
cell_output: @cell_output.to_h,
18+
created_by: @created_by.to_h
19+
}
20+
end
21+
22+
def self.from_h(hash)
23+
return if hash.nil?
24+
25+
new(
26+
cell_output: Output.from_h(hash[:cell_output]),
27+
created_by: TransactionPoint.from_h(hash[:created_by])
28+
)
29+
end
30+
end
31+
end
32+
end
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# frozen_string_literal: true
2+
3+
module CKB
4+
module Types
5+
class LockHashIndexState
6+
attr_reader :lock_hash, :block_number, :block_hash
7+
8+
# @param lock_hash [String]
9+
# @param block_number [String] number
10+
# @param block_hash [String]
11+
def initialize(lock_hash:, block_number:, block_hash:)
12+
@lock_hash = lock_hash
13+
@block_number = block_number
14+
@block_hash = block_hash
15+
end
16+
17+
def to_h
18+
{
19+
lock_hash: @lock_hash,
20+
block_number: @block_number,
21+
block_hash: @block_hash
22+
}
23+
end
24+
25+
def self.from_h(hash)
26+
return if hash.nil?
27+
28+
new(
29+
lock_hash: hash[:lock_hash],
30+
block_numebr: hash[:block_number],
31+
block_hash: hash[:block_hash]
32+
)
33+
end
34+
end
35+
end
36+
end

lib/ckb/types/transaction_point.rb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# frozen_string_literal: true
2+
3+
module CKB
4+
module Types
5+
class TransactionPoint
6+
attr_reader :block_number, :tx_hash, :index
7+
8+
# @param block_number [String]
9+
# @param tx_hash [String]
10+
# @param index [String]
11+
def initialize(block_number:, tx_hash:, index:)
12+
@block_number = block_number
13+
@tx_hash = tx_hash
14+
@index = index
15+
end
16+
17+
def to_h
18+
{
19+
block_number: @block_number,
20+
tx_hash: @tx_hash,
21+
index: @index
22+
}
23+
end
24+
25+
def self.from_h(hash)
26+
return if hash.nil?
27+
28+
new(
29+
block_number: hash[:block_number],
30+
tx_hash: hash[:tx_hash],
31+
index: hash[:index]
32+
)
33+
end
34+
end
35+
end
36+
end

lib/ckb/types/types.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
require_relative "peer"
2222
require_relative "tx_pool_info"
2323
require_relative "dry_run_result"
24+
require_relative "transaction_point"
25+
require_relative "lock_hash_index_state"
26+
require_relative "live_cell"
27+
require_relative "cell_transaction"
2428

2529
module CKB
2630
module Types

0 commit comments

Comments
 (0)