From e7127d94279ab2802120faeeb8d8236d1ee29900 Mon Sep 17 00:00:00 2001 From: Miles Zhang Date: Fri, 23 Feb 2024 18:21:15 +0800 Subject: [PATCH] fix: remove spore cluster and cell contract code_hash mapping (#1648) Signed-off-by: Miles Zhang --- app/models/ckb_sync/api.rb | 11 ----------- app/models/ckb_sync/new_node_data_processor.rb | 7 ++++--- app/workers/token_transfer_detect_worker.rb | 8 ++++---- 3 files changed, 8 insertions(+), 18 deletions(-) diff --git a/app/models/ckb_sync/api.rb b/app/models/ckb_sync/api.rb index d2e39e4d6..14c0c6b71 100644 --- a/app/models/ckb_sync/api.rb +++ b/app/models/ckb_sync/api.rb @@ -87,17 +87,6 @@ def spore_cell_code_hashes end end - def spore_code_hash_mapping - if mode == CKB::MODE::MAINNET - { Settings.spore_cell1_code_hash => Settings.spore_cluster1_code_hash } - else - { - Settings.spore_cell1_code_hash => Settings.spore_cluster1_code_hash, - Settings.spore_cell2_code_hash => Settings.spore_cluster2_code_hash, - } - end - end - def omiga_inscription_info_code_hash Settings.omiga_inscription_info_code_hash end diff --git a/app/models/ckb_sync/new_node_data_processor.rb b/app/models/ckb_sync/new_node_data_processor.rb index 0741cad74..b26f9ea22 100644 --- a/app/models/ckb_sync/new_node_data_processor.rb +++ b/app/models/ckb_sync/new_node_data_processor.rb @@ -681,9 +681,10 @@ def build_udts!(local_block, outputs, outputs_data) if cell_type == "spore_cell" parsed_spore_cell = CkbUtils.parse_spore_cell_data(outputs_data[tx_index][index]) if parsed_spore_cell[:cluster_id].present? - cluster_code_hash = CkbSync::Api.instance.spore_code_hash_mapping[output.type.code_hash] - spore_cluster_type_ids = TypeScript.where(code_hash: cluster_code_hash, hash_type: "data1", - args: parsed_spore_cell[:cluster_id]).pluck(:id) + binary_hashes = CkbUtils.hexes_to_bins_sql(CkbSync::Api.instance.spore_cluster_code_hashes) + spore_cluster_type_ids = TypeScript.where("code_hash IN (#{binary_hashes})").where(hash_type: "data1", + args: parsed_spore_cell[:cluster_id]).pluck(:id) + spore_cluster_cell = CellOutput.live.where(type_script_id: spore_cluster_type_ids).last parsed_cluster_data = CkbUtils.parse_spore_cluster_data(spore_cluster_cell.data) nft_token_attr[:full_name] = parsed_cluster_data[:name] diff --git a/app/workers/token_transfer_detect_worker.rb b/app/workers/token_transfer_detect_worker.rb index 026aba969..b5d1b950d 100644 --- a/app/workers/token_transfer_detect_worker.rb +++ b/app/workers/token_transfer_detect_worker.rb @@ -144,9 +144,8 @@ def find_or_create_m_nft_collection(_cell, type_script) def find_or_create_spore_collection(_cell, type_script) spore_cell = type_script.cell_outputs.order("id desc").first parsed_spore_cell = CkbUtils.parse_spore_cell_data(spore_cell.data) - cluster_code_hash = CkbSync::Api.instance.spore_code_hash_mapping[type_script.code_hash] if parsed_spore_cell[:cluster_id].nil? - spore_cluster_type = TypeScript.find_or_create_by(code_hash: cluster_code_hash, hash_type: "data1", + spore_cluster_type = TypeScript.find_or_create_by(code_hash: CkbSync::Api.instance.spore_cluster_code_hashes.first, hash_type: "data1", args: parsed_spore_cell[:cluster_id]) TokenCollection.find_or_create_by( standard: "spore", @@ -154,8 +153,9 @@ def find_or_create_spore_collection(_cell, type_script) description: "Only for no cluster spore cell", ) else - spore_cluster_type_ids = TypeScript.where(code_hash: cluster_code_hash, hash_type: "data1", - args: parsed_spore_cell[:cluster_id]).pluck(:id) + binary_hashes = CkbUtils.hexes_to_bins_sql(CkbSync::Api.instance.spore_cluster_code_hashes) + spore_cluster_type_ids = TypeScript.where("code_hash IN (#{binary_hashes})").where(hash_type: "data1", + args: parsed_spore_cell[:cluster_id]).pluck(:id) spore_cluster_cell = CellOutput.live.where(type_script_id: spore_cluster_type_ids).last coll = TokenCollection.find_or_create_by( standard: "spore",