Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adjust generate_referring_cells rake #1476

Merged
merged 1 commit into from
Oct 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 14 additions & 16 deletions lib/tasks/migration/generate_referring_cells.rake
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,21 @@ namespace :migration do
contract_hashes = Contract.where(role: "type_script").pluck(:code_hash)
binary_hashes = CkbUtils.hexes_to_bins(contract_hashes)
contract_type_ids = TypeScript.where(code_hash: binary_hashes).pluck(:id)
live_cells = CellOutput.live.where(type_script_id: contract_type_ids)
progress_bar = ProgressBar.create({ total: live_cells.count, format: "%e %B %p%% %c/%C" })

live_cells.find_in_batches do |outputs|
outputs.each do |output|
progress_bar.increment

contract = output.type_script&.contract

next unless contract

contracts.each do |contract|
ReferringCell.create_or_find_by(
cell_output_id: output.id,
ckb_transaction_id: output.ckb_transaction_id,
contract_id: contract.id
)
contract_type_ids.each do |type_id|
puts "============#{type_id}"
progress_bar.increment
live_cells = CellOutput.live.where(type_script_id: type_id)

live_cells.find_in_batches do |outputs|
outputs.each do |output|
contract = output.type_script&.contract

ReferringCell.create_or_find_by(
cell_output_id: output.id,
ckb_transaction_id: output.ckb_transaction_id,
contract_id: contract.id
)
end
end
end
Expand Down