Skip to content

Commit 282dbd1

Browse files
authored
Merge pull request #2590 from nervosnetwork/develop
Deploy to testnet
2 parents 9b080f7 + 38c6b92 commit 282dbd1

File tree

3 files changed

+43
-12
lines changed

3 files changed

+43
-12
lines changed

app/controllers/api/v1/address_live_cells_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def show
88

99
json = Addresses::LiveCells.run!(
1010
{ request:,
11-
key: params[:id], sort: params[:sort], bound_status: params[:bound_status],
11+
key: params[:id], sort: params[:sort], bound_status: params[:bound_status], tag: params[:tag],
1212
page: params[:page], page_size: params[:page_size] },
1313
)
1414
render json:

app/interactions/addresses/live_cells.rb

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,15 @@ class LiveCells < ActiveInteraction::Base
88
string :sort, default: "block_timestamp.desc"
99
integer :page, default: 1
1010
integer :page_size, default: CellOutput.default_per_page
11+
string :tag, default: nil
1112

1213
def execute
1314
address = Explore.run!(key:)
1415
raise AddressNotFoundError if address.is_a?(NullAddress)
1516

1617
order_by, asc_or_desc = live_cells_ordering
17-
if bound_status
18-
bitcoin_vouts = BitcoinVout.where(address_id: address.map(&:id), status: bound_status)
19-
records = CellOutput.live.where(id: bitcoin_vouts.map(&:cell_output_id)).order(order_by => asc_or_desc).
20-
page(page).per(page_size).fast_page
21-
else
22-
records = CellOutput.live.where(address_id: address.map(&:id)).order(order_by => asc_or_desc).
23-
page(page).per(page_size).fast_page
24-
end
18+
records = fetch_cell_output_scope(address)
19+
records = records.order(order_by => asc_or_desc).page(page).per(page_size).fast_page
2520

2621
options = FastJsonapi::PaginationMetaGenerator.new(request:, records:, page:, page_size:).call
2722
CellOutputSerializer.new(records, options).serialized_json
@@ -37,5 +32,42 @@ def live_cells_ordering
3732

3833
[sort_by, sort_order]
3934
end
35+
36+
def fetch_cell_output_scope(address)
37+
address_ids = address.map(&:id)
38+
39+
scope =
40+
if bound_status
41+
vout_ids = BitcoinVout.where(address_id: address_ids, status: bound_status).pluck(:cell_output_id)
42+
CellOutput.live.where(id: vout_ids)
43+
else
44+
CellOutput.live.where(address_id: address_ids)
45+
end
46+
47+
tag.present? ? filter_by_tag(scope) : scope
48+
end
49+
50+
def filter_by_tag(scope)
51+
case tag
52+
when "fiber"
53+
lock_script_ids = scope.where.not(lock_script_id: nil).distinct.pluck(:lock_script_id)
54+
filtered_ids = LockScript.where(id: lock_script_ids, code_hash: Settings.fiber_funding_code_hash).pluck(:id)
55+
scope.where(lock_script_id: filtered_ids)
56+
when "multisig"
57+
lock_script_ids = scope.where.not(lock_script_id: nil).distinct.pluck(:lock_script_id)
58+
filtered_ids = LockScript.where(id: lock_script_ids).where(
59+
"(code_hash = ? AND hash_type = ?) OR (code_hash = ? AND hash_type = ?)",
60+
Settings.multisig_code_hash, "data1",
61+
Settings.secp_multisig_cell_type_hash, "type"
62+
).pluck(:id)
63+
scope.where(lock_script_id: filtered_ids)
64+
when "deployment"
65+
scope_ids = scope.pluck(:id)
66+
matched_ids = Contract.where(deployed_cell_output_id: scope_ids).pluck(:deployed_cell_output_id)
67+
scope.where(id: matched_ids)
68+
else
69+
CellOutput.none
70+
end
71+
end
4072
end
4173
end

lib/tasks/migration/check_cell_output_data.rake

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,16 @@ namespace :migration do
88
write_timeout: 1
99
})
1010
(args[:start_block].to_i..args[:end_block].to_i).to_a.each_slice(100).to_a.each do |range|
11-
compare_output(range, 0)
11+
check_output(range, 0)
1212
end
13-
nil
1413

1514
puts "=============="
1615
puts "retry IDS:"
1716
puts $retry_ids.join(",")
1817
puts "done"
1918
end
2019

21-
def compare_output(range, retry_count)
20+
def check_output(range, retry_count)
2221
request_body =
2322
range.map do |number|
2423
["get_block_by_number", number]

0 commit comments

Comments
 (0)