Skip to content

Commit

Permalink
fix: contract with data1 hash_type needs to handle
Browse files Browse the repository at this point in the history
Signed-off-by: Miles Zhang <[email protected]>
  • Loading branch information
zmcNotafraid committed Mar 21, 2024
1 parent c58eb40 commit 13af18b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion app/jobs/import_transaction_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def process_deployed_cell(lock_script_or_type_script)

dep =
case lock_script_or_type_script.hash_type
when "data"
when "data", "data1"
by_data_hash[lock_script_or_type_script.code_hash]
when "type"
by_type_hash[lock_script_or_type_script.code_hash]
Expand Down
22 changes: 11 additions & 11 deletions app/models/deployed_cell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class DeployedCell < ApplicationRecord
# @param cell_output_id [Integer] deployed cell output id
def self.cell_output_id_to_contract_id(cell_output_id)
Rails.cache.fetch(["cell_output_id_to_contract_id", cell_output_id], expires_in: 1.day) do
DeployedCell.where(cell_output_id: cell_output_id).pick(:contract_id)
DeployedCell.where(cell_output_id:).pick(:contract_id)
end
end

Expand Down Expand Up @@ -73,7 +73,7 @@ def self.create_initial_data_for_ckb_transaction(ckb_transaction, cell_deps)
dep_type: cell_dep["dep_type"],
ckb_transaction_id: ckb_transaction.id,
contract_id: DeployedCell.cell_output_id_to_contract_id(cell_output.id), # check if we already known the relationship between the contract cell and contract
implicit: cell_dep["implicit"] || false
implicit: cell_dep["implicit"] || false,
}

# we don't know how the cells in transaction may refer to the contract cell
Expand Down Expand Up @@ -106,7 +106,7 @@ def self.create_initial_data_for_ckb_transaction(ckb_transaction, cell_deps)
dep_type: cell_dep["dep_type"],
ckb_transaction_id: ckb_transaction.id,
contract_id: nil,
implicit: false
implicit: false,
}
binary_data = mid_cell.binary_data
# binary_data = [hex_data[2..-1]].pack("H*")
Expand All @@ -121,10 +121,10 @@ def self.create_initial_data_for_ckb_transaction(ckb_transaction, cell_deps)
co = parse_code_dep[{
"out_point" => {
"tx_hash" => "0x#{tx_hash}",
"index" => cell_index
"index" => cell_index,
},
"dep_type" => "code",
"implicit" => true # this is an implicit dependency
"implicit" => true, # this is an implicit dependency
}]
end
end
Expand All @@ -138,10 +138,10 @@ def self.create_initial_data_for_ckb_transaction(ckb_transaction, cell_deps)
scripts.each do |lock_script_or_type_script|
dep =
case lock_script_or_type_script.hash_type
when "data"
by_data_hash[lock_script_or_type_script.code_hash]
when "type"
by_type_hash[lock_script_or_type_script.code_hash]
when "data", "data1"
by_data_hash[lock_script_or_type_script.code_hash]
when "type"
by_type_hash[lock_script_or_type_script.code_hash]
end
next unless dep

Expand All @@ -158,7 +158,7 @@ def self.create_initial_data_for_ckb_transaction(ckb_transaction, cell_deps)

deployed_cells_attrs << {
contract_id: contract.id,
cell_output_id: dep[:contract_cell_id]
cell_output_id: dep[:contract_cell_id],
}
end
end
Expand All @@ -168,7 +168,7 @@ def self.create_initial_data_for_ckb_transaction(ckb_transaction, cell_deps)
if cell_dependencies_attrs.present?
CellDependency.upsert_all cell_dependencies_attrs.uniq { |a|
a[:contract_cell_id]
}, unique_by: [:ckb_transaction_id, :contract_cell_id]
}, unique_by: %i[ckb_transaction_id contract_cell_id]
end
DeployedCell.upsert_all deployed_cells_attrs, unique_by: [:cell_output_id] if deployed_cells_attrs.present?
deployed_cells_attrs.each do |deployed_cell_attr|
Expand Down

0 comments on commit 13af18b

Please sign in to comment.