diff --git a/app/models/ckb_sync/new_node_data_processor.rb b/app/models/ckb_sync/new_node_data_processor.rb index b3e74a993..48b75213e 100644 --- a/app/models/ckb_sync/new_node_data_processor.rb +++ b/app/models/ckb_sync/new_node_data_processor.rb @@ -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 @@ -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 @@ -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 diff --git a/app/models/lock_script.rb b/app/models/lock_script.rb index 2df44740f..77032f25e 100644 --- a/app/models/lock_script.rb +++ b/app/models/lock_script.rb @@ -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 diff --git a/app/models/script.rb b/app/models/script.rb index 3fa9b16a3..12a5f00ec 100644 --- a/app/models/script.rb +++ b/app/models/script.rb @@ -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 @@ -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 diff --git a/app/models/type_script.rb b/app/models/type_script.rb index d9007c188..d4705291e 100644 --- a/app/models/type_script.rb +++ b/app/models/type_script.rb @@ -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