Skip to content

Commit

Permalink
feat: stop create contract in node processor
Browse files Browse the repository at this point in the history
Signed-off-by: Miles Zhang <[email protected]>
  • Loading branch information
zmcNotafraid committed Dec 4, 2024
1 parent 9865c68 commit d451f8e
Showing 1 changed file with 33 additions and 33 deletions.
66 changes: 33 additions & 33 deletions app/models/ckb_sync/new_node_data_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -801,43 +801,43 @@ def build_cells_and_locks!(
lock_scripts_attributes.map! do |attr|
attr.merge!(created_at: Time.current, updated_at: Time.current)
end
lock_script_ids = LockScript.upsert_all(lock_scripts_attributes, unique_by: :script_hash, returning: [:id])

lock_script_ids.each do |row|
lock_script_id = row["id"]
lock_script = LockScript.find lock_script_id
contract = Contract.find_by code_hash: lock_script.code_hash
temp_hash = { script_hash: lock_script&.script_hash, is_contract: false }
if contract
temp_hash = temp_hash.merge is_contract: true, contract_id: contract.id
else
contract = Contract.create code_hash: lock_script.script_hash
temp_hash = temp_hash.merge contract_id: contract.id
end
# script = Script.find_or_create_by temp_hash
# lock_script.update script_id: script.id
end
LockScript.upsert_all(lock_scripts_attributes, unique_by: :script_hash, returning: [:id])

# lock_script_ids.each do |row|
# lock_script_id = row["id"]
# lock_script = LockScript.find lock_script_id
# contract = Contract.find_by code_hash: lock_script.code_hash
# temp_hash = { script_hash: lock_script&.script_hash, is_contract: false }
# if contract
# temp_hash = temp_hash.merge is_contract: true, contract_id: contract.id
# else
# contract = Contract.create code_hash: lock_script.script_hash
# temp_hash = temp_hash.merge contract_id: contract.id
# end
# # script = Script.find_or_create_by temp_hash
# # lock_script.update script_id: script.id
# end
end

if type_scripts_attributes.present?
type_scripts_attributes.map! do |attr|
attr.merge!(created_at: Time.current, updated_at: Time.current)
end
type_script_ids = TypeScript.upsert_all(type_scripts_attributes, unique_by: :script_hash, returning: [:id])
type_script_ids.each do |row|
type_script_id = row["id"]
type_script = TypeScript.find(type_script_id)
temp_hash = { script_hash: type_script&.script_hash, is_contract: false }
contract = Contract.find_by code_hash: type_script.code_hash
if contract
temp_hash = temp_hash.merge is_contract: true, contract_id: contract.id
else
contract = Contract.create code_hash: type_script.script_hash
temp_hash = temp_hash.merge contract_id: contract.id
end
# script = Script.find_or_create_by temp_hash
# type_script.update script_id: script.id
end
TypeScript.upsert_all(type_scripts_attributes, unique_by: :script_hash, returning: [:id])
# type_script_ids.each do |row|
# type_script_id = row["id"]
# type_script = TypeScript.find(type_script_id)
# temp_hash = { script_hash: type_script&.script_hash, is_contract: false }
# contract = Contract.find_by code_hash: type_script.code_hash
# if contract
# temp_hash = temp_hash.merge is_contract: true, contract_id: contract.id
# else
# contract = Contract.create code_hash: type_script.script_hash
# temp_hash = temp_hash.merge contract_id: contract.id
# end
# # script = Script.find_or_create_by temp_hash
# # type_script.update script_id: script.id
# end
end
build_addresses!(outputs, local_block)
# prepare script ids for insert cell_outputs
Expand Down Expand Up @@ -910,8 +910,8 @@ def build_cells_and_locks!(
record_timestamps: true)
end

ScriptTransaction.create_from_scripts TypeScript.where(id: type_script_ids)
ScriptTransaction.create_from_scripts LockScript.where(id: lock_script_ids)
# ScriptTransaction.create_from_scripts TypeScript.where(id: type_script_ids)
# ScriptTransaction.create_from_scripts LockScript.where(id: lock_script_ids)

[input_capacities, output_capacities]
end
Expand Down

0 comments on commit d451f8e

Please sign in to comment.