Skip to content

Commit

Permalink
Merge pull request #2322 from nervosnetwork/develop
Browse files Browse the repository at this point in the history
Deploy to testnet
  • Loading branch information
zmcNotafraid authored Dec 6, 2024
2 parents 9513941 + aaf9f3d commit 804e3e5
Showing 1 changed file with 1 addition and 88 deletions.
89 changes: 1 addition & 88 deletions lib/tasks/migration/analyze_contract_from_start_block.rake
Original file line number Diff line number Diff line change
Expand Up @@ -89,95 +89,8 @@ namespace :migration do
end
end
end
cell_deps_out_points_attrs = Set.new
contract_attrs = Set.new
cell_deps_attrs = Set.new

CellDependency.where(contract_analyzed: false).where.not(block_number: nil).order("block_number desc").limit(1000).each do |cell_dep|
cell_deps_attrs << { contract_analyzed: true, ckb_transaction_id: cell_dep.ckb_transaction_id, contract_cell_id: cell_dep.contract_cell_id, dep_type: cell_dep.dep_type }

next if CellDepsOutPoint.where(contract_cell_id: cell_dep.contract_cell_id).exists?

ckb_transaction = CkbTransaction.find(cell_dep.ckb_transaction_id)

type_script_hashes = Set.new
lock_script_hashes = Set.new

cell_outputs = ckb_transaction.cell_outputs.includes(:type_script, :lock_script).to_a
cell_inputs = ckb_transaction.cell_inputs.includes(:previous_cell_output).map(&:previous_cell_output)
cell_inputs.each do |input|
lock_script_hashes << input.lock_script.code_hash
type_script_hashes << input.type_script.code_hash if input.type_script
end

cell_outputs.each do |output|
lock_script_hashes << output.lock_script.code_hash
type_script_hashes << output.type_script.code_hash if output.type_script
end

case cell_dep.dep_type
when "code"
cell_output = cell_dep.cell_output
cell_deps_out_points_attrs << {
tx_hash: cell_output.tx_hash,
cell_index: cell_output.cell_index,
deployed_cell_output_id: cell_output.id,
contract_cell_id: cell_output.id,
}

is_lock_script = cell_output.type_script&.script_hash.in?(lock_script_hashes) || cell_output.data_hash.in?(lock_script_hashes)
is_type_script = cell_output.type_script&.script_hash.in?(type_script_hashes) || cell_output.data_hash.in?(type_script_hashes)

if is_lock_script || is_type_script
contract_attrs <<
{
type_hash: cell_output.type_script&.script_hash,
data_hash: cell_output.data_hash,
deployed_cell_output_id: cell_output.id,
is_type_script:,
is_lock_script:,
deployed_args: cell_output.type_script&.args,
}
end

when "dep_group"
# when the type of cell_dep is "dep_group", it means the cell specified by the `out_point` is a list of out points to the actual referred contract cells
mid_cell = cell_dep.cell_output

binary_data = mid_cell.binary_data
# parse the actual list of out points from the data field of the cell
out_points_count = binary_data[0, 4].unpack("L<")
# iterate over the out point list and append actual referred contract cells to cell dependencies_attrs
0.upto(out_points_count[0] - 1) do |i|
part_tx_hash, cell_index = binary_data[4 + i * 36, 36].unpack("H64L<")

tx_hash = "0x#{part_tx_hash}"
cell_output = CellOutput.find_by_pointer tx_hash, cell_index
cell_deps_out_points_attrs << {
tx_hash:,
cell_index:,
deployed_cell_output_id: cell_output.id,
contract_cell_id: mid_cell.id,
}

is_lock_script = cell_output.type_script&.script_hash.in?(lock_script_hashes) || cell_output.data_hash.in?(lock_script_hashes)
is_type_script = cell_output.type_script&.script_hash.in?(type_script_hashes) || cell_output.data_hash.in?(type_script_hashes)

if is_lock_script || is_type_script
contract_attrs <<
{
type_hash: cell_output.type_script&.script_hash,
data_hash: cell_output.data_hash,
deployed_cell_output_id: cell_output.id,
deployed_args: cell_output.type_script&.args,
is_type_script:,
is_lock_script:,
}
end
end
end
end
end

if cell_deps_out_points_attrs.any?
CellDepsOutPoint.upsert_all(cell_deps_out_points_attrs,

Check warning on line 95 in lib/tasks/migration/analyze_contract_from_start_block.rake

View check run for this annotation

Codecov / codecov/patch

lib/tasks/migration/analyze_contract_from_start_block.rake#L94-L95

Added lines #L94 - L95 were not covered by tests
unique_by: %i[contract_cell_id deployed_cell_output_id])
Expand Down

0 comments on commit 804e3e5

Please sign in to comment.