From 8514413569baa2d894de0159e9f440327d117f40 Mon Sep 17 00:00:00 2001 From: Miles Zhang Date: Thu, 22 Feb 2024 13:47:29 +0800 Subject: [PATCH 1/7] fix: spore cluster and cell query should be mapping (#1638) Signed-off-by: Miles Zhang --- app/models/ckb_sync/api.rb | 11 +++++++++++ app/models/ckb_sync/new_node_data_processor.rb | 4 ++-- app/workers/token_transfer_detect_worker.rb | 4 ++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/app/models/ckb_sync/api.rb b/app/models/ckb_sync/api.rb index 14c0c6b71..d2e39e4d6 100644 --- a/app/models/ckb_sync/api.rb +++ b/app/models/ckb_sync/api.rb @@ -87,6 +87,17 @@ 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 be99a1794..305e46288 100644 --- a/app/models/ckb_sync/new_node_data_processor.rb +++ b/app/models/ckb_sync/new_node_data_processor.rb @@ -673,8 +673,8 @@ 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? - binary_hashes = CkbUtils.hexes_to_bins_sql(CkbSync::Api.instance.spore_cluster_code_hashes) - spore_cluster_type = TypeScript.where("code_hash IN (#{binary_hashes})").where( + cluster_code_hash = CkbSync::Api.instance.spore_code_hash_mapping[output.type.code_hash] + spore_cluster_type = TypeScript.where(code_hash: cluster_code_hash).where( args: parsed_spore_cell[:cluster_id], ).first if spore_cluster_type.present? diff --git a/app/workers/token_transfer_detect_worker.rb b/app/workers/token_transfer_detect_worker.rb index 02c976127..5ade161ee 100644 --- a/app/workers/token_transfer_detect_worker.rb +++ b/app/workers/token_transfer_detect_worker.rb @@ -144,8 +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) - binary_hashes = CkbUtils.hexes_to_bins_sql(CkbSync::Api.instance.spore_cluster_code_hashes) - spore_cluster_type = TypeScript.where("code_hash IN (#{binary_hashes})").where( + cluster_code_hash = CkbSync::Api.instance.spore_code_hash_mapping[type_script.code_hash] + spore_cluster_type = TypeScript.where(code_hash: cluster_code_hash).where( args: parsed_spore_cell[:cluster_id], ).first coll = TokenCollection.find_or_create_by( From 780f081e97842b336dfc9eb1b9b69a493a2d6dc2 Mon Sep 17 00:00:00 2001 From: Miles Zhang Date: Thu, 22 Feb 2024 16:25:01 +0800 Subject: [PATCH 2/7] chore: remove sentry transaction performance tracer (#1641) Signed-off-by: Miles Zhang --- config/initializers/sentry.rb | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/config/initializers/sentry.rb b/config/initializers/sentry.rb index 33f4f4609..24daf223e 100644 --- a/config/initializers/sentry.rb +++ b/config/initializers/sentry.rb @@ -1,14 +1,6 @@ Sentry.init do |config| config.dsn = ENV["SENTRY_DSN"] - config.breadcrumbs_logger = [:active_support_logger, :http_logger] - - # Set tracesSampleRate to 1.0 to capture 100% - # of transactions for performance monitoring. - # We recommend adjusting this value in production - config.traces_sample_rate = ENV.fetch("SENTRY_SAMPLE_RATE", 1.0).to_f - config.traces_sampler = lambda do |context| - true - end + config.breadcrumbs_logger = %i[active_support_logger http_logger] config.logger = Logger.new(STDERR) config.enabled_environments = %w[production staging] end From bc3a4300fbf6db4b8fea676910c94603bac8c0c0 Mon Sep 17 00:00:00 2001 From: Miles Zhang Date: Thu, 22 Feb 2024 18:24:48 +0800 Subject: [PATCH 3/7] fix: support no cluster spore cell display (#1643) Signed-off-by: Miles Zhang --- .../ckb_sync/new_node_data_processor.rb | 23 +++------- app/workers/clean_up_worker.rb | 1 - app/workers/token_transfer_detect_worker.rb | 43 +++++++++++-------- 3 files changed, 32 insertions(+), 35 deletions(-) diff --git a/app/models/ckb_sync/new_node_data_processor.rb b/app/models/ckb_sync/new_node_data_processor.rb index 305e46288..901b76191 100644 --- a/app/models/ckb_sync/new_node_data_processor.rb +++ b/app/models/ckb_sync/new_node_data_processor.rb @@ -674,23 +674,12 @@ def build_udts!(local_block, outputs, outputs_data) 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 = TypeScript.where(code_hash: cluster_code_hash).where( - args: parsed_spore_cell[:cluster_id], - ).first - if spore_cluster_type.present? - spore_cluster_cell = spore_cluster_type.cell_outputs.last - parsed_cluster_data = CkbUtils.parse_spore_cluster_data(spore_cluster_cell.data) - coll = TokenCollection.find_or_create_by( - standard: "spore", - name: parsed_cluster_data[:name], - description: parsed_cluster_data[:description], - cell_id: spore_cluster_cell.id, - creator_id: spore_cluster_cell.address_id, - ) - - nft_token_attr[:full_name] = parsed_cluster_data[:name] - nft_token_attr[:published] = true - end + spore_cluster_type_ids = TypeScript.where(code_hash: cluster_code_hash, 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] + nft_token_attr[:published] = true end end if cell_type == "nrc_721_token" diff --git a/app/workers/clean_up_worker.rb b/app/workers/clean_up_worker.rb index 187fbd992..e126aab01 100644 --- a/app/workers/clean_up_worker.rb +++ b/app/workers/clean_up_worker.rb @@ -2,7 +2,6 @@ class CleanUpWorker include Sidekiq::Worker def perform - TokenCollection.remove_corrupted CkbTransaction.tx_pending.where("created_at < ?", 1.day.ago).destroy_all CkbTransaction.tx_rejected.where("created_at < ?", 3.months.ago).destroy_all end diff --git a/app/workers/token_transfer_detect_worker.rb b/app/workers/token_transfer_detect_worker.rb index 5ade161ee..026aba969 100644 --- a/app/workers/token_transfer_detect_worker.rb +++ b/app/workers/token_transfer_detect_worker.rb @@ -145,23 +145,32 @@ 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] - spore_cluster_type = TypeScript.where(code_hash: cluster_code_hash).where( - args: parsed_spore_cell[:cluster_id], - ).first - coll = TokenCollection.find_or_create_by( - standard: "spore", - type_script_id: spore_cluster_type.id, - sn: spore_cluster_type.script_hash, - ) - spore_cluster_cell = spore_cluster_type.cell_outputs.order("id desc").first - if spore_cluster_cell.present? && coll.creator_id != spore_cluster_cell.address_id - parsed_cluster_data = CkbUtils.parse_spore_cluster_data(spore_cluster_cell.data) - coll.creator_id = spore_cluster_cell.address_id - coll.cell_id = spore_cluster_cell.id - coll.name = parsed_cluster_data[:name] - coll.description = parsed_cluster_data[:description] - coll.save + if parsed_spore_cell[:cluster_id].nil? + spore_cluster_type = TypeScript.find_or_create_by(code_hash: cluster_code_hash, hash_type: "data1", + args: parsed_spore_cell[:cluster_id]) + TokenCollection.find_or_create_by( + standard: "spore", + sn: spore_cluster_type.script_hash, + 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) + spore_cluster_cell = CellOutput.live.where(type_script_id: spore_cluster_type_ids).last + coll = TokenCollection.find_or_create_by( + standard: "spore", + sn: spore_cluster_cell.type_hash, + ) + if spore_cluster_cell.present? && coll.creator_id != spore_cluster_cell.address_id + parsed_cluster_data = CkbUtils.parse_spore_cluster_data(spore_cluster_cell.data) + coll.type_script_id = spore_cluster_cell.type_script_id + coll.creator_id = spore_cluster_cell.address_id + coll.cell_id = spore_cluster_cell.id + coll.name = parsed_cluster_data[:name] + coll.description = parsed_cluster_data[:description] + coll.save + end + coll end - coll end end From e929082c5446f47bd47108d080bab9c3e18a6147 Mon Sep 17 00:00:00 2001 From: Miles Zhang Date: Thu, 22 Feb 2024 20:37:39 +0800 Subject: [PATCH 4/7] fix: invoke TokenTransferDetectWorker after tx's data saved (#1645) Signed-off-by: Miles Zhang --- app/models/ckb_sync/new_node_data_processor.rb | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/app/models/ckb_sync/new_node_data_processor.rb b/app/models/ckb_sync/new_node_data_processor.rb index 901b76191..1e7818e18 100644 --- a/app/models/ckb_sync/new_node_data_processor.rb +++ b/app/models/ckb_sync/new_node_data_processor.rb @@ -818,6 +818,7 @@ def build_cells_and_locks!( lock_scripts_attributes, type_scripts_attributes = build_scripts(outputs) lock_script_ids = [] type_script_ids = [] + token_transfer_ckb_tx_ids = Set.new if lock_scripts_attributes.present? lock_scripts_attributes.map! do |attr| @@ -868,7 +869,7 @@ def build_cells_and_locks!( # prepare script ids for insert cell_outputs prepare_script_ids(outputs) build_cell_outputs!(node_block, outputs, ckb_txs, local_block, cell_outputs_attributes, output_capacities, tags, - udt_address_ids, dao_address_ids, contained_udt_ids, contained_addr_ids, addrs_changes) + udt_address_ids, dao_address_ids, contained_udt_ids, contained_addr_ids, addrs_changes, token_transfer_ckb_tx_ids) if cell_outputs_attributes.present? id_hashes = CellOutput.upsert_all(cell_outputs_attributes, unique_by: %i[tx_hash cell_index], returning: %i[id data_hash]) @@ -892,7 +893,7 @@ def build_cells_and_locks!( prev_outputs = nil build_cell_inputs(inputs, ckb_txs, local_block.id, cell_inputs_attributes, prev_cell_outputs_attributes, input_capacities, tags, udt_address_ids, dao_address_ids, contained_udt_ids, contained_addr_ids, - prev_outputs, addrs_changes) + prev_outputs, addrs_changes, token_transfer_ckb_tx_ids) CellInput.upsert_all(cell_inputs_attributes, unique_by: %i[ckb_transaction_id index]) @@ -901,6 +902,10 @@ def build_cells_and_locks!( unique_by: %i[tx_hash cell_index]) end + token_transfer_ckb_tx_ids.each do |tx_id| + TokenTransferDetectWorker.perform_async(tx_id) + end + ScriptTransaction.create_from_scripts TypeScript.where(id: type_script_ids) ScriptTransaction.create_from_scripts LockScript.where(id: lock_script_ids) @@ -985,7 +990,7 @@ def script_attributes(script, script_hash) def build_cell_inputs( inputs, ckb_txs, local_block_id, cell_inputs_attributes, prev_cell_outputs_attributes, -input_capacities, tags, udt_address_ids, dao_address_ids, contained_udt_ids, contained_addr_ids, prev_outputs, addrs_changes +input_capacities, tags, udt_address_ids, dao_address_ids, contained_udt_ids, contained_addr_ids, prev_outputs, addrs_changes, token_transfer_ckb_tx_ids ) tx_index = 0 @@ -1030,7 +1035,7 @@ def build_cell_inputs( change_rec[:dao_txs] ||= Set.new change_rec[:dao_txs] << ckb_txs[tx_index]["tx_hash"] elsif cell_type.in?(%w(m_nft_token nrc_721_token spore_cell)) - TokenTransferDetectWorker.perform_async(ckb_txs[tx_index]["id"]) + token_transfer_ckb_tx_ids << ckb_txs[tx_index]["id"] end case previous_output[:cell_type] @@ -1058,7 +1063,7 @@ def build_cell_inputs( def build_cell_outputs!( node_block, outputs, ckb_txs, local_block, cell_outputs_attributes, output_capacities, -tags, udt_address_ids, dao_address_ids, contained_udt_ids, contained_addr_ids, addrs_changes +tags, udt_address_ids, dao_address_ids, contained_udt_ids, contained_addr_ids, addrs_changes, token_transfer_ckb_tx_ids ) outputs.each do |tx_index, items| cell_index = 0 @@ -1111,7 +1116,7 @@ def build_cell_outputs!( type_hash: item.type.compute_hash, udt_type: "omiga_inscription", ).pick(:id) elsif attr[:cell_type].in?(%w(m_nft_token nrc_721_token spore_cell)) - TokenTransferDetectWorker.perform_async(ckb_txs[tx_index]["id"]) + token_transfer_ckb_tx_ids << ckb_txs[tx_index]["id"] end output_capacities[tx_index] += item.capacity if tx_index != 0 From 35dfa27dde48c60f39b1cbfa07026fae5801963b Mon Sep 17 00:00:00 2001 From: Miles Zhang Date: Thu, 22 Feb 2024 21:44:51 +0800 Subject: [PATCH 5/7] Issue 548 3 (#1646) chore: debug for TokenTransferDetectWorker Signed-off-by: Miles Zhang --- app/workers/token_transfer_detect_worker.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/workers/token_transfer_detect_worker.rb b/app/workers/token_transfer_detect_worker.rb index 026aba969..da8aa94fe 100644 --- a/app/workers/token_transfer_detect_worker.rb +++ b/app/workers/token_transfer_detect_worker.rb @@ -3,6 +3,7 @@ class TokenTransferDetectWorker def perform(tx_id) tx = CkbTransaction.includes(:cell_outputs, cell_inputs: :previous_cell_output).find tx_id + puts "==================#{tx.inspect}" return unless tx @lock = Redis::Lock.new("token_transfer_#{tx_id}", expiration: 180, timeout: 30) @@ -11,6 +12,7 @@ def perform(tx_id) source_collections = [] tx.cell_inputs.each do |input| + puts input.cell_type if input.cell_type.in?(%w(m_nft_token nrc_721_token spore_cell)) cell = input.previous_cell_output type_script = input.type_script @@ -20,7 +22,9 @@ def perform(tx_id) end tx.cell_outputs.each do |output| + puts output.cell_type if output.cell_type.in?(%w(m_nft_token nrc_721_token spore_cell)) + puts "========================#{output.id}" type_script = output.type_script item = find_or_create_item(output, type_script) attrs = { From e176fe4f43611d6ec2a1e55d450664d8c6a8b5bf Mon Sep 17 00:00:00 2001 From: Miles Zhang Date: Fri, 23 Feb 2024 11:43:25 +0800 Subject: [PATCH 6/7] Issue 548 4 (#1647) * fix: invoke worker in outside node process transaction Signed-off-by: Miles Zhang * Revert "Issue 548 3 (#1646)" This reverts commit 35dfa27dde48c60f39b1cbfa07026fae5801963b. --------- Signed-off-by: Miles Zhang --- .../ckb_sync/new_node_data_processor.rb | 19 +++++++++++-------- app/workers/token_transfer_detect_worker.rb | 4 ---- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/app/models/ckb_sync/new_node_data_processor.rb b/app/models/ckb_sync/new_node_data_processor.rb index 1e7818e18..0741cad74 100644 --- a/app/models/ckb_sync/new_node_data_processor.rb +++ b/app/models/ckb_sync/new_node_data_processor.rb @@ -10,7 +10,7 @@ class NewNodeDataProcessor value :reorg_started_at, global: true attr_accessor :local_tip_block, :pending_raw_block, :ckb_txs, :target_block, :addrs_changes, :outputs, :inputs, :outputs_data, :udt_address_ids, :contained_address_ids, - :dao_address_ids, :contained_udt_ids, :cell_datas, :enable_cota + :dao_address_ids, :contained_udt_ids, :cell_datas, :enable_cota, :token_transfer_ckb_tx_ids def initialize(enable_cota = ENV["COTA_AGGREGATOR_URL"].present?) @enable_cota = enable_cota @@ -68,13 +68,14 @@ def process_block(node_block, refresh_balance: true) @dao_address_ids = dao_address_ids = [] @contained_udt_ids = contained_udt_ids = [] @contained_address_ids = contained_address_ids = [] + @token_transfer_ckb_tx_ids = token_transfer_ckb_tx_ids = Set.new benchmark :process_ckb_txs, node_block, ckb_txs, contained_address_ids, contained_udt_ids, dao_address_ids, tags, udt_address_ids addrs_changes = Hash.new { |hash, key| hash[key] = {} } input_capacities, output_capacities = benchmark :build_cells_and_locks!, local_block, node_block, ckb_txs, inputs, outputs, - tags, udt_address_ids, dao_address_ids, contained_udt_ids, contained_address_ids, addrs_changes + tags, udt_address_ids, dao_address_ids, contained_udt_ids, contained_address_ids, addrs_changes, token_transfer_ckb_tx_ids # update explorer data benchmark :update_ckb_txs_rel_and_fee, ckb_txs, tags, input_capacities, output_capacities, udt_address_ids, @@ -94,6 +95,7 @@ def process_block(node_block, refresh_balance: true) generate_statistics_data(local_block) generate_deployed_cells_and_referring_cells(local_block) detect_cota_infos(local_block) + invoke_token_transfer_detect_worker(token_transfer_ckb_tx_ids) local_block.update_counter_for_ckb_node_version local_block @@ -131,6 +133,12 @@ def detect_cota_infos(local_block) FetchCotaWorker.perform_async(local_block.number) if enable_cota end + def invoke_token_transfer_detect_worker(token_transfer_ckb_tx_ids) + token_transfer_ckb_tx_ids.each do |tx_id| + TokenTransferDetectWorker.perform_async(tx_id) + end + end + def process_ckb_txs( node_block, ckb_txs, contained_address_ids, contained_udt_ids, dao_address_ids, tags, udt_address_ids @@ -808,7 +816,7 @@ def update_ckb_txs_rel_and_fee( def build_cells_and_locks!( local_block, node_block, ckb_txs, inputs, outputs, tags, udt_address_ids, - dao_address_ids, contained_udt_ids, contained_addr_ids, addrs_changes + dao_address_ids, contained_udt_ids, contained_addr_ids, addrs_changes, token_transfer_ckb_tx_ids ) cell_outputs_attributes = [] cell_inputs_attributes = [] @@ -818,7 +826,6 @@ def build_cells_and_locks!( lock_scripts_attributes, type_scripts_attributes = build_scripts(outputs) lock_script_ids = [] type_script_ids = [] - token_transfer_ckb_tx_ids = Set.new if lock_scripts_attributes.present? lock_scripts_attributes.map! do |attr| @@ -902,10 +909,6 @@ def build_cells_and_locks!( unique_by: %i[tx_hash cell_index]) end - token_transfer_ckb_tx_ids.each do |tx_id| - TokenTransferDetectWorker.perform_async(tx_id) - end - ScriptTransaction.create_from_scripts TypeScript.where(id: type_script_ids) ScriptTransaction.create_from_scripts LockScript.where(id: lock_script_ids) diff --git a/app/workers/token_transfer_detect_worker.rb b/app/workers/token_transfer_detect_worker.rb index da8aa94fe..026aba969 100644 --- a/app/workers/token_transfer_detect_worker.rb +++ b/app/workers/token_transfer_detect_worker.rb @@ -3,7 +3,6 @@ class TokenTransferDetectWorker def perform(tx_id) tx = CkbTransaction.includes(:cell_outputs, cell_inputs: :previous_cell_output).find tx_id - puts "==================#{tx.inspect}" return unless tx @lock = Redis::Lock.new("token_transfer_#{tx_id}", expiration: 180, timeout: 30) @@ -12,7 +11,6 @@ def perform(tx_id) source_collections = [] tx.cell_inputs.each do |input| - puts input.cell_type if input.cell_type.in?(%w(m_nft_token nrc_721_token spore_cell)) cell = input.previous_cell_output type_script = input.type_script @@ -22,9 +20,7 @@ def perform(tx_id) end tx.cell_outputs.each do |output| - puts output.cell_type if output.cell_type.in?(%w(m_nft_token nrc_721_token spore_cell)) - puts "========================#{output.id}" type_script = output.type_script item = find_or_create_item(output, type_script) attrs = { From e7127d94279ab2802120faeeb8d8236d1ee29900 Mon Sep 17 00:00:00 2001 From: Miles Zhang Date: Fri, 23 Feb 2024 18:21:15 +0800 Subject: [PATCH 7/7] 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",