Skip to content

Commit

Permalink
fix: current exist no binded type script that cause wrong query (#1417)
Browse files Browse the repository at this point in the history
fix: with no unique index can't use create_or_find_by

Signed-off-by: Miles Zhang <mingchang555@hotmail.com>
  • Loading branch information
zmcNotafraid committed Aug 29, 2023
1 parent 3c9174c commit 3bb9457
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions app/models/ckb_sync/new_node_data_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ def build_cells_and_locks!(
contract = Contract.create code_hash: lock_script.script_hash
temp_hash = temp_hash.merge contract_id: contract.id
end
script = Script.create_or_find_by temp_hash
script = Script.find_or_create_by temp_hash
lock_script.update script_id: script.id
end
end
Expand All @@ -798,7 +798,7 @@ def build_cells_and_locks!(
contract = Contract.create code_hash: type_script.script_hash
temp_hash = temp_hash.merge contract_id: contract.id
end
script = Script.create_or_find_by temp_hash
script = Script.find_or_create_by temp_hash
type_script.update script_id: script.id
end
end
Expand Down Expand Up @@ -1401,7 +1401,7 @@ def generate_address_in_advance(cellbase, block_timestamp)
return if cellbase.witnesses.blank?

lock_script = CkbUtils.generate_lock_script_from_cellbase(cellbase)
lock = LockScript.create_or_find_by(
lock = LockScript.find_or_create_by(
code_hash: lock_script.code_hash,
hash_type: lock_script.hash_type,
args: lock_script.args
Expand Down
2 changes: 1 addition & 1 deletion app/models/lock_script.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def self.process(sdk_lock)
create_with(
script_hash: lock_hash,
address: address
).create_or_find_by!(
).find_or_create_by!(
code_hash: sdk_lock.code_hash,
hash_type: sdk_lock.hash_type,
args: sdk_lock.args
Expand Down
4 changes: 2 additions & 2 deletions app/models/script.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def self.create_initial_data
temp_hash = temp_hash.merge is_contract: true, contract_id: contract_id
end

script = Script.create_or_find_by temp_hash
script = Script.find_or_create_by temp_hash
type_script.update script_id: script.id
end

Expand All @@ -32,7 +32,7 @@ def self.create_initial_data
if contract_id
temp_hash = temp_hash.merge is_contract: true, contract_id: contract_id
end
script = Script.create_or_find_by temp_hash
script = Script.find_or_create_by temp_hash
lock_script.update script_id: script.id
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/type_script.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def self.process(sdk_type)
# script = Script
create_with(
script_hash: type_hash
).create_or_find_by(
).find_or_create_by(
code_hash: sdk_type.code_hash,
hash_type: sdk_type.hash_type,
args: sdk_type.args
Expand Down

0 comments on commit 3bb9457

Please sign in to comment.