Skip to content

Commit

Permalink
fix: support no cluster spore cell display (#1643)
Browse files Browse the repository at this point in the history
Signed-off-by: Miles Zhang <[email protected]>
  • Loading branch information
zmcNotafraid authored Feb 22, 2024
1 parent 780f081 commit bc3a430
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 35 deletions.
23 changes: 6 additions & 17 deletions app/models/ckb_sync/new_node_data_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion app/workers/clean_up_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 26 additions & 17 deletions app/workers/token_transfer_detect_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit bc3a430

Please sign in to comment.